From 1b917f357d14ef6f92416b5307fa783c6792ad57 Mon Sep 17 00:00:00 2001 From: Mark Nardi Date: Wed, 26 Jun 2024 11:24:37 +0200 Subject: [PATCH] feat: update session on login rather than disconnecting wallet connect session (#2630) * update session on login * update persisted dapp story types * fix dapp drawer * show fallback if not connected to profile * fix locale * fix remove connected dapps * fix clearing expired dapps --- .../dapp-config/components/DappCard.svelte | 2 +- .../components/EditSelectionDrawer.svelte | 4 +- .../views/ConfirmConnectionDrawer.svelte | 10 +-- .../views/ConnectedDappsDrawer.svelte | 13 +--- .../views/DappDetailsDrawer.svelte | 9 +-- .../wallet-connect/actions/connectToDapp.ts | 4 +- .../actions/removeAllDisconnectedDapps.ts | 11 ++- .../stores/persisted-dapp-namespaces.store.ts | 9 ++- .../stores/persisted-dapps.store.ts | 68 +++++++++++-------- .../utils/buildDefaultNamespaces.ts | 36 ++++++++++ .../auxiliary/wallet-connect/utils/index.ts | 3 + .../utils/normalizeSupportedNamespace.ts | 16 +++++ .../updateActiveSessionsToActiveProfile.ts | 34 ++++++++++ .../profile/actions/active-profile/login.ts | 4 +- .../alpha/alpha-profile-migration-15-to-16.ts | 3 +- .../prod/prod-profile-migration-8-to-9.ts | 7 +- packages/shared/src/locales/en.json | 1 + 17 files changed, 168 insertions(+), 66 deletions(-) create mode 100644 packages/shared/src/lib/auxiliary/wallet-connect/utils/buildDefaultNamespaces.ts create mode 100644 packages/shared/src/lib/auxiliary/wallet-connect/utils/normalizeSupportedNamespace.ts create mode 100644 packages/shared/src/lib/auxiliary/wallet-connect/utils/updateActiveSessionsToActiveProfile.ts diff --git a/packages/desktop/views/dashboard/drawers/dapp-config/components/DappCard.svelte b/packages/desktop/views/dashboard/drawers/dapp-config/components/DappCard.svelte index 0ecea8e1ae..f025c3f431 100644 --- a/packages/desktop/views/dashboard/drawers/dapp-config/components/DappCard.svelte +++ b/packages/desktop/views/dashboard/drawers/dapp-config/components/DappCard.svelte @@ -12,7 +12,7 @@ export let onClick: (() => unknown) | undefined = undefined $: networkIds = Object.values( - dapp.session?.namespaces ?? getPersistedDappNamespacesForDapp(dapp.metadata?.url ?? '')?.supported ?? {} + dapp.session?.namespaces ?? getPersistedDappNamespacesForDapp(dapp.metadata?.url ?? '') ?? {} ).flatMap((namespace) => namespace.chains as NetworkId[]) $: verifiedState = $activeProfileId diff --git a/packages/desktop/views/dashboard/drawers/dapp-config/components/EditSelectionDrawer.svelte b/packages/desktop/views/dashboard/drawers/dapp-config/components/EditSelectionDrawer.svelte index 7809483912..9a167dc4d8 100644 --- a/packages/desktop/views/dashboard/drawers/dapp-config/components/EditSelectionDrawer.svelte +++ b/packages/desktop/views/dashboard/drawers/dapp-config/components/EditSelectionDrawer.svelte @@ -32,7 +32,7 @@ selections, requiredNamespaces, optionalNamespaces, - persistedDapp?.namespaces.supported + persistedDapp?.supported ) updateSupportedDappNamespacesForDapp(dappMetadata.url, updatedNamespace) if ($selectedDapp?.session) { @@ -59,7 +59,7 @@
diff --git a/packages/desktop/views/dashboard/drawers/dapp-config/views/ConfirmConnectionDrawer.svelte b/packages/desktop/views/dashboard/drawers/dapp-config/views/ConfirmConnectionDrawer.svelte index 888df6871c..0ef46d540d 100644 --- a/packages/desktop/views/dashboard/drawers/dapp-config/views/ConfirmConnectionDrawer.svelte +++ b/packages/desktop/views/dashboard/drawers/dapp-config/views/ConfirmConnectionDrawer.svelte @@ -4,7 +4,7 @@ import { DappVerification } from '@auxiliary/wallet-connect/enums' import { clearSessionInitiationRequest, - getPersistedDappNamespacesForDapp, + getPersistedDapp, sessionInitiationRequest, } from '@auxiliary/wallet-connect/stores' import { ISupportedNamespace, SupportedNamespaces } from '@auxiliary/wallet-connect/types' @@ -63,12 +63,12 @@ return {} } - const persistedNamespaces = $sessionInitiationRequest - ? getPersistedDappNamespacesForDapp($sessionInitiationRequest.params.proposer.metadata.url) + const persistedDapp = $sessionInitiationRequest + ? getPersistedDapp($sessionInitiationRequest.params.proposer.metadata.url) : undefined - if (persistedNamespaces) { - return persistedNamespaces.supported + if (persistedDapp?.supported) { + return persistedDapp.supported } const { requiredNamespaces, optionalNamespaces } = $sessionInitiationRequest.params diff --git a/packages/desktop/views/dashboard/drawers/dapp-config/views/ConnectedDappsDrawer.svelte b/packages/desktop/views/dashboard/drawers/dapp-config/views/ConnectedDappsDrawer.svelte index decf541efb..4aae4c2fb2 100644 --- a/packages/desktop/views/dashboard/drawers/dapp-config/views/ConnectedDappsDrawer.svelte +++ b/packages/desktop/views/dashboard/drawers/dapp-config/views/ConnectedDappsDrawer.svelte @@ -1,10 +1,5 @@