Correct connected node ss58 settings display (#7046)

This commit is contained in:
Jaco 2022-02-25 12:38:31 +01:00 committed by GitHub
parent 292bd8b655
commit cf406781af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 13 deletions

View File

@ -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<Props> {
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<boolean | null>(null);
@ -48,27 +47,21 @@ function General ({ className = '' }: Props): React.ReactElement<Props> {
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(

View File

@ -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,

View File

@ -18,6 +18,7 @@ export interface BareProps {
export interface ApiState {
apiDefaultTx: SubmittableExtrinsicFunction;
apiDefaultTxSudo: SubmittableExtrinsicFunction;
chainSS58: number;
hasInjectedAccounts: boolean;
isApiReady: boolean;
isDevelopment: boolean;