Display ss58Format in dropdown (#5263)
This commit is contained in:
parent
47bacb3b24
commit
b43559f09f
@ -7,9 +7,11 @@ import type { SettingsStruct } from '@polkadot/ui-settings/types';
|
||||
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
|
||||
import { createLanguages, createSs58 } from '@polkadot/apps-config';
|
||||
import { all as allNetworks } from '@polkadot/networks';
|
||||
import { Button, Dropdown, MarkWarning } from '@polkadot/react-components';
|
||||
import { useLedger } from '@polkadot/react-hooks';
|
||||
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';
|
||||
@ -22,6 +24,7 @@ const ledgerConnOptions = settings.availableLedgerConn;
|
||||
|
||||
function General ({ className = '' }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
const { api, isApiReady } = useApi();
|
||||
const { isLedgerCapable } = useLedger();
|
||||
// tri-state: null = nothing changed, false = no reload, true = reload required
|
||||
const [changed, setChanged] = useState<boolean | null>(null);
|
||||
@ -39,8 +42,28 @@ function General ({ className = '' }: Props): React.ReactElement<Props> {
|
||||
);
|
||||
|
||||
const prefixOptions = useMemo(
|
||||
() => createSs58(t).map((o): Option | React.ReactNode => createOption(o, ['default'])),
|
||||
[t]
|
||||
(): (Option | React.ReactNode)[] => {
|
||||
let ss58Format = api.registry.chainSS58;
|
||||
|
||||
if (isUndefined(ss58Format)) {
|
||||
ss58Format = 42;
|
||||
}
|
||||
|
||||
const network = allNetworks.find(({ prefix }) => prefix === ss58Format);
|
||||
|
||||
return createSs58(t).map((o) =>
|
||||
createOption(o, ['default'], 'empty', (
|
||||
o.value === -1
|
||||
? isApiReady
|
||||
? network
|
||||
? ` (${network.displayName}, ${ss58Format || 0})`
|
||||
: ` (${ss58Format || 0})`
|
||||
: undefined
|
||||
: ` (${o.value})`
|
||||
))
|
||||
);
|
||||
},
|
||||
[api, isApiReady, t]
|
||||
);
|
||||
|
||||
const themeOptions = useMemo(
|
||||
|
||||
@ -9,7 +9,7 @@ import React from 'react';
|
||||
import { ChainImg, Dropdown, IdentityIcon } from '@polkadot/react-components';
|
||||
import { settings } from '@polkadot/ui-settings';
|
||||
|
||||
export function createOption ({ info, isHeader, text, value }: Option, overrides: string[] = [], override = 'empty'): Option | React.ReactNode {
|
||||
export function createOption ({ info, isHeader, text, value }: Option, overrides: string[] = [], override = 'empty', extra?: string): Option | React.ReactNode {
|
||||
if (isHeader) {
|
||||
return (
|
||||
<Dropdown.Header
|
||||
@ -33,7 +33,7 @@ export function createOption ({ info, isHeader, text, value }: Option, overrides
|
||||
: info
|
||||
}
|
||||
/>
|
||||
<div className='ui--Dropdown-name'>{text}</div>
|
||||
<div className='ui--Dropdown-name'>{text}{extra}</div>
|
||||
</div>
|
||||
),
|
||||
value
|
||||
|
||||
Loading…
Reference in New Issue
Block a user