-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add register session * skip session_authorization when registering session * remove duplicate of assert_only_self * add register session tests * external owners * add external owners test * rebuild account * add delegate account --------- Co-authored-by: Szymon Wojtulewicz <[email protected]>
- Loading branch information
Showing
42 changed files
with
19,027 additions
and
16,155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
examples/starknet-react-next/src/components/DelegateAccount.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { useAccount } from "@starknet-react/core"; | ||
import { useCallback, useEffect, useState } from "react"; | ||
import { constants } from "starknet"; | ||
import CartridgeConnector from "@cartridge/connector"; | ||
|
||
export const DelegateAccount = () => { | ||
const [chainId] = useState<constants.StarknetChainId>( | ||
constants.StarknetChainId.SN_SEPOLIA, | ||
); | ||
const [submitted, setSubmitted] = useState<boolean>(false); | ||
const { account, connector } = useAccount(); | ||
|
||
const [delegateAddress, setDelegateAddress] = useState(""); | ||
const [delegateAddressInput, setDelegateAddressInput] = useState(""); | ||
const [isDelegateSupported, setIsDelegateSupported] = useState(false); | ||
|
||
const cartridgeConnector = connector as unknown as CartridgeConnector; | ||
|
||
const load = useCallback(async () => { | ||
if (!account) { | ||
return; | ||
} | ||
|
||
try { | ||
const delegate = await cartridgeConnector.delegateAccount(); | ||
setDelegateAddress(delegate?.toString() || ""); | ||
setIsDelegateSupported(true); | ||
} catch (e: any) { | ||
// controller doesnt support delegateAccount, ignore | ||
} | ||
}, [account, chainId]); | ||
|
||
const execute = useCallback(async () => { | ||
if (!account) { | ||
return; | ||
} | ||
setSubmitted(true); | ||
|
||
account | ||
.execute([ | ||
{ | ||
contractAddress: account.address, | ||
entrypoint: "set_delegate_account", | ||
calldata: [delegateAddressInput], | ||
}, | ||
]) | ||
.catch((e) => console.error(e)) | ||
.finally(() => setSubmitted(false)); | ||
}, [account, chainId, delegateAddressInput]); | ||
|
||
useEffect(() => { | ||
load(); | ||
}, [account, chainId, load]); | ||
|
||
if (!account) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<> | ||
<h2>Delegate account</h2> | ||
{isDelegateSupported ? ( | ||
<> | ||
<p> | ||
Address: {delegateAddress} | ||
<button onClick={() => load()}>Load</button> | ||
</p> | ||
|
||
<input | ||
type="text" | ||
min-width="420px" | ||
value={delegateAddressInput} | ||
onChange={(e) => setDelegateAddressInput(e.target.value)} | ||
/> | ||
<button onClick={() => execute()} disabled={submitted}> | ||
Set Delegate | ||
</button> | ||
</> | ||
) : ( | ||
<p>Not supported!</p> | ||
)} | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/account_sdk/compiled/controller.compiled_contract_class.json
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.