File tree Expand file tree Collapse file tree 3 files changed +27
-12
lines changed Expand file tree Collapse file tree 3 files changed +27
-12
lines changed Original file line number Diff line number Diff line change @@ -165,6 +165,7 @@ export enum WalletState {
165
165
export interface WalletEvents {
166
166
'accountChanged' : [ event : any ] ;
167
167
'displayWalletConnectQRCodeUri' : [ chainId : string ] ;
168
+ 'disconnect' : [ event : any ] ;
168
169
}
169
170
170
171
export const WcProviderEventType = {
Original file line number Diff line number Diff line change @@ -55,7 +55,7 @@ export class WCWallet extends BaseWallet {
55
55
}
56
56
57
57
async init ( ) : Promise < void > {
58
- this . events . removeAllListeners ( ) ;
58
+ // this.events.removeAllListeners()
59
59
60
60
const defaultOption : UniversalProviderOpts = {
61
61
projectId : '15a12f05b38b78014b2bb06d77eecdc3' ,
@@ -330,9 +330,12 @@ export class WCWallet extends BaseWallet {
330
330
console . error ( 'disconnect:' , error ) ;
331
331
} ) ;
332
332
333
- this . provider . on ( 'session_delete' , ( error : { message : string ; code : number } ) => {
334
- console . log ( 'session_delete:' , event ) ;
335
- localStorage . removeItem ( 'wc-session' ) ;
333
+ this . provider . on ( "session_delete" , ( error : { message : string ; code : number } ) => {
334
+ console . log ( "session_delete:" , error ) ;
335
+ localStorage . removeItem ( 'wc-session' )
336
+
337
+ // Emit disconnect event to notify StatefulWallet
338
+ this . events . emit ( 'disconnect' , '' )
336
339
} ) ;
337
340
338
341
this . provider . on ( 'session_event' , ( error : { message : string ; code : number } ) => {
Original file line number Diff line number Diff line change @@ -66,16 +66,27 @@ export class StatefulWallet extends BaseWallet {
66
66
67
67
async init ( ) : Promise < void > {
68
68
69
- this . originalWallet . events . on ( 'accountChanged' , async ( ) => {
70
- const chains = Array . from ( this . originalWallet . chainMap . values ( ) )
71
- for ( const chain of chains ) {
72
- await this . getAccount ( chain . chainId )
73
- }
74
- } )
75
-
76
-
77
69
try {
78
70
await this . originalWallet . init ( )
71
+
72
+ this . originalWallet . events . on ( 'accountChanged' , async ( ) => {
73
+ const chains = Array . from ( this . originalWallet . chainMap . values ( ) )
74
+ for ( const chain of chains ) {
75
+ await this . getAccount ( chain . chainId )
76
+ }
77
+ } )
78
+
79
+ this . originalWallet . events . on ( 'disconnect' , ( ) => {
80
+ // Update all chains for this wallet to disconnected state
81
+ this . store . chains . forEach ( chain => {
82
+ this . store . updateChainWalletState ( this . walletName , chain . chainName , {
83
+ walletState : WalletState . Disconnected ,
84
+ account : null ,
85
+ errorMessage : ''
86
+ } ) ;
87
+ } ) ;
88
+ } ) ;
89
+
79
90
this . store . chains . forEach ( chain => {
80
91
const lastChainWalletState = this . store . getChainWalletState ( this . walletName , chain . chainName ) ?. walletState
81
92
if ( lastChainWalletState === WalletState . NotExist ) {
You can’t perform that action at this time.
0 commit comments