File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed
Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -238,4 +238,30 @@ describe('InterchainStore', () => {
238238 expect ( osmosisKeplr ) . toBeUndefined ( ) ;
239239 } ) ;
240240 } ) ;
241+
242+ describe ( 'Current Wallet/Chain Auto-Sync' , ( ) => {
243+ it ( 'should set currentWalletName and currentChainName when connected' , ( ) => {
244+ store . updateChainWalletState ( 'keplr' , 'cosmoshub' , {
245+ walletState : WalletState . Connected ,
246+ } ) ;
247+
248+ const state = store . getState ( ) ;
249+ expect ( state . currentWalletName ) . toBe ( 'keplr' ) ;
250+ expect ( state . currentChainName ) . toBe ( 'cosmoshub' ) ;
251+ } ) ;
252+
253+ it ( 'should clear current when disconnecting the current wallet/chain' , ( ) => {
254+ store . updateChainWalletState ( 'keplr' , 'cosmoshub' , {
255+ walletState : WalletState . Connected ,
256+ } ) ;
257+
258+ store . updateChainWalletState ( 'keplr' , 'cosmoshub' , {
259+ walletState : WalletState . Disconnected ,
260+ } ) ;
261+
262+ const state = store . getState ( ) ;
263+ expect ( state . currentWalletName ) . toBe ( '' ) ;
264+ expect ( state . currentChainName ) . toBe ( '' ) ;
265+ } ) ;
266+ } ) ;
241267} ) ;
Original file line number Diff line number Diff line change @@ -78,6 +78,21 @@ export class InterchainStore {
7878 } else {
7979 this . addChainWalletState ( walletName , chainName , state ) ;
8080 }
81+
82+ switch ( state . walletState ) {
83+ case WalletState . Connected :
84+ this . setCurrentWalletName ( walletName ) ;
85+ this . setCurrentChainName ( chainName ) ;
86+ break ;
87+ case WalletState . Disconnected :
88+ if ( this . state . currentWalletName === walletName && this . state . currentChainName === chainName ) {
89+ // TODO: for supporting multiple wallet connections,
90+ // we should set these to the previous instead of clearing
91+ this . setCurrentWalletName ( '' ) ;
92+ this . setCurrentChainName ( '' ) ;
93+ }
94+ break ;
95+ }
8196 }
8297
8398 // 添加新的 chain wallet state
You can’t perform that action at this time.
0 commit comments