diff --git a/examples/starknet-react-next/src/components/DelegateAccount.tsx b/examples/starknet-react-next/src/components/DelegateAccount.tsx index 8772cac9f..9862bbcc5 100644 --- a/examples/starknet-react-next/src/components/DelegateAccount.tsx +++ b/examples/starknet-react-next/src/components/DelegateAccount.tsx @@ -29,7 +29,7 @@ export const DelegateAccount = () => { setDelegateAddress(delegate?.toString() || ""); setIsDelegateSupported(true); } catch (e: any) { - console.log(e) + console.log(e); // controller doesnt support delegateAccount, ignore } }, [account, chainId, cartridgeConnector]); @@ -76,12 +76,16 @@ export const DelegateAccount = () => { type="text" min-width="420px" value={delegateAddressInput} - onChange={(e:any ) => setDelegateAddressInput(e.target.value)} + onChange={(e: any) => setDelegateAddressInput(e.target.value)} /> + +
+ +
) : (

Not supported!

diff --git a/packages/connector/src/index.ts b/packages/connector/src/index.ts index e0693ea89..a8edcef6c 100644 --- a/packages/connector/src/index.ts +++ b/packages/connector/src/index.ts @@ -68,6 +68,10 @@ class ControllerConnector extends Connector { return await this.controller.delegateAccount(); } + async openSetDelegate(address: string) { + return await this.controller.openSetDelegate(address) + } + async openMenu() { return await this.controller.openMenu(); } diff --git a/packages/controller/src/index.ts b/packages/controller/src/index.ts index 9afc97f27..c7cf58c86 100644 --- a/packages/controller/src/index.ts +++ b/packages/controller/src/index.ts @@ -72,6 +72,20 @@ class Controller { return true; } + async openSetDelegate(address: string) { + if (!this.keychain || !this.modal) { + console.error(new NotReadyToConnect().message); + return null; + } + this.modal.open(); + const res = await this.keychain.openSetDelegate(address); + this.modal.close(); + if (res && (res as ConnectError).code === ResponseCodes.NOT_CONNECTED) { + return false; + } + return true; + } + private initModal() { if (typeof document === "undefined") return; diff --git a/packages/controller/src/types.ts b/packages/controller/src/types.ts index af13f5d32..aa8662c7d 100644 --- a/packages/controller/src/types.ts +++ b/packages/controller/src/types.ts @@ -87,6 +87,7 @@ export interface Keychain { ): Promise; logout(): Promise; openMenu(): Promise; + openSetDelegate(address: string): Promise; session(): Promise; sessions(): Promise<{ [key: string]: Session; diff --git a/packages/keychain/src/components/SetDelegate.tsx b/packages/keychain/src/components/SetDelegate.tsx index c1bebd018..a461c63af 100644 --- a/packages/keychain/src/components/SetDelegate.tsx +++ b/packages/keychain/src/components/SetDelegate.tsx @@ -7,11 +7,13 @@ import { CallData, num } from "starknet"; export function SetDelegate({ onClose, onSetDelegate, + defaultAddress, }: { onClose: () => void; onSetDelegate: (address: string) => void; + defaultAddress: string; }) { - const [delegateAddress, setDelegateAddress] = useState(""); + const [delegateAddress, setDelegateAddress] = useState(defaultAddress); const [isValid, setIsValid] = useState(true); useEffect(() => { diff --git a/packages/keychain/src/pages/index.tsx b/packages/keychain/src/pages/index.tsx index c099cbb60..3b11b3e87 100644 --- a/packages/keychain/src/pages/index.tsx +++ b/packages/keychain/src/pages/index.tsx @@ -168,6 +168,7 @@ function Home() { onSetDelegate={(delegateAddress) => { setDelegateTransaction(ctx, delegateAddress); }} + defaultAddress={ctx.account} /> );