Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: wallet state corruption round 4 #8519

Merged
merged 11 commits into from
Jan 13, 2025
Merged

Conversation

woodenfurniture
Copy link
Member

@woodenfurniture woodenfurniture commented Jan 9, 2025

Description

Patch for state corruption in wallet provider when user backs out of switching wallet. See #7904 for context.

The fix here is a patch to prevent corrupt state by preventing "back-out" of native connect into corrupt state by forcing the previous wallet to first disconnect before the password prompt is displayed.

Previous issue in simplified terms:

  1. User is connected to native wallet
  2. User clicks "switch wallet"
  3. User clicks different native wallet and is presented with password prompt
  4. WalletProvider updates the deviceId with the new wallet device ID
  5. User exits the password prompt without entering the password
  6. WalletProvider now has the wrong deviceId until they reconnect the wallet

This PR:

  1. User is connected to native wallet
  2. User clicks "switch wallet"
  3. User clicks different native wallet and is presented with password prompt
  4. Both the WalletProvider deviceId and the redux wallet ID are cleared, wallet is disconnected
  5. User exits the password prompt without entering the password
  6. User is in a disconnected state without mismatch of wallet device IDs

See below jam exaplaining in more detail.

Issue (if applicable)

closes #7904

Risk

High Risk PRs Require 2 approvals

High risk because it modifies WalletProvider and could theoretically result in inability to open a wallet.

What protocols, transaction types, wallets or contract interactions might be affected by this PR?

All wallets, especially native.

Testing

Thoroughly test opening/closing/switching wallets, with more emphasis on native wallet.
Sanity check signin, broadcasting, trading etc is not somehow unexpectedly broken.

Engineering

Operations

  • 🏁 My feature is behind a flag and doesn't require operations testing (yet)

Screenshots (if applicable)

Have a watch of my home movie explaining everything (audio on)
https://jam.dev/c/22a2572a-aeb6-4a82-a6c2-bd79bac3079d

@woodenfurniture woodenfurniture marked this pull request as ready for review January 9, 2025 05:15
@woodenfurniture woodenfurniture requested a review from a team as a code owner January 9, 2025 05:15
@gomesalexandre gomesalexandre self-requested a review January 9, 2025 15:49
src/App.tsx Outdated Show resolved Hide resolved
Copy link
Contributor

@gomesalexandre gomesalexandre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Diff-wise looks excellent.
A few comments mostly re: types and cleanup, but shouldn't really change anything at runtime (the KK event listeners would just be EventEmitter spew rather than an actual bug, assuming we ever end up there).

Runtime pass incoming, stay tuned 🎸

Copy link
Contributor

@gomesalexandre gomesalexandre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested localy, purposedly starting from a non nuked cache with these guys cached

  • two native wallet
  • two MIPD wallets
  • Ledger
  • KK

Wallet connection flow - right accounts derived and no race shenanigns

Native ✅

  • Native is happy e2e: unlock, refresh and unlock, disconnect/reconnect, keystore import ✅

https://jam.dev/c/3a4e5f08-8f0b-4e04-943b-f04beb3f2974

Ledger ✅

https://jam.dev/c/9e00c010-d8ca-4738-bce1-a04e3a54d8ad

KeepKey ✅

https://jam.dev/c/c2825d4c-12dc-4e47-8720-1c09a1b8c728

MIPD Wallets ✅

https://jam.dev/c/3db330fc-71b8-4d09-af17-ae2089608d83

Phantom ✅

https://jam.dev/c/0bb2142a-7fab-4d48-83c5-34797c68ae2b

Signing

Native ✅

https://jam.dev/c/c29ed56d-1df7-44fc-98ff-7bad41b18294

MIPD ✅

https://jam.dev/c/c951c98e-ab0b-4326-8a38-ea420f7c787e

KK ✅

https://jam.dev/c/c7be8103-d524-406b-adb8-a90856481e30

Ledger ✅

https://jam.dev/c/89b5c194-f71b-49a6-ad3f-e149ba213150

Noted one smolish bug however, which I can also repro in develop, not introduced by this diff. Captured in #8535.

@woodenfurniture woodenfurniture force-pushed the wallet-state-corruption-4 branch from ca7169e to 6466cf1 Compare January 12, 2025 23:32
@0xApotheosis 0xApotheosis self-assigned this Jan 13, 2025
Copy link
Member

@0xApotheosis 0xApotheosis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking solid - tried every combination of switching/disconnecting wallets - all worked well, signing still happy.

src/context/WalletProvider/actions.ts Outdated Show resolved Hide resolved
src/App.tsx Outdated Show resolved Hide resolved
@woodenfurniture woodenfurniture force-pushed the wallet-state-corruption-4 branch from 1d9cd18 to ab62b81 Compare January 13, 2025 22:01
@woodenfurniture woodenfurniture enabled auto-merge (squash) January 13, 2025 22:03
@woodenfurniture woodenfurniture merged commit e600c08 into develop Jan 13, 2025
3 checks passed
@woodenfurniture woodenfurniture deleted the wallet-state-corruption-4 branch January 13, 2025 22:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Redux wallet state diverges from context
3 participants