fix: repair wallet state on delete (closes #156) #194
Reference in New Issue
Block a user
Delete Branch "fix/issue-156-delete-last-wallet"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #156.
The three fixes
All in the delete path; the transition moved into
src/shared/walletDelete.js(removeWalletFromState) so it is testablewithout a DOM.
src/popup/views/deleteWallet.jscalls it and keeps thepassword gate, the view stack handling and the site-permission cleanup
unchanged.
hasWalletis nowstate.wallets.length > 0after the splice.Deleting the last wallet sets it false, so the next popup open hits
if (!state.hasWallet)insrc/popup/index.jsand renders Welcomeinstead of Home's "No wallets yet".
selectedWallet === walletIdxfalls back to the first remainingwallet's first address (
0/0);selectedWallet > walletIdxisdecremented to follow the splice; otherwise it is untouched.
activeAddressmoves only when it is one of the deleted wallet'saddresses (fallback: first remaining wallet's first address, or null
when no wallet remains).
AUTISTMASK_ACTIVE_CHANGEDis broadcast whenever the activeaddress actually changed, in the same call shape as the address
switch in
src/popup/views/home.js. It is sent aftersaveState(),because the background reads the active address back out of storage
to build
accountsChanged; the existing handler insrc/background/index.jsthen callsbroadcastAccountsChanged(), soa connected site sees the change (or
[]when the last wallet isgone) instead of a deleted address. No background change was needed.
Site-permission cleanup already mapped over
wallet.addresses, so itcovers every address of an HD wallet; a test now pins that.
Tests
New
tests/walletDelete.test.js, one case per behaviour: last wallet,non-selected wallet before the selection (index shift), wallet after the
selection, active wallet (fallback + change flag), permission cleanup for
every address of a two-address HD wallet, and the broadcast call shape.
Demonstrated failing against the unfixed code
src/shared/walletDelete.jswas temporarily replaced with the pre-fixlogic transcribed from the old inline block in
deleteWallet.js(unconditional
selectedWallet = 0/selectedAddress = 0, nohasWalletupdate, no broadcast), andmake testrun:The permission-cleanup case passes pre-fix, as expected — that part was
already correct and the test exists to keep it that way.
make checkHost, on the rebased branch:
And in the container, via
script/cibuild(docker build ., exit 0) onthe same tree:
Not verified
Manually in a real browser, and not by
make test-e2e— the end-to-endsuite has no wallet-deletion scenario. The wiring inside
deleteWallet.js(that the click handler calls the transition and thebroadcast) is covered by reading, not by a test: importing that view
pulls in the DOM helpers and the vault.
The README TODO checkbox for "Delete wallet (with confirmation)" is
ticked, since the feature exists.
Independent review: PASS — index arithmetic, broadcast wiring, test teeth (5/6 reproduced failing against pre-fix logic in my own clone), policy and containerized
make checkall verified.Disclosure: two DoD items of #156 — "reopen lands on Welcome" and "a connected dApp observes the account change" — were verified by tracing the code path only (
src/popup/index.js:265;AUTISTMASK_ACTIVE_CHANGED->src/background/index.js:804->broadcastAccountsChanged()), not in a real browser, as the author disclosed.