-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update session on login rather than disconnecting wallet connec…
…t 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
- Loading branch information
Showing
17 changed files
with
168 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 5 additions & 6 deletions
11
packages/shared/src/lib/auxiliary/wallet-connect/actions/removeAllDisconnectedDapps.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,18 @@ | ||
import { connectedDapps, getWalletClient, getPersistedDapp, removePersistedDapp } from '../stores' | ||
import { connectedDapps, getWalletClient, setConnectedDapps } 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) => !!getPersistedDapp(dapp.metadata?.url ?? '') && !dapp.session | ||
) | ||
|
||
const connectedDappsForProfile = get(connectedDapps).filter((dapp) => !dapp.session) | ||
for (const dapp of connectedDappsForProfile) { | ||
if (dapp.metadata) { | ||
removePersistedDapp(dapp.metadata.url) | ||
void clearOldPairings(dapp.metadata.url) | ||
} | ||
} | ||
setConnectedDapps() | ||
} |
9 changes: 7 additions & 2 deletions
9
packages/shared/src/lib/auxiliary/wallet-connect/stores/persisted-dapp-namespaces.store.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
packages/shared/src/lib/auxiliary/wallet-connect/utils/buildDefaultNamespaces.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { getEvmNetworks } from '@core/network' | ||
import { SupportedNamespaces } from '../types' | ||
import { getCaip10AddressForAccount } from './buildCaip10Address' | ||
import { ALL_SUPPORTED_METHODS, SUPPORTED_EVENTS } from '../constants' | ||
import { get } from 'svelte/store' | ||
import { activeAccounts } from '@core/profile/stores' | ||
import type { ProposalTypes } from '@walletconnect/types' | ||
|
||
export function buildDefaultNamespaces( | ||
requiredNamespaces: ProposalTypes.RequiredNamespaces, | ||
optionalNamespaces: ProposalTypes.OptionalNamespaces | ||
): SupportedNamespaces { | ||
const allChainids = [...Object.values(requiredNamespaces), ...Object.values(optionalNamespaces)] | ||
.flatMap(({ chains }) => chains) | ||
.filter(Boolean) | ||
|
||
const namespace: SupportedNamespaces = {} | ||
for (const network of getEvmNetworks()) { | ||
if (!allChainids.includes(network.id)) { | ||
continue | ||
} | ||
if (!namespace[network.namespace]) { | ||
const accounts = get(activeAccounts) | ||
.map((account) => getCaip10AddressForAccount(account, network.id) as string) | ||
.filter(Boolean) | ||
namespace[network.namespace] = { | ||
chains: [], | ||
methods: ALL_SUPPORTED_METHODS, | ||
events: SUPPORTED_EVENTS, | ||
accounts, | ||
} | ||
} | ||
namespace[network.namespace].chains.push(network.id) | ||
} | ||
return namespace | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/shared/src/lib/auxiliary/wallet-connect/utils/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
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' |
16 changes: 16 additions & 0 deletions
16
packages/shared/src/lib/auxiliary/wallet-connect/utils/normalizeSupportedNamespace.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type { SessionTypes } from '@walletconnect/types' | ||
import type { SupportedNamespaces } from '../types' | ||
|
||
export function normalizeSessionNamespace(sessionNamespace: SessionTypes.Namespaces): SupportedNamespaces { | ||
const normalizedRecord: SupportedNamespaces = {} | ||
|
||
for (const key in sessionNamespace) { | ||
const session = sessionNamespace[key] | ||
normalizedRecord[key] = { | ||
...session, | ||
chains: session.chains || [], | ||
} | ||
} | ||
|
||
return normalizedRecord | ||
} |
Oops, something went wrong.