Skip to content

Commit 2e35d1e

Browse files
committed
fix: Some work, but disconnect is still not ideal
1 parent 8f43604 commit 2e35d1e

File tree

2 files changed

+62
-13
lines changed

2 files changed

+62
-13
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ tmp
2525
*.njsproj
2626
*.sln
2727
*.sw?
28+
*.tgz
2829

2930
# Yarn
3031
.pnp.*

packages/up-provider/src/client.ts

Lines changed: 61 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,32 @@ function createClientUPProvider(authURL?: UPWindowConfig, search = true): UPClie
577577
}
578578

579579
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+
580606
await doSearch(client)
581607

582608
await startupPromise
@@ -707,21 +733,25 @@ function createClientUPProvider(authURL?: UPWindowConfig, search = true): UPClie
707733
up.emit('chainChanged', chainId)
708734
return
709735
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+
}
716744
return
717745
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+
}
725755
return
726756
case 'rpcUrlsChanged':
727757
rpcUrls = response.params
@@ -733,6 +763,24 @@ function createClientUPProvider(authURL?: UPWindowConfig, search = true): UPClie
733763
return
734764
case 'disconnect':
735765
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+
}
736784
up.emit('disconnect')
737785
return
738786
}

0 commit comments

Comments
 (0)