diff --git a/packages/apps-config/src/ui/identityIcons/index.ts b/packages/apps-config/src/ui/identityIcons/index.ts index 6c39dbf7a2..98b446e0da 100644 --- a/packages/apps-config/src/ui/identityIcons/index.ts +++ b/packages/apps-config/src/ui/identityIcons/index.ts @@ -15,6 +15,17 @@ export const identityNodes: Record = [ ['subsocial-node', 'substrate'], ['substrate-node', 'substrate'], ['polymesh-node', 'substrate'] +].reduce((icons, [node, icon]): Record => ({ + ...icons, + [node.toLowerCase().replace(/-/g, ' ')]: icon +}), {}); + +export const identitySpec: Record = [ + ['rococo', 'polkadot'], + ['statemine', 'polkadot'], + ['statemint', 'polkadot'], + ['westend', 'polkadot'], + ['westmint', 'polkadot'] ].reduce((icons, [spec, icon]): Record => ({ ...icons, [spec.toLowerCase().replace(/-/g, ' ')]: icon diff --git a/packages/apps-config/src/ui/index.ts b/packages/apps-config/src/ui/index.ts index 8b0100bfe5..67211c4425 100644 --- a/packages/apps-config/src/ui/index.ts +++ b/packages/apps-config/src/ui/index.ts @@ -2,19 +2,26 @@ // SPDX-License-Identifier: Apache-2.0 import { chainColors, nodeColors, specColors } from './colors'; -import { identityNodes } from './identityIcons'; +import { identityNodes, identitySpec } from './identityIcons'; export * from './logos'; function sanitize (value?: string): string { - return value?.toLowerCase().replace('-', ' ') || ''; + return value?.toLowerCase().replace(/-/g, ' ') || ''; } -export function getSystemIcon (systemName: string): 'beachball' | 'polkadot' | 'substrate' { - return (identityNodes[systemName.toLowerCase().replace(/-/g, ' ')] || 'substrate') as 'substrate'; +export function getSystemIcon (systemName: string, specName: string): 'beachball' | 'polkadot' | 'substrate' { + return ( + identityNodes[sanitize(systemName)] || + identitySpec[sanitize(specName)] || + 'substrate' + ) as 'substrate'; } export function getSystemColor (systemChain: string, systemName: string, specName: string): string | undefined { - // eslint-disable-next-line @typescript-eslint/no-unsafe-return - return chainColors[sanitize(systemChain)] || nodeColors[sanitize(systemName)] || specColors[sanitize(specName)]; + return ( + chainColors[sanitize(systemChain)] || + nodeColors[sanitize(systemName)] || + specColors[sanitize(specName)] + ); } diff --git a/packages/page-democracy/src/util.spec.ts b/packages/page-democracy/src/util.spec.ts index 766a4848b6..83369a0fd8 100644 --- a/packages/page-democracy/src/util.spec.ts +++ b/packages/page-democracy/src/util.spec.ts @@ -17,25 +17,11 @@ const ACTUAL = { const registry = new TypeRegistry(); -function fmtBn (bn: BN): string { - return bn.toString().padStart(20).substr(0, 8); -} - describe('approxChanges', (): void => { it('approximates where the points are', (): void => { const threshold = registry.createType('VoteThreshold', 0); - - console.time('approxChanges'); - const { changeAye, changeNay } = approxChanges(threshold, ACTUAL.sqrtElectorate, ACTUAL); - console.timeEnd('approxChanges'); - - console.error( - '\n', 'changeAye', fmtBn(changeAye), fmtBn(ACTUAL.votedAye.sub(changeAye)), - '\n', 'changeNay', fmtBn(changeNay), fmtBn(ACTUAL.votedNay.add(changeNay)) - ); - expect( calcPassing(threshold, ACTUAL.sqrtElectorate, { ...ACTUAL, votedAye: ACTUAL.votedAye.sub(changeAye) }) ).toBe(false); diff --git a/packages/page-settings/src/useChainInfo.ts b/packages/page-settings/src/useChainInfo.ts index 5a02956cf0..1903b3c0ea 100644 --- a/packages/page-settings/src/useChainInfo.ts +++ b/packages/page-settings/src/useChainInfo.ts @@ -17,7 +17,7 @@ function createInfo (api: ApiPromise, systemChain: string, systemName: string, s chain: systemChain, color: getSystemColor(systemChain, systemName, specName), genesisHash: api.genesisHash.toHex(), - icon: getSystemIcon(systemName), + icon: getSystemIcon(systemName, specName), metaCalls: Buffer.from(api.runtimeMetadata.asCallsOnly.toU8a()).toString('base64'), specVersion: api.runtimeVersion.specVersion.toNumber(), ss58Format: isNumber(api.registry.chainSS58) ? api.registry.chainSS58 : DEFAULT_SS58.toNumber(), diff --git a/packages/react-components/src/IdentityIcon/index.tsx b/packages/react-components/src/IdentityIcon/index.tsx index d57b8715ab..436dfcb9ac 100644 --- a/packages/react-components/src/IdentityIcon/index.tsx +++ b/packages/react-components/src/IdentityIcon/index.tsx @@ -25,8 +25,8 @@ interface Props { value?: AccountId | AccountIndex | Address | string | Uint8Array | null; } -export function getIdentityTheme (systemName: string): 'substrate' { - return ((settings.icon === 'default' && getSystemIcon(systemName)) || settings.icon) as 'substrate'; +export function getIdentityTheme (systemName: string, specName: string): 'substrate' { + return ((settings.icon === 'default' && getSystemIcon(systemName, specName)) || settings.icon) as 'substrate'; } function isCodec (value?: AccountId | AccountIndex | Address | string | Uint8Array | null): value is AccountId | AccountIndex | Address { @@ -34,10 +34,10 @@ function isCodec (value?: AccountId | AccountIndex | Address | string | Uint8Arr } function IdentityIcon ({ className = '', prefix, size = 24, theme, value }: Props): React.ReactElement { - const { isEthereum, systemName } = useApi(); + const { isEthereum, specName, systemName } = useApi(); const { t } = useTranslation(); const { queueAction } = useContext(StatusContext); - const thisTheme = theme || getIdentityTheme(systemName); + const thisTheme = theme || getIdentityTheme(systemName, specName); const Custom = thisTheme === 'robohash' ? RoboHash : undefined;