Skip to content

fix: recreate EVM adapter on account change - #46

Draft
danilaverbena wants to merge 1 commit into
circlefin:masterfrom
danilaverbena:agent/fix-evm-adapter-account-switch
Draft

fix: recreate EVM adapter on account change#46
danilaverbena wants to merge 1 commit into
circlefin:masterfrom
danilaverbena:agent/fix-evm-adapter-account-switch

Conversation

@danilaverbena

Copy link
Copy Markdown

Summary

  • recreate the EVM adapter when the connected Wagmi address changes, even when the provider object stays the same
  • cancel stale asynchronous adapter initialization when the hook dependencies change or the component unmounts

Why

createViemAdapterFromProvider lazily caches the connected account. The hook previously recreated the adapter only when the provider identity changed, while merely recording address changes in lastAddressRef. Switching accounts in the same wallet therefore left Bridge Kit using an adapter bound to the previous account.

The effect also declared a cancellation flag without registering cleanup, allowing an older asynchronous initialization to overwrite the adapter selected by a newer render.

This change keeps the adapter account aligned with the address shown by Wagmi and prevents stale initialization races.

Validation

  • npm run build
  • npm run lint (0 errors; one pre-existing unrelated warning in src/components/theme-provider.tsx)
  • git diff --check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants