@@ -54,6 +54,9 @@ export let network: WalletStateSliceStore
54
54
export let balance : BalanceStore | WalletStateSliceStore
55
55
export let wallet : WritableStore
56
56
export let state : ReadableStore
57
+ export let walletInterface : WalletInterfaceStore
58
+
59
+ let currentSyncerIntervals : ( { clear : ( ) => void } | undefined ) [ ]
57
60
58
61
export function initializeStores ( ) {
59
62
address = createWalletStateSliceStore ( {
@@ -96,43 +99,39 @@ export function initializeStores() {
96
99
}
97
100
}
98
101
)
99
- }
100
102
101
- // keep track of intervals that are syncing state so they can be cleared
102
- let currentSyncerIntervals : ( { clear : ( ) => void } | undefined ) [ ] = [ ]
103
-
104
- export const walletInterface : WalletInterfaceStore = createWalletInterfaceStore (
105
- null
106
- )
107
-
108
- walletInterface . subscribe ( ( walletInterface : WalletInterface | null ) => {
109
- // make sure that stores have been initialized
110
- if ( state ) {
111
- // clear all current intervals if they exist
112
- currentSyncerIntervals . forEach (
113
- ( interval : { clear : ( ) => void } | undefined ) =>
114
- interval && interval . clear ( )
115
- )
116
-
117
- const currentState = get ( state )
118
-
119
- // reset state
120
- currentState . balance && balance . reset ( )
121
- currentState . address && address . reset ( )
122
- currentState . network && network . reset ( )
123
-
124
- if ( walletInterface ) {
125
- // start syncing state and save intervals
126
- currentSyncerIntervals = [
127
- address . setStateSyncer ( walletInterface . address ) ,
128
- network . setStateSyncer ( walletInterface . network ) ,
129
- balance . setStateSyncer ( walletInterface . balance )
130
- ]
131
- }
103
+ currentSyncerIntervals = [ ]
132
104
133
- resetCheckModules ( )
134
- }
135
- } )
105
+ walletInterface = createWalletInterfaceStore ( null )
106
+ walletInterface . subscribe ( ( walletInterface : WalletInterface | null ) => {
107
+ // make sure that stores have been initialized
108
+ if ( state ) {
109
+ // clear all current intervals if they exist
110
+ currentSyncerIntervals . forEach (
111
+ ( interval : { clear : ( ) => void } | undefined ) =>
112
+ interval && interval . clear ( )
113
+ )
114
+
115
+ const currentState = get ( state )
116
+
117
+ // reset state
118
+ currentState . balance && balance . reset ( )
119
+ currentState . address && address . reset ( )
120
+ currentState . network && network . reset ( )
121
+
122
+ if ( walletInterface ) {
123
+ // start syncing state and save intervals
124
+ currentSyncerIntervals = [
125
+ address . setStateSyncer ( walletInterface . address ) ,
126
+ network . setStateSyncer ( walletInterface . network ) ,
127
+ balance . setStateSyncer ( walletInterface . balance )
128
+ ]
129
+ }
130
+
131
+ resetCheckModules ( )
132
+ }
133
+ } )
134
+ }
136
135
137
136
export function resetWalletState ( options ?: {
138
137
disconnected : boolean
0 commit comments