@@ -577,6 +577,32 @@ function createClientUPProvider(authURL?: UPWindowConfig, search = true): UPClie
577
577
}
578
578
579
579
client . request = async ( method : string | { method : string ; params : unknown [ ] } , params ?: unknown [ ] ) => {
580
+ const methodName = typeof method === 'string' ? method : method . method
581
+ switch ( methodName ) {
582
+ case 'wallet_revokePermissions' :
583
+ // This is a special case for revoke permissions.
584
+ if ( ( allowedAccounts ?. length ?? 0 ) > 0 ) {
585
+ allowedAccounts = [ ]
586
+ persist ( )
587
+ remote . emit (
588
+ 'accountsChanged' ,
589
+ // Cleanup wrong null or undefined.
590
+ cleanupAccounts ( allowedAccounts )
591
+ )
592
+ }
593
+ if ( ( contextAccounts ?. length ?? 0 ) > 0 ) {
594
+ contextAccounts = [ ]
595
+ persist ( )
596
+ remote . emit (
597
+ 'contextAccountsChanged' ,
598
+ // Cleanup wrong null or undefined.
599
+ cleanupAccounts ( contextAccounts )
600
+ )
601
+ }
602
+ remote . emit ( 'disconnect' )
603
+ return null
604
+ }
605
+
580
606
await doSearch ( client )
581
607
582
608
await startupPromise
@@ -707,21 +733,25 @@ function createClientUPProvider(authURL?: UPWindowConfig, search = true): UPClie
707
733
up . emit ( 'chainChanged' , chainId )
708
734
return
709
735
case 'contextAccountsChanged' :
710
- contextAccounts = response . params
711
- up . emit (
712
- 'contextAccountsChanged' ,
713
- // Cleanup wrong null or undefined.
714
- cleanupAccounts ( contextAccounts )
715
- )
736
+ if ( ( contextAccounts ?. length ?? 0 ) !== ( response . params ?. length ?? 0 ) || contextAccounts ?. some ( ( account , index ) => account !== response . params [ index ] ) ) {
737
+ contextAccounts = response . params
738
+ up . emit (
739
+ 'contextAccountsChanged' ,
740
+ // Cleanup wrong null or undefined.
741
+ cleanupAccounts ( contextAccounts )
742
+ )
743
+ }
716
744
return
717
745
case 'accountsChanged' :
718
- allowedAccounts = response . params
719
- persist ( )
720
- up . emit (
721
- 'accountsChanged' ,
722
- // Cleanup wrong null or undefined.
723
- cleanupAccounts ( allowedAccounts )
724
- )
746
+ if ( ( allowedAccounts ?. length ?? 0 ) !== ( response . params ?. length ?? 0 ) || allowedAccounts ?. some ( ( account , index ) => account !== response . params [ index ] ) ) {
747
+ allowedAccounts = response . params
748
+ persist ( )
749
+ up . emit (
750
+ 'accountsChanged' ,
751
+ // Cleanup wrong null or undefined.
752
+ cleanupAccounts ( allowedAccounts )
753
+ )
754
+ }
725
755
return
726
756
case 'rpcUrlsChanged' :
727
757
rpcUrls = response . params
@@ -733,6 +763,24 @@ function createClientUPProvider(authURL?: UPWindowConfig, search = true): UPClie
733
763
return
734
764
case 'disconnect' :
735
765
options . connectEmitted = false
766
+ if ( ( allowedAccounts ?. length ?? 0 ) > 0 ) {
767
+ allowedAccounts = [ ]
768
+ persist ( )
769
+ up . emit (
770
+ 'accountsChanged' ,
771
+ // Cleanup wrong null or undefined.
772
+ cleanupAccounts ( allowedAccounts )
773
+ )
774
+ }
775
+ if ( ( contextAccounts ?. length ?? 0 ) > 0 ) {
776
+ contextAccounts = [ ]
777
+ persist ( )
778
+ up . emit (
779
+ 'contextAccountsChanged' ,
780
+ // Cleanup wrong null or undefined.
781
+ cleanupAccounts ( contextAccounts )
782
+ )
783
+ }
736
784
up . emit ( 'disconnect' )
737
785
return
738
786
}
0 commit comments