Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions apps/dialog/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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' })
Expand Down Expand Up @@ -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 =
Expand Down
Loading