Repository navigation
fix(store): do not restore a NotExist wallet state from localStorage - #51
Merged
pyramation merged 1 commit intoOct 23, 2026
Merged
Conversation
When an extension wallet is injected after document.readyState reaches 'complete' (e.g. Keplr's MV3 build on a cold browser start), init() throws 'Client not exist' and WalletStore.init() marks the wallet NotExist on every chain. That state is persisted, and restore() brought it back on every later load while a successful init() never cleared it. Since ChainWalletStore.connect() returns early for NotExist, the wallet stayed 'not installed' and connect() did nothing until the user cleared site data. restore() now maps a saved NotExist to Disconnected; init() still sets NotExist on a load where the extension is really missing. Also fix the swapped getChainWalletState(walletName, chainName) arguments in the ChainWalletStore walletState/errorMessage getters, which made them always fall back to NotExist / '' (the existing test asserted the swapped order).
7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
If a browser extension wallet hasn't injected its client by the time
document.readyStatereachescomplete,getClientFromExtension()throwsClient not exist. This happens with Keplr's MV3 build, which addswindow.keplrfrom a service-worker-registered script, typically on a cold browser start. When it does, the wallet stays in that state on that browser for good:WalletStore.init()catches the error and setswalletState: NotExistfor that wallet on every chain.interchain-kit-store).restore()brings the savedchainWalletStatesback as they are. A successfulinit()never resets them.NotExist,ChainWalletStore.connect()returns early, so connecting does nothing.The modal shows " Not Installed" and asks the user to refresh, but refreshing can't fix it. The only way out is clearing the site's storage.
Separately,
ChainWalletStore'swalletStateanderrorMessagegetters callgetChainWalletState(this.chain.chainName, this.wallet.info.name). The store's signature isgetChainWalletState(walletName, chainName), so the lookup never matches:walletStatealways returnsNotExistanderrorMessagealways returns''. The existing unit test asserted the swapped order, so it never caught this.Fix
restore()turns a savedNotExistentry intoDisconnected(and clears its error message). If the extension really is missing,init()setsNotExistagain on that load, so the "not installed" view still works.(walletName, chainName).Tests
chain-wallet-store.test.ts: thewalletStatetest now expects('keplr', 'cosmoshub'), and theerrorMessagetest checks the arguments too.wallet-manager-store.test.ts: new test, "should restore a saved NotExist state as Disconnected". It checks the firstsetStatecall, which is the one that writes the restored state.packages/store: 178/178 tests pass. Without the source change, these 3 tests fail.Reproduce
walletStateto"NotExist"for thekeplr-extensionentries in localStorageinterchain-kit-store.