Skip to content
Merged
Show file tree
Hide file tree
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
26 changes: 26 additions & 0 deletions packages/store/__tests__/interchain-store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,30 @@ describe('InterchainStore', () => {
expect(osmosisKeplr).toBeUndefined();
});
});

describe('Current Wallet/Chain Auto-Sync', () => {
it('should set currentWalletName and currentChainName when connected', () => {
store.updateChainWalletState('keplr', 'cosmoshub', {
walletState: WalletState.Connected,
});

const state = store.getState();
expect(state.currentWalletName).toBe('keplr');
expect(state.currentChainName).toBe('cosmoshub');
});

it('should clear current when disconnecting the current wallet/chain', () => {
store.updateChainWalletState('keplr', 'cosmoshub', {
walletState: WalletState.Connected,
});

store.updateChainWalletState('keplr', 'cosmoshub', {
walletState: WalletState.Disconnected,
});

const state = store.getState();
expect(state.currentWalletName).toBe('');
expect(state.currentChainName).toBe('');
});
});
});
15 changes: 15 additions & 0 deletions packages/store/src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,21 @@ export class InterchainStore {
} else {
this.addChainWalletState(walletName, chainName, state);
}

switch (state.walletState) {
case WalletState.Connected:
this.setCurrentWalletName(walletName);
this.setCurrentChainName(chainName);
break;
case WalletState.Disconnected:
if (this.state.currentWalletName === walletName && this.state.currentChainName === chainName) {
// TODO: for supporting multiple wallet connections,
// we should set these to the previous instead of clearing
this.setCurrentWalletName('');
this.setCurrentChainName('');
}
break;
}
}

// 添加新的 chain wallet state
Expand Down
Loading