From c942610b318d82cc70590cfece4be12b28c77190 Mon Sep 17 00:00:00 2001 From: broody Date: Tue, 20 Aug 2024 15:05:51 -0700 Subject: [PATCH] Make backwards compat with 0.3.40 --- packages/controller/src/index.ts | 12 +++++------- packages/controller/src/types.ts | 7 +++++-- packages/keychain/src/components/connect/Login.tsx | 3 ++- .../keychain/src/components/layout/Footer/index.tsx | 4 ++-- packages/keychain/src/hooks/connection.tsx | 2 +- packages/keychain/src/utils/connection/connect.ts | 7 ++----- packages/keychain/src/utils/connection/types.ts | 2 +- 7 files changed, 18 insertions(+), 19 deletions(-) diff --git a/packages/controller/src/index.ts b/packages/controller/src/index.ts index 10f808fe7..c481fbc82 100644 --- a/packages/controller/src/index.ts +++ b/packages/controller/src/index.ts @@ -30,7 +30,7 @@ import { KEYCHAIN_URL, RPC_SEPOLIA } from "./constants"; class Controller { private url: URL; - private policies?: Policy[]; + private policies: Policy[]; private paymaster?: PaymasterOptions; private connection?: Connection; private modal?: Modal; @@ -51,13 +51,11 @@ class Controller { this.url = new URL(url || KEYCHAIN_URL); this.rpc = new URL(rpc || RPC_SEPOLIA); this.paymaster = paymaster; - - if (policies?.length) { - this.policies = policies.map((policy) => ({ + this.policies = + policies?.map((policy) => ({ ...policy, target: addAddressPadding(policy.target), - })); - } + })) || []; this.setTheme(theme, config?.presets); if (colorMode) { @@ -190,8 +188,8 @@ class Controller { try { let response = await this.keychain.connect({ - rpcUrl: this.rpc.toString(), policies: this.policies, + rpcUrl: this.rpc.toString(), }); if (response.code !== ResponseCodes.SUCCESS) { throw new Error(response.message); diff --git a/packages/controller/src/types.ts b/packages/controller/src/types.ts index 1f9c6dcb1..61d4b43a9 100644 --- a/packages/controller/src/types.ts +++ b/packages/controller/src/types.ts @@ -61,9 +61,12 @@ export type ProbeReply = { export interface Keychain { probe(rpcUrl?: string): Promise; - connect(args: { + connect({ + rpcUrl, + policies, + }: { rpcUrl: string; - policies?: Policy[]; + policies: Policy[]; }): Promise; disconnect(): void; diff --git a/packages/keychain/src/components/connect/Login.tsx b/packages/keychain/src/components/connect/Login.tsx index b37095a41..8050b75ed 100644 --- a/packages/keychain/src/components/connect/Login.tsx +++ b/packages/keychain/src/components/connect/Login.tsx @@ -50,6 +50,7 @@ function Form({ const [isValidating, setIsValidating] = useState(false); const onSubmit = useCallback(async () => { + console.log(policies); setIsValidating(true); const error = await validateUsernameFor("login")(usernameField.value); if (error) { @@ -81,7 +82,7 @@ function Form({ credentialId, }); - if (mode === LoginMode.Controller && policies.length > 0) { + if (mode === LoginMode.Controller && policies?.length > 0) { await controller.approve(origin, expiresAt, policies); } else { await doLogin(usernameField.value, credentialId); diff --git a/packages/keychain/src/components/layout/Footer/index.tsx b/packages/keychain/src/components/layout/Footer/index.tsx index dd0a11ccf..abb049401 100644 --- a/packages/keychain/src/components/layout/Footer/index.tsx +++ b/packages/keychain/src/components/layout/Footer/index.tsx @@ -32,7 +32,7 @@ export function Footer({ const isExpandable = useMemo( () => !!origin && - !!policies?.length && + !!policies.length && variant === "connect" && !isSignup && !hideTxSummary, @@ -100,7 +100,7 @@ export function Footer({ onClick={footer.onToggle} _hover={{ cursor: "pointer" }} > - {!hideTxSummary && !!policies?.length && ( + {!hideTxSummary && !!policies.length && ( => { setOrigin(origin); setRpcUrl(rpcUrl); - - if (policies?.length) { - setPolicies(policies); - } + setPolicies(policies); return new Promise((resolve, reject) => { setContext({ diff --git a/packages/keychain/src/utils/connection/types.ts b/packages/keychain/src/utils/connection/types.ts index 4e820133f..14736619e 100644 --- a/packages/keychain/src/utils/connection/types.ts +++ b/packages/keychain/src/utils/connection/types.ts @@ -26,7 +26,7 @@ export type ConnectionCtx = export type ConnectCtx = { origin: string; type: "connect"; - policies?: Policy[]; + policies: Policy[]; resolve: (res: ConnectReply | ConnectError) => void; reject: (reason?: unknown) => void; };