diff --git a/examples/starknet-react-next/src/components/providers/StarknetProvider.tsx b/examples/starknet-react-next/src/components/providers/StarknetProvider.tsx index 81b019c38..913f10ec1 100644 --- a/examples/starknet-react-next/src/components/providers/StarknetProvider.tsx +++ b/examples/starknet-react-next/src/components/providers/StarknetProvider.tsx @@ -52,14 +52,14 @@ const cartridge = new CartridgeConnector({ ], url: !process.env.NEXT_PUBLIC_VERCEL_BRANCH_URL || - process.env.NEXT_PUBLIC_VERCEL_BRANCH_URL.split(".")[0] === + process.env.NEXT_PUBLIC_VERCEL_BRANCH_URL.split(".")[0] === "cartridge-starknet-react-next" ? process.env.XFRAME_URL : "https://" + - (process.env.NEXT_PUBLIC_VERCEL_BRANCH_URL ?? "").replace( - "cartridge-starknet-react-next", - "keychain", - ), + (process.env.NEXT_PUBLIC_VERCEL_BRANCH_URL ?? "").replace( + "cartridge-starknet-react-next", + "keychain", + ), rpc: process.env.NEXT_PUBLIC_RPC_SEPOLIA, paymaster: { caller: shortString.encodeShortString("ANY_CALLER"), diff --git a/packages/controller/src/index.ts b/packages/controller/src/index.ts index 10f808fe7..9da531c05 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) { @@ -189,10 +187,10 @@ class Controller { this.modal.open(); try { - let response = await this.keychain.connect({ - rpcUrl: this.rpc.toString(), - policies: this.policies, - }); + let response = await this.keychain.connect( + this.policies, + 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..c50b112eb 100644 --- a/packages/controller/src/types.ts +++ b/packages/controller/src/types.ts @@ -61,10 +61,10 @@ export type ProbeReply = { export interface Keychain { probe(rpcUrl?: string): Promise; - connect(args: { - rpcUrl: string; - policies?: Policy[]; - }): Promise; + connect( + policies: Policy[], + rpcUrl: string, + ): Promise; disconnect(): void; reset(): void; diff --git a/packages/keychain/src/components/connect/Login.tsx b/packages/keychain/src/components/connect/Login.tsx index b37095a41..ba1ca7c2f 100644 --- a/packages/keychain/src/components/connect/Login.tsx +++ b/packages/keychain/src/components/connect/Login.tsx @@ -81,7 +81,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 && ( void; }) { return (origin: string) => - ({ - rpcUrl, - policies, - }: { - rpcUrl: string; - policies?: Policy[]; - }): Promise => { + (policies: Policy[], rpcUrl: string): Promise => { 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; };