@@ -6,15 +6,14 @@ 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 { addSessionKey } from "thirdweb/extensions/erc4337" ;
1010import {
1111 ConnectButton ,
1212 ConnectEmbed ,
1313 useActiveAccount ,
1414 useActiveWallet ,
1515 useSiweAuth ,
1616} from "thirdweb/react" ;
17- import { isContractDeployed } from "thirdweb/utils" ;
1817import { type Account , inAppWallet } from "thirdweb/wallets" ;
1918import { createCode } from "../actions/create-code" ;
2019import {
@@ -163,31 +162,28 @@ async function ensureSessionKey(options: {
163162 client : options . client ,
164163 } ) ;
165164
165+ const shouldUpdateSessionkey = await shouldUpdateSessionKey ( {
166+ account : options . account ,
167+ client : options . client ,
168+ chain : options . chain ,
169+ sessionKeySignerAddress : options . sessionKeySignerAddress ,
170+ } ) ;
171+
166172 // 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- }
173+ if ( ! shouldUpdateSessionkey ) {
174+ return {
175+ success : true ,
176+ message : "Session key already added" ,
177+ transaction : null ,
178+ } ;
181179 }
182- // if not added, send tx to add the session key
183-
180+ // if not added or needs to be updated, send tx to add the session key
184181 const tx = await sendAndConfirmTransaction ( {
185182 account : options . account ,
186183 transaction : addSessionKey ( {
187184 account : options . account ,
188185 contract : accountContract ,
189186 sessionKeyAddress : options . sessionKeySignerAddress ,
190- // hard coded for now
191187 permissions : {
192188 approvedTargets :
193189 typeof options . permissions [ "contracts:write" ] === "boolean"
0 commit comments