diff --git a/src/contexts/Account.tsx b/src/contexts/Account.tsx index 7562c469..b621dc5b 100644 --- a/src/contexts/Account.tsx +++ b/src/contexts/Account.tsx @@ -3,6 +3,10 @@ import type { SigningAccount } from '../types'; import React, { useContext, createContext, useState, useEffect } from 'react'; import { extractChainInfo, useAppLifeCycle } from '../lifecycle/index.js'; import { useWallets } from './Wallets.js'; +import { + isSubstrateAccount, + isAccountAllowedOnChain, +} from '../utils/polkadot-api.js'; export interface IAccountContext { connectedAccount: SigningAccount | undefined; @@ -58,9 +62,8 @@ const AccountProvider = ({ children }: { children: React.ReactNode }) => { // filter accounts that match the genesis hash. const accounts = (await wallet.getAccounts()).filter( (account) => - !account.genesisHash || - !genesisHash || - account.genesisHash === genesisHash + isSubstrateAccount(account) && + isAccountAllowedOnChain(account, genesisHash) ); if (accounts.length > 0) { diff --git a/src/utils/polkadot-api.ts b/src/utils/polkadot-api.ts index c022f7f5..f816df76 100644 --- a/src/utils/polkadot-api.ts +++ b/src/utils/polkadot-api.ts @@ -18,6 +18,7 @@ import { addressEq } from '@polkadot/util-crypto'; import BN from 'bn.js'; import { Conviction } from '../types'; import { DispatchError } from '@polkadot/types/interfaces'; +import { Account } from '@polkadot-onboard/core'; const DEFAULT_OPTIONS = { noInitWarn: true, @@ -110,6 +111,21 @@ export function formatConviction(conviction: Conviction): string { } } +export function isSubstrateAccount(account: Account) { + return !!account?.type && ['ed25519', 'sr25519'].includes(account.type); +} + +export function isAccountAllowedOnChain( + account: Account, + chainGenesisHash: string | undefined | null +) { + return ( + !account.genesisHash || + !chainGenesisHash || + account.genesisHash === chainGenesisHash + ); +} + export function isValidAddress(address: string): boolean { try { encodeAddress(isHex(address) ? hexToU8a(address) : decodeAddress(address));