Skip to content

Commit

Permalink
Revert "feat: update session on login rather than disconnecting walle…
Browse files Browse the repository at this point in the history
…t connec…" (#2659)

This reverts commit 1b917f3.
  • Loading branch information
MarkNerdi authored Jun 26, 2024
1 parent 1b917f3 commit 8066cee
Show file tree
Hide file tree
Showing 17 changed files with 66 additions and 168 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
export let onClick: (() => unknown) | undefined = undefined
$: networkIds = Object.values(
dapp.session?.namespaces ?? getPersistedDappNamespacesForDapp(dapp.metadata?.url ?? '') ?? {}
dapp.session?.namespaces ?? getPersistedDappNamespacesForDapp(dapp.metadata?.url ?? '')?.supported ?? {}
).flatMap((namespace) => namespace.chains as NetworkId[])
$: verifiedState = $activeProfileId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
selections,
requiredNamespaces,
optionalNamespaces,
persistedDapp?.supported
persistedDapp?.namespaces.supported
)
updateSupportedDappNamespacesForDapp(dappMetadata.url, updatedNamespace)
if ($selectedDapp?.session) {
Expand All @@ -59,7 +59,7 @@
<div class="p-6 flex-grow overflow-hidden">
<div class="h-full flex flex-col gap-8 overflow-scroll">
<slot
persistedSupportedNamespaces={persistedDapp?.supported}
persistedSupportedNamespaces={persistedDapp?.namespaces.supported}
{requiredNamespaces}
{optionalNamespaces}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { DappVerification } from '@auxiliary/wallet-connect/enums'
import {
clearSessionInitiationRequest,
getPersistedDapp,
getPersistedDappNamespacesForDapp,
sessionInitiationRequest,
} from '@auxiliary/wallet-connect/stores'
import { ISupportedNamespace, SupportedNamespaces } from '@auxiliary/wallet-connect/types'
Expand Down Expand Up @@ -63,12 +63,12 @@
return {}
}
const persistedDapp = $sessionInitiationRequest
? getPersistedDapp($sessionInitiationRequest.params.proposer.metadata.url)
const persistedNamespaces = $sessionInitiationRequest
? getPersistedDappNamespacesForDapp($sessionInitiationRequest.params.proposer.metadata.url)
: undefined
if (persistedDapp?.supported) {
return persistedDapp.supported
if (persistedNamespaces) {
return persistedNamespaces.supported
}
const { requiredNamespaces, optionalNamespaces } = $sessionInitiationRequest.params
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<script lang="ts">
import { clearSelectedDapp, connectedDapps, setSelectedDapp } from '@auxiliary/wallet-connect/stores'
import {
clearSelectedDapp,
connectedDapps,
persistedDapps,
setSelectedDapp,
} from '@auxiliary/wallet-connect/stores'
import { Button, IconName, Tabs, Text } from '@bloomwalletio/ui'
import { DappListActionsMenu, DrawerTemplate, EmptyListPlaceholder } from '@components'
import { localize } from '@core/i18n'
Expand All @@ -8,6 +13,7 @@
import { DappConfigRoute } from '../dapp-config-route.enum'
import { IConnectedDapp } from '@auxiliary/wallet-connect/interface'
import { updateDrawerProps } from '@desktop/auxiliary/drawer'
import { activeProfileId } from '@core/profile/stores'
export let drawerRouter: Router<unknown>
Expand All @@ -25,8 +31,9 @@
let selectedTab = tabs[0]
let selectedIndex = 0
$: connectedDappsForProfile = $connectedDapps
$: connectedDappsForProfile = $connectedDapps.filter(
(dapp) => !!$persistedDapps[$activeProfileId as string]?.[dapp.metadata?.url ?? '']
)
$: displayedDapps = connectedDappsForProfile.filter(
(dapp) => (selectedIndex === 0 && !!dapp.session) || (selectedIndex === 1 && !dapp.session)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
const localeKey = 'views.dashboard.drawers.dapps.details'
const dapp = structuredClone($selectedDapp) as IConnectedDapp
const persistedDapp = dapp?.metadata ? getPersistedDapp(dapp?.metadata.url) : undefined
$: persistedDapp = dapp?.metadata ? getPersistedDapp(dapp?.metadata.url) : undefined
onMount(() => {
if (!$selectedDapp) {
Expand All @@ -40,17 +41,15 @@
orientation="vertical"
/>
{/if}
{#if persistedDapp?.supported}
{#if persistedDapp?.namespaces.supported}
<ConnectionSummary
requiredNamespaces={dapp.session?.requiredNamespaces}
editable={!!dapp.session}
supportedNamespaces={persistedDapp?.supported}
supportedNamespaces={persistedDapp?.namespaces.supported}
onEditPermissionsClick={() => drawerRouter.goTo(DappConfigRoute.EditPermissions)}
onEditNetworksClick={() => drawerRouter.goTo(DappConfigRoute.EditNetworks)}
onEditAccountsClick={() => drawerRouter.goTo(DappConfigRoute.EditAccounts)}
/>
{:else}
<Text type="body2" align="center">{localize(`${localeKey}.notConnectedToProfile`)}</Text>
{/if}
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ export async function connectToDapp(
persistDapp(
dappUrl,
verificationState.isScam ? DappVerification.Scam : (verificationState.validation as DappVerification),
requiredNamespaces,
optionalNamespaces,
supportedNamespaces
{ supported: supportedNamespaces, required: requiredNamespaces, optional: optionalNamespaces }
)
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { connectedDapps, getWalletClient, setConnectedDapps } from '../stores'
import { connectedDapps, getWalletClient, getPersistedDapp, removePersistedDapp } from '../stores'
import { get } from 'svelte/store'
import { clearOldPairings } from './clearOldPairings'

export function removeAllDisconnectedDapps(): void {
const client = getWalletClient()
if (!client) {
return
}

const connectedDappsForProfile = get(connectedDapps).filter((dapp) => !dapp.session)
const connectedDappsForProfile = get(connectedDapps).filter(
(dapp) => !!getPersistedDapp(dapp.metadata?.url ?? '') && !dapp.session
)

for (const dapp of connectedDappsForProfile) {
if (dapp.metadata) {
void clearOldPairings(dapp.metadata.url)
removePersistedDapp(dapp.metadata.url)
}
}
setConnectedDapps()
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import { persistent } from '@core/utils/store'
import { Writable } from 'svelte/store'
import { SupportedNamespaces } from '../types'
import { ProposalTypes } from '@walletconnect/types'
import { IPersistedNamespaces } from '../interface'

interface IPersistedNamespacesStore {
[profileId: string]: {
[dappOriginUrl: string]: {
supported: SupportedNamespaces
required: ProposalTypes.RequiredNamespaces
optional: ProposalTypes.OptionalNamespaces
}
[dappOriginUrl: string]: IPersistedNamespaces
}
}
// Keeping this store for for backwards compatibility for 1.0.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ import { persistent } from '@core/utils/store'
import { Writable, get } from 'svelte/store'
import { SupportedNamespaces } from '../types'
import { getActiveProfileId } from '@core/profile/stores'
import { IPersistedNamespaces } from '../interface'
import { DappVerification } from '../enums'
import { ProposalTypes } from '@walletconnect/types'

interface IPersistedDappStore {
[dappOriginUrl: string]: {
verificationState: DappVerification
required: ProposalTypes.RequiredNamespaces
optional: ProposalTypes.OptionalNamespaces
supported: {
[profileId: string]: SupportedNamespaces
[profileId: string]: {
[dappOriginUrl: string]: {
verificationState: DappVerification
namespaces: IPersistedNamespaces
}
}
}
Expand All @@ -21,47 +19,31 @@ export const persistedDapps: Writable<IPersistedDappStore> = persistent('persist
export function getPersistedDapp(dappOriginUrl: string):
| {
verificationState: DappVerification
required: ProposalTypes.RequiredNamespaces
optional: ProposalTypes.OptionalNamespaces
supported: SupportedNamespaces | undefined
namespaces: IPersistedNamespaces
}
| undefined {
const profileId = getActiveProfileId()
const persistedDapp = get(persistedDapps)?.[dappOriginUrl]
if (!persistedDapp) {
return undefined
}

return {
verificationState: persistedDapp.verificationState,
required: persistedDapp.required,
optional: persistedDapp.optional,
supported: persistedDapp.supported[profileId],
}
return get(persistedDapps)?.[profileId]?.[dappOriginUrl]
}

export function getPersistedDappNamespacesForDapp(dappOriginUrl: string): SupportedNamespaces | undefined {
return getPersistedDapp(dappOriginUrl)?.supported
export function getPersistedDappNamespacesForDapp(dappOriginUrl: string): IPersistedNamespaces | undefined {
return getPersistedDapp(dappOriginUrl)?.namespaces
}

export function persistDapp(
dappOriginUrl: string,
verificationState: DappVerification,
required: ProposalTypes.RequiredNamespaces,
optional: ProposalTypes.OptionalNamespaces,
supported: SupportedNamespaces
namespaces: IPersistedNamespaces
): void {
const profileId = getActiveProfileId()

return persistedDapps.update((state) => {
state[dappOriginUrl] = {
if (!state[profileId]) {
state[profileId] = {}
}
state[profileId][dappOriginUrl] = {
verificationState,
required,
optional,
supported: {
...(state[dappOriginUrl]?.supported ?? {}),
[profileId]: supported,
},
namespaces,
}

return state
Expand All @@ -72,14 +54,14 @@ export function updateSupportedDappNamespacesForDapp(dappOriginUrl: string, supp
const profileId = getActiveProfileId()

return persistedDapps.update((state) => {
const persistedDapp = state?.[dappOriginUrl]
const persistedDapp = state?.[profileId]?.[dappOriginUrl]
if (!persistedDapp) {
return state
}

const updatedNamespaces = {
...persistedDapp,
supported: { ...persistedDapp.supported, [profileId]: supported },
...persistedDapp.namespaces,
supported: { ...persistedDapp.namespaces.supported, ...supported },
}

state[profileId][dappOriginUrl] = {
Expand All @@ -89,15 +71,16 @@ export function updateSupportedDappNamespacesForDapp(dappOriginUrl: string, supp
return state
})
}

export function updateVerificationStateForDapp(dappOriginUrl: string, verificationState: DappVerification): void {
const profileId = getActiveProfileId()

return persistedDapps.update((state) => {
const persistedDapp = state?.[dappOriginUrl]
const persistedDapp = state?.[profileId]?.[dappOriginUrl]
if (!persistedDapp) {
return state
}

state[dappOriginUrl] = {
state[profileId][dappOriginUrl] = {
...persistedDapp,
verificationState,
}
Expand All @@ -106,8 +89,13 @@ export function updateVerificationStateForDapp(dappOriginUrl: string, verificati
}

export function removePersistedDapp(dappOriginUrl: string): void {
const profileId = getActiveProfileId()

return persistedDapps.update((state) => {
delete state[dappOriginUrl]
if (!state[profileId]) {
return state
}
delete state[profileId][dappOriginUrl]
return state
})
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
export * from './buildCaip10Address'
export * from './buildDefaultNamespaces'
export * from './disconnectAllDapps'
export * from './doesNamespaceSupportEvent'
export * from './getBloomError'
export * from './getPermissionForMethod'
export * from './normalizeSupportedNamespace'
export * from './rejectAndClearSessionInitiationRequest'
export * from './rejectSessionInitiationRequest'
export * from './switchToRequiredAccount'
export * from './updateActiveSessionsToActiveProfile'
export * from './updateSession'
export * from './validateConnectionCodeUri'

This file was deleted.

Loading

0 comments on commit 8066cee

Please sign in to comment.