diff --git a/apps/dialog/src/main.tsx b/apps/dialog/src/main.tsx index 46606f53d..18c5d4039 100644 --- a/apps/dialog/src/main.tsx +++ b/apps/dialog/src/main.tsx @@ -35,6 +35,10 @@ if (import.meta.env.PROD) { const offInitialized = Events.onInitialized(porto, async (payload, event) => { const { chainIds, features, labels, mode, referrer, theme } = payload + // Clear accounts on dialog init. If the parent has a connected account, + // it will be synced via when the first request comes in (requireAccountSync). + porto._internal.store.setState((x) => ({ ...x, accounts: [] })) + // Prevent showing stale route from a previous action. const pathname = Router.router.state.location.pathname.replace(/\/+$/, '') if (pathname !== '/dialog') await Router.router.navigate({ to: '/dialog' }) @@ -88,8 +92,12 @@ const offDialogRequest = Events.onDialogRequest( const connectedAccount = porto._internal.store.getState().accounts[0] - // Clear the dialog accounts if disconnected - if (!account && connectedAccount?.address) + // Only clear dialog accounts on explicit disconnect request. + // We do NOT clear accounts just because `account` is undefined in the request - + // that just means the request didn't specify a `from` address (e.g. wallet_sendCalls + // without `from`). The connected account should persist through such requests. + // See: https://github.com/ithacaxyz/porto/pull/1009 + if (request?.method === 'wallet_disconnect' && connectedAccount?.address) porto._internal.store.setState((x) => ({ ...x, accounts: [] })) const requireAccountSync =