File tree Expand file tree Collapse file tree 1 file changed +19
-3
lines changed Expand file tree Collapse file tree 1 file changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -154,9 +154,17 @@ function createWalletStateSliceStore(options: {
154
154
const { parameter, initialState } = options
155
155
const { subscribe, set } = writable ( initialState )
156
156
157
+ let currentState : string | number | null | undefined
158
+ const unsubscribe = subscribe ( store => {
159
+ currentState = store
160
+ } )
161
+
157
162
return {
158
163
subscribe,
159
- reset : ( ) => set ( undefined ) ,
164
+ reset : ( ) => {
165
+ unsubscribe ( )
166
+ set ( undefined )
167
+ } ,
160
168
setStateSyncer : ( stateSyncer : StateSyncer ) => {
161
169
validateType ( { name : 'stateSyncer' , value : stateSyncer , type : 'object' } )
162
170
@@ -177,14 +185,22 @@ function createWalletStateSliceStore(options: {
177
185
} )
178
186
179
187
if ( onChange ) {
180
- onChange ( set )
188
+ onChange ( newVal => {
189
+ if ( newVal || currentState !== initialState ) {
190
+ set ( newVal )
191
+ }
192
+ } )
181
193
return
182
194
}
183
195
184
196
if ( get ) {
185
197
const interval : any = setInterval ( ( ) => {
186
198
get ( )
187
- . then ( set )
199
+ . then ( newVal => {
200
+ if ( newVal || currentState !== initialState ) {
201
+ set ( newVal )
202
+ }
203
+ } )
188
204
. catch ( ( err : any ) => {
189
205
console . warn (
190
206
`Error getting ${ parameter } from state syncer: ${ err } `
You can’t perform that action at this time.
0 commit comments