Skip to content

Commit

Permalink
fix optional and account filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbaut committed Feb 20, 2025
1 parent 9fd785e commit 8e7246b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
16 changes: 4 additions & 12 deletions packages/ui/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,7 @@ export const networkList: Record<string, NetworkInfo> = {
networkLogo: nodesCoretimeSVG,
descriptor: 'coretimeDot',
pplChainDescriptor: 'dotPpl',
// not set bc not supported by Nova
// 0xefb56e30d9b4a24099f88820987d0f45fb645992416535d87650d98e00f46fc4
genesisHash: undefined
genesisHash: '0xefb56e30d9b4a24099f88820987d0f45fb645992416535d87650d98e00f46fc4'
},
// 'coretime-kusama': {
// chainId: 'coretime-kusama',
Expand Down Expand Up @@ -338,9 +336,7 @@ export const networkList: Record<string, NetworkInfo> = {
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',
Expand All @@ -357,9 +353,7 @@ export const networkList: Record<string, NetworkInfo> = {
networkLogo: nodesAssetHubSVG,
descriptor: 'wesAssetHub',
pplChainDescriptor: 'wesPpl',
// not set bc not supported by Nova
// '0x67f9723393ef76214df0118c34bbbd3dbebc8ed46a10973a8c969d48fe7598c9'
genesisHash: undefined
genesisHash: '0x67f9723393ef76214df0118c34bbbd3dbebc8ed46a10973a8c969d48fe7598c9'
},
paseo: {
chainId: 'paseo',
Expand All @@ -376,9 +370,7 @@ export const networkList: Record<string, NetworkInfo> = {
networkLogo: paseoSVG,
descriptor: 'paseo',
pplChainDescriptor: 'pasPpl',
genesisHash: undefined
// not set bc not supported by Nova
//'0x77afd6190f1554ad45fd0d31aee62aacc33c6db0ea801129acb813f913e0764f'
genesisHash: '0x77afd6190f1554ad45fd0d31aee62aacc33c6db0ea801129acb813f913e0764f'
},
// amplitude: {
// chainId: 'amplitude',
Expand Down
17 changes: 13 additions & 4 deletions packages/ui/src/contexts/AccountsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -35,12 +36,20 @@ export interface IAccountContext {
const AccountContext = createContext<IAccountContext | undefined>(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<InjectedPolkadotAccount | undefined>(
ownAccountList?.[0]
)
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/walletConfigs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const config = defineConfig({
icons: ['https://multix.chainsafe.io/android-chrome-192x192.png?raw=true']
}
},
chainIds: getAllNetworkWalletConnectIds()
optionalChainIds: getAllNetworkWalletConnectIds()
})
]
})
Expand Down

0 comments on commit 8e7246b

Please sign in to comment.