@@ -6,15 +6,17 @@ import { toast } from "sonner";
66import { getContract , sendAndConfirmTransaction } from "thirdweb" ;
77import type { Chain , ThirdwebClient } from "thirdweb" ;
88import { defineChain } from "thirdweb/chains" ;
9- import { addSessionKey , isActiveSigner } from "thirdweb/extensions/erc4337" ;
9+ import {
10+ addSessionKey ,
11+ shouldUpdateSessionKey ,
12+ } from "thirdweb/extensions/erc4337" ;
1013import {
1114 ConnectButton ,
1215 ConnectEmbed ,
1316 useActiveAccount ,
1417 useActiveWallet ,
1518 useSiweAuth ,
1619} from "thirdweb/react" ;
17- import { isContractDeployed } from "thirdweb/utils" ;
1820import { type Account , inAppWallet } from "thirdweb/wallets" ;
1921import { createCode } from "../actions/create-code" ;
2022import {
@@ -163,31 +165,28 @@ async function ensureSessionKey(options: {
163165 client : options . client ,
164166 } ) ;
165167
168+ const shouldUpdateSessionkey = await shouldUpdateSessionKey ( {
169+ account : options . account ,
170+ client : options . client ,
171+ chain : options . chain ,
172+ sessionKeySignerAddress : options . sessionKeySignerAddress ,
173+ } ) ;
174+
166175 // check if already added
167- const accountDeployed = await isContractDeployed ( accountContract ) ;
168- if ( accountDeployed ) {
169- if (
170- await isActiveSigner ( {
171- contract : accountContract ,
172- signer : options . sessionKeySignerAddress ,
173- } )
174- ) {
175- return {
176- success : true ,
177- message : "Session key already added" ,
178- transaction : null ,
179- } ;
180- }
176+ if ( ! shouldUpdateSessionkey ) {
177+ return {
178+ success : true ,
179+ message : "Session key already added" ,
180+ transaction : null ,
181+ } ;
181182 }
182- // if not added, send tx to add the session key
183-
183+ // if not added or needs to be updated, send tx to add the session key
184184 const tx = await sendAndConfirmTransaction ( {
185185 account : options . account ,
186186 transaction : addSessionKey ( {
187187 account : options . account ,
188188 contract : accountContract ,
189189 sessionKeyAddress : options . sessionKeySignerAddress ,
190- // hard coded for now
191190 permissions : {
192191 approvedTargets :
193192 typeof options . permissions [ "contracts:write" ] === "boolean"
0 commit comments