diff --git a/packages/core/src/controllers/AccountController.ts b/packages/core/src/controllers/AccountController.ts index 5469a56a2e..20262aba7e 100644 --- a/packages/core/src/controllers/AccountController.ts +++ b/packages/core/src/controllers/AccountController.ts @@ -77,5 +77,6 @@ export const AccountController = { state.profileName = undefined state.profileImage = undefined state.addressExplorerUrl = undefined + state.smartAccountDeployed = undefined } } diff --git a/packages/ethers/src/client.ts b/packages/ethers/src/client.ts index 3d1e6fc82c..a40ab675cf 100644 --- a/packages/ethers/src/client.ts +++ b/packages/ethers/src/client.ts @@ -37,7 +37,6 @@ import type { EthereumProviderOptions } from '@walletconnect/ethereum-provider' import type { Eip1193Provider } from 'ethers' import { W3mFrameProvider, W3mFrameHelpers, W3mFrameRpcConstants } from '@web3modal/wallet' import type { CombinedProvider } from '@web3modal/scaffold-utils/ethers' -import { AccountController } from '@web3modal/core' // -- Types --------------------------------------------------------------------- export interface Web3ModalClientOptions extends Omit { @@ -618,7 +617,7 @@ export class Web3Modal extends Web3ModalScaffold { EthersStoreUtil.setProvider(this.emailProvider as unknown as CombinedProvider) EthersStoreUtil.setIsConnected(true) const { isDeployed, address: smartAccountAddress } = await this.initSmartAccount(chainId) - AccountController.setSmartAccountDeployed(isDeployed) + this.setSmartAccountDeployed(isDeployed) if (isDeployed && smartAccountAddress) { EthersStoreUtil.setAddress(smartAccountAddress as Address) } else { diff --git a/packages/scaffold/src/client.ts b/packages/scaffold/src/client.ts index 283c1ca1ea..89dbf64ff9 100644 --- a/packages/scaffold/src/client.ts +++ b/packages/scaffold/src/client.ts @@ -197,6 +197,10 @@ export class Web3ModalScaffold { AccountController.setAddressExplorerUrl(addressExplorerUrl) } + protected setSmartAccountDeployed: (typeof AccountController)['setSmartAccountDeployed'] = + isDeployed => { + AccountController.setSmartAccountDeployed(isDeployed) + } // -- Private ------------------------------------------------------------------ private async initControllers(options: ScaffoldOptions) { NetworkController.setClient(options.networkControllerClient) diff --git a/packages/wagmi/src/client.ts b/packages/wagmi/src/client.ts index da6c7ff277..b6753d6fb5 100644 --- a/packages/wagmi/src/client.ts +++ b/packages/wagmi/src/client.ts @@ -393,6 +393,11 @@ export class Web3Modal extends Web3ModalScaffold { if (isLoginEmailUsed) { this.setIsConnected(false) } + + provider.onInitSmartAccount((isDeployed: boolean) => { + this.setSmartAccountDeployed(isDeployed) + }) + provider.onRpcRequest(request => { if (W3mFrameHelpers.checkIfRequestExists(request)) { if (!W3mFrameHelpers.checkIfRequestIsAllowed(request)) { diff --git a/packages/wagmi/src/connectors/EmailConnector.ts b/packages/wagmi/src/connectors/EmailConnector.ts index fc0f6edd54..9c7b30fdc7 100644 --- a/packages/wagmi/src/connectors/EmailConnector.ts +++ b/packages/wagmi/src/connectors/EmailConnector.ts @@ -4,7 +4,6 @@ import { SwitchChainError, getAddress } from 'viem' import type { Address } from 'viem' import { ConstantsUtil } from '@web3modal/scaffold-utils' -import { AccountController } from '@web3modal/core' // -- Types ---------------------------------------------------------------------------------------- interface W3mFrameProviderOptions { @@ -38,7 +37,6 @@ export function emailConnector(parameters: EmailParameters) { if (smartAccountEnabledNetworks.includes(chainId)) { const { address: smartAccountAddress, isDeployed } = await provider.initSmartAccount() - AccountController.setSmartAccountDeployed(isDeployed) if (isDeployed) { return { accounts: [smartAccountAddress as Address], diff --git a/packages/wallet/src/W3mFrameProvider.ts b/packages/wallet/src/W3mFrameProvider.ts index e41cdb6040..7766dc9639 100644 --- a/packages/wallet/src/W3mFrameProvider.ts +++ b/packages/wallet/src/W3mFrameProvider.ts @@ -396,6 +396,16 @@ export class W3mFrameProvider { }) } + public onInitSmartAccount(callback: (isDeployed: boolean) => void) { + this.w3mFrame.events.onFrameEvent(event => { + if (event.type === W3mFrameConstants.FRAME_INIT_SMART_ACCOUNT_SUCCESS) { + callback(event.payload.isDeployed) + } else if (event.type === W3mFrameConstants.FRAME_INIT_SMART_ACCOUNT_ERROR) { + callback(false) + } + }) + } + // -- Promise Handlers ------------------------------------------------ private onConnectEmailSuccess( event: Extract @@ -637,7 +647,7 @@ export class W3mFrameProvider { } private setLastUsedChainId(chainId: number) { - W3mFrameStorage.set(W3mFrameConstants.LAST_USED_CHAIN_KEY, `${chainId}`) + W3mFrameStorage.set(W3mFrameConstants.LAST_USED_CHAIN_KEY, String(chainId)) } private getLastUsedChainId() {