Skip to content

Commit

Permalink
fix client package (#1027)
Browse files Browse the repository at this point in the history
  • Loading branch information
turbocrime authored May 3, 2024
1 parent 88cd189 commit 8410d2f
Show file tree
Hide file tree
Showing 19 changed files with 65 additions and 75 deletions.
5 changes: 5 additions & 0 deletions .changeset/dull-papayas-tap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@penumbra-zone/bech32m': patch
---

dependency version bump
5 changes: 5 additions & 0 deletions .changeset/lovely-days-lick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@penumbra-zone/client': minor
---

add createPraxTransport export, change interface name
25 changes: 10 additions & 15 deletions apps/extension/src/content-scripts/injected-penumbra-global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,20 @@
* mainworld global that allows pages to detect installed providers and connect
* to them.
*
* The global is identified by `Symbol.for('penumbra')` and consists
* of a record with string keys referring to `PenumbraProvider` objects that
* contain a simple api. The identifiers on this record should be unique and
* correspond to an id in a manifest, and providers should provide a link to
* the manifest in their record entry.
*
* The global is identified by `Symbol.for('penumbra')` and consists of a record
* with string keys referring to `PenumbraInjection` objects that contain a
* simple api. The identifiers on this record should be unique and correspond to
* an id in a manifest, and providers should provide a link to the manifest in
* their record entry.
*
* The global is frozen to prevent mutation, but you should consider that the
* global and everything on it is only as trustable as the scripts running on
* the page - imports, includes, and packages your webapp depends on could all
* mutate or preempt the global. User-agent injections like userscripts or
* other content scripts could interfere or intercept connections.
* the page. Imports, includes, and packages your webapp depends on could all
* mutate or preempt the global. User-agent injections like userscripts or other
* content scripts could interfere or intercept connections.
*/

import {
PenumbraProvider,
PenumbraRequestFailure,
PenumbraSymbol,
} from '@penumbra-zone/client/global';
import { PenumbraInjection, PenumbraRequestFailure, PenumbraSymbol } from '@penumbra-zone/client';
import { isPraxFailureMessageEvent, isPraxPortMessageEvent, PraxMessage } from './message-event';

import { PraxConnection } from '../message/prax';
Expand Down Expand Up @@ -93,7 +88,7 @@ const postRequest = () => {
};

// the actual object we attach to the global record, frozen
const praxProvider: PenumbraProvider = Object.freeze({
const praxProvider: PenumbraInjection = Object.freeze({
manifest: `${PRAX_ORIGIN}/manifest.json`,
connect: () => connection.promise,
isConnected: () => connection.state,
Expand Down
2 changes: 1 addition & 1 deletion apps/minifront/src/clients.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createPraxClient } from '@penumbra-zone/client';
import { createPraxClient } from '@penumbra-zone/client/prax';
import { ViewService } from '@buf/penumbra-zone_penumbra.connectrpc_es/penumbra/view/v1/view_connect';
import { SimulationService } from '@buf/penumbra-zone_penumbra.connectrpc_es/penumbra/core/component/dex/v1/dex_connect';
import { CustodyService } from '@buf/penumbra-zone_penumbra.connectrpc_es/penumbra/custody/v1/custody_connect';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
TableRow,
} from '@penumbra-zone/ui/components/ui/table';
import { ValueViewComponent } from '@penumbra-zone/ui/components/ui/tx/view/value';
import { throwIfPraxNotConnectedTimeout } from '@penumbra-zone/client';
import { throwIfPraxNotConnectedTimeout } from '@penumbra-zone/client/prax';
import { EquivalentValues } from './equivalent-values';
import { Fragment } from 'react';

Expand Down
4 changes: 2 additions & 2 deletions apps/minifront/src/components/extension-not-connected.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import {
requestPraxConnection,
throwIfPraxNotAvailable,
throwIfPraxNotInstalled,
} from '@penumbra-zone/client';
} from '@penumbra-zone/client/prax';
import { useState } from 'react';
import { PenumbraRequestFailure } from '@penumbra-zone/client/global';
import { PenumbraRequestFailure } from '@penumbra-zone/client';

const handleErr = (e: unknown) => {
if (e instanceof Error && e.cause) {
Expand Down
6 changes: 5 additions & 1 deletion apps/minifront/src/components/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import { Toaster } from '@penumbra-zone/ui/components/ui/toaster';
import { ExtensionNotConnected } from './extension-not-connected';
import { ExtensionNotInstalled } from './extension-not-installed';
import { Footer } from './footer/footer';
import { isPraxConnected, isPraxConnectedTimeout, isPraxAvailable } from '@penumbra-zone/client';
import {
isPraxConnected,
isPraxConnectedTimeout,
isPraxAvailable,
} from '@penumbra-zone/client/prax';
import '@penumbra-zone/ui/styles/globals.css';
import { getChainId } from '../fetchers/chain-id';
import { useEffect, useState } from 'react';
Expand Down
2 changes: 1 addition & 1 deletion apps/minifront/src/components/send/send-form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { LoaderFunction, useLoaderData } from 'react-router-dom';
import { getBalances } from '../../../fetchers/balances';
import { useMemo } from 'react';
import { penumbraAddrValidation } from '../helpers';
import { throwIfPraxNotConnectedTimeout } from '@penumbra-zone/client';
import { throwIfPraxNotConnectedTimeout } from '@penumbra-zone/client/prax';
import InputToken from '../../shared/input-token';
import { useRefreshFee } from './use-refresh-fee';
import { GasFee } from '../../shared/gas-fee';
Expand Down
2 changes: 1 addition & 1 deletion apps/minifront/src/components/shared/error-boundary.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isRouteErrorResponse, useRouteError } from 'react-router-dom';
import { PraxNotConnectedError } from '@penumbra-zone/client';
import { PraxNotConnectedError } from '@penumbra-zone/client/prax';
import { ExtensionNotConnected } from '../extension-not-connected';
import { NotFound } from '../not-found';
import { ExtensionUnavailable } from '../extension-unavailable';
Expand Down
2 changes: 1 addition & 1 deletion apps/minifront/src/components/staking/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect } from 'react';
import { AllSlices, useStore } from '../../state';
import { throwIfPraxNotConnectedTimeout } from '@penumbra-zone/client';
import { throwIfPraxNotConnectedTimeout } from '@penumbra-zone/client/prax';
import { Card, CardContent, CardHeader, CardTitle } from '@penumbra-zone/ui/components/ui/card';
import { Header } from './account/header';
import { Delegations } from './account/delegations';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { throwIfPraxNotConnectedTimeout } from '@penumbra-zone/client';
import { throwIfPraxNotConnectedTimeout } from '@penumbra-zone/client/prax';
import { getSwappableBalancesResponses } from '../helpers';
import { useStore } from '../../../state';
import { getAllAssets } from '../../../fetchers/assets';
Expand Down
2 changes: 1 addition & 1 deletion apps/minifront/src/components/swap/swap/swap-loader.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { LoaderFunction } from 'react-router-dom';
import { useStore } from '../../../state';
import { throwIfPraxNotConnectedTimeout } from '@penumbra-zone/client';
import { throwIfPraxNotConnectedTimeout } from '@penumbra-zone/client/prax';
import {
BalancesResponse,
SwapRecord,
Expand Down
2 changes: 1 addition & 1 deletion apps/minifront/src/components/tx-details/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { EduPanel } from '../shared/edu-panels/content';
import { LoaderFunction, useLoaderData, useRouteError } from 'react-router-dom';
import { getTxInfoByHash } from '../../fetchers/tx-info-by-hash';
import { TransactionInfo } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/view/v1/view_pb';
import { throwIfPraxNotConnectedTimeout } from '@penumbra-zone/client';
import { throwIfPraxNotConnectedTimeout } from '@penumbra-zone/client/prax';
import { RestrictMaxWidth } from '../shared/restrict-max-width';

export interface TxDetailsLoaderResult {
Expand Down
30 changes: 18 additions & 12 deletions packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,29 @@
"description": "Package for connecting to any Penumbra extension, including Prax.",
"type": "module",
"scripts": {
"build": "tsc && vite build",
"clean": "rm -rfv dist",
"lint": "eslint \"**/*.ts*\""
"build": "tsc",
"clean": "rm -rfv dist package penumbra-zone-client-*.tgz",
"lint": "eslint \"**/*.ts*\"",
"prebuild": "$npm_execpath run clean",
"prepack": "$npm_execpath run build"
},
"files": [
"dist"
],
"exports": {
".": "./src/prax.ts",
"./global": "./src/global.ts",
"./get-port": "./src/get-port.ts"
".": "./src/index.ts",
"./prax": "./src/prax.ts"
},
"publishConfig": {
"files": [
"dist"
],
"exports": {
".": "./dist/prax.js",
"./global": "./dist/global.js",
"./get-port": "./dist/get-port.js"
".": {
"import": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"./*": {
"import": "./dist/*.js",
"types": "./dist/*.d.ts"
}
}
},
"dependencies": {
Expand Down
13 changes: 0 additions & 13 deletions packages/client/src/get-port.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export enum PenumbraRequestFailure {

export const PenumbraSymbol = Symbol.for('penumbra');

export interface PenumbraProvider {
export interface PenumbraInjection {
readonly connect: () => Promise<MessagePort>;
readonly request: () => Promise<void>;
readonly isConnected: () => boolean | undefined;
Expand All @@ -14,6 +14,6 @@ export interface PenumbraProvider {

declare global {
interface Window {
readonly [PenumbraSymbol]?: undefined | Readonly<Record<string, PenumbraProvider>>;
readonly [PenumbraSymbol]?: undefined | Readonly<Record<string, PenumbraInjection>>;
}
}
11 changes: 7 additions & 4 deletions packages/client/src/prax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { JsonValue, ServiceType } from '@bufbuild/protobuf';
import type { Transport } from '@connectrpc/connect';
import { createPromiseClient } from '@connectrpc/connect';
import { createChannelTransport } from '@penumbra-zone/transport-dom/create';
import { PenumbraSymbol } from './global';
import { PenumbraSymbol } from '.';
import { jsonOptions } from '@penumbra-zone/protobuf';

const prax_id = 'lkpmkhpnhknhmibgnmmhdhgdilepfghe';
Expand Down Expand Up @@ -83,11 +83,14 @@ export const throwIfPraxNotInstalled = async () => {
if (!isInstalled) throw new PraxNotInstalledError('Prax not installed');
};

let praxTransport: Transport | undefined;
export const createPraxClient = <T extends ServiceType>(serviceType: T) => {
praxTransport ??= createChannelTransport({
export const createPraxTransport = () =>
createChannelTransport({
jsonOptions,
getPort: getPraxPort,
});

let praxTransport: Transport | undefined;
export const createPraxClient = <T extends ServiceType>(serviceType: T) => {
praxTransport ??= createPraxTransport();
return createPromiseClient(serviceType, praxTransport);
};
5 changes: 3 additions & 2 deletions packages/client/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"extends": "tsconfig/base.json",
"exclude": ["node_modules"],
"include": ["src"],
"exclude": ["node_modules", "dist"],
"compilerOptions": {
"outDir": "dist",
"noEmit": true
"noEmit": false
}
}
16 changes: 0 additions & 16 deletions packages/client/vite.config.ts

This file was deleted.

0 comments on commit 8410d2f

Please sign in to comment.