From 8e7246b65b6a6276042e480de6d02445291494a3 Mon Sep 17 00:00:00 2001 From: Thibaut Sardan Date: Thu, 20 Feb 2025 14:53:56 +0000 Subject: [PATCH] fix optional and account filtering --- packages/ui/src/constants.ts | 16 ++++------------ packages/ui/src/contexts/AccountsContext.tsx | 17 +++++++++++++---- packages/ui/src/walletConfigs.ts | 2 +- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/packages/ui/src/constants.ts b/packages/ui/src/constants.ts index 61afde801..5d9e90b44 100644 --- a/packages/ui/src/constants.ts +++ b/packages/ui/src/constants.ts @@ -179,9 +179,7 @@ export const networkList: Record = { networkLogo: nodesCoretimeSVG, descriptor: 'coretimeDot', pplChainDescriptor: 'dotPpl', - // not set bc not supported by Nova - // 0xefb56e30d9b4a24099f88820987d0f45fb645992416535d87650d98e00f46fc4 - genesisHash: undefined + genesisHash: '0xefb56e30d9b4a24099f88820987d0f45fb645992416535d87650d98e00f46fc4' }, // 'coretime-kusama': { // chainId: 'coretime-kusama', @@ -338,9 +336,7 @@ export const networkList: Record = { networkLogo: nodesWestendColourSVG, descriptor: 'westend', pplChainDescriptor: 'wesPpl', - // not set bc not supported by Nova - // '0xe143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e' - genesisHash: undefined + genesisHash: '0xe143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e' }, 'asset-hub-westend': { chainId: 'asset-hub-westend', @@ -357,9 +353,7 @@ export const networkList: Record = { networkLogo: nodesAssetHubSVG, descriptor: 'wesAssetHub', pplChainDescriptor: 'wesPpl', - // not set bc not supported by Nova - // '0x67f9723393ef76214df0118c34bbbd3dbebc8ed46a10973a8c969d48fe7598c9' - genesisHash: undefined + genesisHash: '0x67f9723393ef76214df0118c34bbbd3dbebc8ed46a10973a8c969d48fe7598c9' }, paseo: { chainId: 'paseo', @@ -376,9 +370,7 @@ export const networkList: Record = { networkLogo: paseoSVG, descriptor: 'paseo', pplChainDescriptor: 'pasPpl', - genesisHash: undefined - // not set bc not supported by Nova - //'0x77afd6190f1554ad45fd0d31aee62aacc33c6db0ea801129acb813f913e0764f' + genesisHash: '0x77afd6190f1554ad45fd0d31aee62aacc33c6db0ea801129acb813f913e0764f' }, // amplitude: { // chainId: 'amplitude', diff --git a/packages/ui/src/contexts/AccountsContext.tsx b/packages/ui/src/contexts/AccountsContext.tsx index a4cb82804..5a793dc7d 100644 --- a/packages/ui/src/contexts/AccountsContext.tsx +++ b/packages/ui/src/contexts/AccountsContext.tsx @@ -12,6 +12,7 @@ import { useAccounts as useRedotAccounts } from '@reactive-dot/react' import { useApi } from './ApiContext' import { encodeAccounts } from '../utils/encodeAccounts' import { InjectedPolkadotAccount } from 'polkadot-api/pjs-signer' +import { useGetWalletConnectNamespace } from '../hooks/useWalletConnectNamespace' const LOCALSTORAGE_SELECTED_ACCOUNT_KEY = 'multix.selectedAccount' const LOCALSTORAGE_ALLOWED_CONNECTION_KEY = 'multix.canConnectToExtension' @@ -35,12 +36,20 @@ export interface IAccountContext { const AccountContext = createContext(undefined) const AccountContextProvider = ({ children }: AccountContextProps) => { + const { currentNamespace } = useGetWalletConnectNamespace() const redotAccountList = useRedotAccounts() const { chainInfo } = useApi() - const ownAccountList = useMemo( - () => chainInfo && encodeAccounts(redotAccountList, chainInfo.ss58Format), - [chainInfo, redotAccountList] - ) + const ownAccountList = useMemo(() => { + if (!chainInfo || !redotAccountList) return [] + // redot would share 10 accounts if we connect say Nova with 1 account, and 10 networks + // for this reason, we need to filter out the accounts that are not for the current network + // this only applies to wallet-connect accounts + const filteredAccounts = redotAccountList.filter((account) => { + return account.wallet.id !== 'wallet-connect' || account.genesisHash === currentNamespace + }) + return encodeAccounts(filteredAccounts, chainInfo.ss58Format) + }, [chainInfo, currentNamespace, redotAccountList]) + const [selectedAccount, setSelected] = useState( ownAccountList?.[0] ) diff --git a/packages/ui/src/walletConfigs.ts b/packages/ui/src/walletConfigs.ts index ac358e9ba..2bf85532e 100644 --- a/packages/ui/src/walletConfigs.ts +++ b/packages/ui/src/walletConfigs.ts @@ -19,7 +19,7 @@ export const config = defineConfig({ icons: ['https://multix.chainsafe.io/android-chrome-192x192.png?raw=true'] } }, - chainIds: getAllNetworkWalletConnectIds() + optionalChainIds: getAllNetworkWalletConnectIds() }) ] })