@@ -75,54 +75,55 @@ export const walletInterface: WalletInterfaceStore = createWalletInterfaceStore(
75
75
)
76
76
77
77
walletInterface . subscribe ( ( walletInterface : WalletInterface | null ) => {
78
- if ( walletInterface ) {
79
- const currentState = get ( state )
80
- // reset state
81
- currentState . balance && balance . reset ( )
82
- currentState . address && address . reset ( )
83
- currentState . network && network . reset ( )
78
+ // clear all current intervals if they exist
79
+ currentSyncerIntervals . forEach (
80
+ ( interval : number | undefined ) => interval && clearInterval ( interval )
81
+ )
84
82
85
- // clear all current intervals if they exist
86
- currentSyncerIntervals . forEach (
87
- ( interval : number | undefined ) => interval && clearInterval ( interval )
88
- )
83
+ const currentState = get ( state )
89
84
85
+ // reset state
86
+ currentState . balance && balance . reset ( )
87
+ currentState . address && address . reset ( )
88
+ currentState . network && network . reset ( )
89
+
90
+ if ( walletInterface ) {
90
91
// start syncing state and save intervals
91
92
currentSyncerIntervals = [
92
93
address . setStateSyncer ( walletInterface . address ) ,
93
94
network . setStateSyncer ( walletInterface . network ) ,
94
95
balance . setStateSyncer ( walletInterface . balance )
95
96
]
97
+ } else {
98
+ wallet . update ( ( ) => ( {
99
+ name : undefined ,
100
+ provider : undefined ,
101
+ connect : undefined ,
102
+ instance : undefined ,
103
+ url : undefined ,
104
+ loading : undefined
105
+ } ) )
96
106
}
97
107
} )
98
108
99
- export function resetWalletState ( options : { disconnected ?: boolean } = { } ) {
100
- // clear all current intervals if they exist
101
- currentSyncerIntervals . forEach (
102
- ( interval : number | undefined ) => interval && clearInterval ( interval )
103
- )
104
-
109
+ export function resetWalletState (
110
+ options : { disconnected ?: boolean ; walletName ?: string } = { }
111
+ ) {
105
112
walletInterface . update ( ( currentInterface : WalletInterface | null ) => {
106
- const { disconnected } = options
107
- ! disconnected &&
108
- currentInterface &&
109
- currentInterface . disconnect &&
110
- currentInterface . disconnect ( )
111
- return null
112
- } )
113
-
114
- wallet . update ( ( ) => ( {
115
- name : undefined ,
116
- provider : undefined ,
117
- connect : undefined ,
118
- instance : undefined ,
119
- url : undefined ,
120
- loading : undefined
121
- } ) )
113
+ if (
114
+ ! options . walletName ||
115
+ ( currentInterface && currentInterface . name === options . walletName )
116
+ ) {
117
+ const { disconnected } = options
118
+ ! disconnected &&
119
+ currentInterface &&
120
+ currentInterface . disconnect &&
121
+ currentInterface . disconnect ( )
122
+ return null
123
+ }
122
124
123
- balance . reset ( )
124
- address . reset ( )
125
- network . reset ( )
125
+ return currentInterface
126
+ } )
126
127
127
128
app . update ( store => ( {
128
129
...store ,
0 commit comments