diff --git a/packages/page-settings/src/General.tsx b/packages/page-settings/src/General.tsx index 35e33cf2d3..1c1d582f87 100644 --- a/packages/page-settings/src/General.tsx +++ b/packages/page-settings/src/General.tsx @@ -11,7 +11,6 @@ import { allNetworks } from '@polkadot/networks'; import { Button, Dropdown, MarkWarning } from '@polkadot/react-components'; import { useApi, useLedger } from '@polkadot/react-hooks'; import { settings } from '@polkadot/ui-settings'; -import { isUndefined } from '@polkadot/util'; import { useTranslation } from './translate'; import { createIdenticon, createOption, save, saveAndReload } from './util'; @@ -24,7 +23,7 @@ const _ledgerConnOptions = settings.availableLedgerConn; function General ({ className = '' }: Props): React.ReactElement { const { t } = useTranslation(); - const { api, isApiReady, isElectron } = useApi(); + const { chainSS58, isApiReady, isElectron } = useApi(); const { isLedgerCapable } = useLedger(); // tri-state: null = nothing changed, false = no reload, true = reload required const [changed, setChanged] = useState(null); @@ -48,27 +47,21 @@ function General ({ className = '' }: Props): React.ReactElement { const prefixOptions = useMemo( (): (Option | React.ReactNode)[] => { - let ss58Format = api.registry.chainSS58; - - if (isUndefined(ss58Format)) { - ss58Format = 42; - } - - const network = allNetworks.find(({ prefix }) => prefix === ss58Format); + const network = allNetworks.find(({ prefix }) => prefix === chainSS58); return createSs58(t).map((o) => createOption(o, ['default'], 'empty', ( o.value === -1 ? isApiReady ? network - ? ` (${network.displayName}, ${ss58Format || 0})` - : ` (${ss58Format || 0})` + ? ` (${network.displayName}, ${chainSS58 || 0})` + : ` (${chainSS58 || 0})` : undefined : ` (${o.value})` )) ); }, - [api, isApiReady, t] + [chainSS58, isApiReady, t] ); const themeOptions = useMemo( diff --git a/packages/react-api/src/Api.tsx b/packages/react-api/src/Api.tsx index ead2c3b04a..d858f94e8f 100644 --- a/packages/react-api/src/Api.tsx +++ b/packages/react-api/src/Api.tsx @@ -128,8 +128,9 @@ async function loadOnReady (api: ApiPromise, endpoint: LinkOption | null, inject registry.register(types); const { injectedAccounts, properties, systemChain, systemChainType, systemName, systemVersion } = await retrieve(api, injectedPromise); + const chainSS58 = properties.ss58Format.unwrapOr(DEFAULT_SS58).toNumber(); const ss58Format = settings.prefix === -1 - ? properties.ss58Format.unwrapOr(DEFAULT_SS58).toNumber() + ? chainSS58 : settings.prefix; const tokenSymbol = properties.tokenSymbol.unwrapOr([formatBalance.getDefaults().unit, ...DEFAULT_AUX]); const tokenDecimals = properties.tokenDecimals.unwrapOr([DEFAULT_DECIMALS]); @@ -170,6 +171,7 @@ async function loadOnReady (api: ApiPromise, endpoint: LinkOption | null, inject return { apiDefaultTx, apiDefaultTxSudo, + chainSS58, hasInjectedAccounts: injectedAccounts.length !== 0, isApiReady: true, isDevelopment: isEthereum ? false : isDevelopment, diff --git a/packages/react-api/src/types.ts b/packages/react-api/src/types.ts index 2b200152c3..0cddef6a7a 100644 --- a/packages/react-api/src/types.ts +++ b/packages/react-api/src/types.ts @@ -18,6 +18,7 @@ export interface BareProps { export interface ApiState { apiDefaultTx: SubmittableExtrinsicFunction; apiDefaultTxSudo: SubmittableExtrinsicFunction; + chainSS58: number; hasInjectedAccounts: boolean; isApiReady: boolean; isDevelopment: boolean;