Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
turbocrime committed Jul 15, 2024
1 parent 47067e0 commit 87d69ef
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 43 deletions.
27 changes: 9 additions & 18 deletions apps/minifront/src/prax.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
import { createPromiseClient, PromiseClient, Transport } from '@connectrpc/connect';
import { getPenumbraManifest } from '@penumbra-zone/client';
import {
assertProvider,
assertProviderConnected,
assertProviderManifest,
getPenumbraPort,
syncCreatePenumbraChannelTransport,
} from '@penumbra-zone/client/create';
} from '@penumbra-zone/client/assert';
import { createPenumbraChannelTransportSync } from '@penumbra-zone/client/create';
import { jsonOptions, PenumbraService } from '@penumbra-zone/protobuf';

const prax_id = 'lkpmkhpnhknhmibgnmmhdhgdilepfghe';
const prax_origin = `chrome-extension://${prax_id}`;

export const getPraxOrigin = () => prax_origin;

export const getPraxManifest = async () => {
const { manifest } = await assertProviderManifest(prax_origin);
const requestManifest = await fetch(manifest);
return (await requestManifest.json()) as unknown;
};
export const getPraxManifest = () => getPenumbraManifest(prax_origin);

export const isPraxConnected = () => {
try {
Expand All @@ -29,7 +26,7 @@ export const isPraxConnected = () => {

export const isPraxInstalled = async () => {
try {
await assertProviderManifest();
await assertProviderManifest(prax_origin);
return true;
} catch {
return false;
Expand All @@ -40,16 +37,10 @@ export const throwIfPraxNotConnected = () => assertProviderConnected(prax_origin

export const throwIfPraxNotInstalled = async () => assertProviderManifest(prax_origin);

export const getPraxPort = () => getPenumbraPort(prax_origin);

export const requestPraxAccess = () => getPraxPort();

export const praxTransportOptions = {
jsonOptions,
getPort: getPraxPort,
};
export const requestPraxAccess = () => assertProvider(prax_origin).then(p => p.request());

export const createPraxTransport = () => syncCreatePenumbraChannelTransport(prax_origin);
export const createPraxTransport = () =>
createPenumbraChannelTransportSync(prax_origin, { jsonOptions });

let praxTransport: Transport | undefined;
export const createPraxClient = <T extends PenumbraService>(service: T): PromiseClient<T> =>
Expand Down
5 changes: 3 additions & 2 deletions packages/client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ declare global {
}

/** Synchronously return the specified provider, without verifying anything. */
export const getPenumbraProviderUnsafe = (penumbraOrigin: string) =>
export const getPenumbraUnsafe = (penumbraOrigin: string) =>
window[PenumbraSymbol]?.[penumbraOrigin];

/** Return the specified provider after confirming presence of its manifest. */
export const getPenumbraProvider = (penumbraOrigin: string) => assertProvider(penumbraOrigin);
export const getPenumbra = (penumbraOrigin: string) => assertProvider(penumbraOrigin);

/** Return the specified provider's manifest. */
export const getPenumbraManifest = async (
Expand All @@ -41,6 +41,7 @@ export const getAllPenumbraManifests = (): Record<
]),
);

export * from './error.js';
export type { PenumbraManifest } from './manifest.js';
export type { PenumbraProvider } from './provider.js';
export { PenumbraState } from './state.js';
Expand Down
13 changes: 0 additions & 13 deletions packages/react/eslint.config.mjs

This file was deleted.

4 changes: 3 additions & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"build": "tsc --build --verbose",
"clean": "rm -rfv dist *.tsbuildinfo package penumbra-zone-*.tgz",
"dev:pack": "tsc-watch --onSuccess \"$npm_execpath pack\"",
"lint": "eslint src"
"lint": "eslint src",
"lint:fix": "eslint src --fix",
"lint:strict": "tsc --noEmit && eslint src --max-warnings 0"
},
"files": [
"dist"
Expand Down
37 changes: 28 additions & 9 deletions packages/react/src/components/penumbra-context-provider.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { getPenumbraManifest, PenumbraProvider, PenumbraState } from '@penumbra-zone/client';
import { assertProviderRecord } from '@penumbra-zone/client/assert';
import { isPenumbraStateEvent } from '@penumbra-zone/client/event';
import { useCallback, useEffect, useMemo, useState, type ReactNode } from 'react';
import { PenumbraContext, penumbraContext } from '../penumbra-context.js';
import { PenumbraManifest } from '@penumbra-zone/client/manifest';
import { jsonOptions } from '@penumbra-zone/protobuf';
import {
ChannelTransportOptions,
createChannelTransport,
} from '@penumbra-zone/transport-dom/create';
import { jsonOptions } from '@penumbra-zone/protobuf';
import { assertProviderRecord } from '@penumbra-zone/client/assert';
import { useCallback, useEffect, useMemo, useState, type ReactNode } from 'react';
import { PenumbraContext, penumbraContext } from '../penumbra-context.js';

type PenumbraContextProviderProps = {
children?: ReactNode;
Expand Down Expand Up @@ -66,7 +66,7 @@ export const PenumbraContextProvider = ({
.catch(setFailure);

return () => ac.abort();
}, [providerOrigin, penumbra, providerManifest, setProviderManifest]);
}, [failure, penumbra, providerManifest, providerOrigin, setFailure, setProviderManifest]);

// attach state event listener
useEffect(() => {
Expand Down Expand Up @@ -94,7 +94,7 @@ export const PenumbraContextProvider = ({
{ signal: ac.signal },
);
return () => ac.abort();
}, [penumbra, penumbra.addEventListener, providerManifest, failure]);
}, [failure, penumbra, penumbra.addEventListener, providerManifest, providerOrigin, setFailure]);

// request effect
useEffect(() => {
Expand All @@ -110,7 +110,15 @@ export const PenumbraContextProvider = ({
break;
}
}
}, [makeApprovalRequest, providerState, penumbra.request, providerManifest, failure]);
}, [
failure,
makeApprovalRequest,
penumbra,
penumbra.request,
providerManifest,
providerState,
setFailure,
]);

// connect effect
useEffect(() => {
Expand All @@ -135,7 +143,15 @@ export const PenumbraContextProvider = ({
break;
}
}
}, [makeApprovalRequest, providerState, penumbra.connect, providerManifest, failure]);
}, [
failure,
makeApprovalRequest,
penumbra,
penumbra.connect,
providerManifest,
providerState,
setFailure,
]);

const createdContext: PenumbraContext = useMemo(
() => ({
Expand Down Expand Up @@ -170,9 +186,12 @@ export const PenumbraContextProvider = ({
}),
[
failure,
penumbra.connect,
penumbra.addEventListener,
penumbra.connect,
penumbra.disconnect,
penumbra.removeEventListener,
penumbra.request,
providerConnected,
providerManifest,
providerOrigin,
providerPort,
Expand Down

0 comments on commit 87d69ef

Please sign in to comment.