Move ledger config (#4306)

* Move ledger config

* naming
This commit is contained in:
Jaco Greeff 2020-12-31 10:47:32 +01:00 committed by GitHub
parent 2a768eaf77
commit ba46bc5b37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 12 deletions

View File

@ -3,4 +3,4 @@
// The list of Ethereum networks, for these the UI will default to Ethereum-only accounts
export const ethereumNetworks = ['node-moonbeam', 'moonbase-alphanet', 'moonbeam-alphanet', 'moonbeam-standalone'];
export const ethereumChains = ['node-moonbeam', 'moonbase-alphanet', 'moonbeam-alphanet', 'moonbeam-standalone'];

View File

@ -1,6 +1,7 @@
// Copyright 2017-2020 @polkadot/apps-config authors & contributors
// SPDX-License-Identifier: Apache-2.0
export * from './ethereumNetworks';
export * from './ethereumChains';
export * from './languages';
export * from './ledgerChains';
export * from './ss58';

View File

@ -0,0 +1,10 @@
// Copyright 2017-2020 @polkadot/apps-config authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { KUSAMA_GENESIS, POLKADOT_GENESIS } from '../api/constants';
// mapping of the genesisHash with the actual app name for Ledger
export const ledgerChains = [
[KUSAMA_GENESIS, 'kusama'],
[POLKADOT_GENESIS, 'polkadot']
];

View File

@ -11,7 +11,7 @@ import store from 'store';
import { ApiPromise } from '@polkadot/api/promise';
import { deriveMapCache, setDeriveCache } from '@polkadot/api-derive/util';
import { ethereumNetworks, POLKADOT_DENOM_BLOCK, POLKADOT_GENESIS, typesBundle, typesChain, typesSpec } from '@polkadot/apps-config';
import { ethereumChains, POLKADOT_DENOM_BLOCK, POLKADOT_GENESIS, typesBundle, typesChain, typesSpec } from '@polkadot/apps-config';
import { web3Accounts, web3Enable } from '@polkadot/extension-dapp';
import { TokenUnit } from '@polkadot/react-components/InputNumber';
import { StatusContext } from '@polkadot/react-components/Status';
@ -127,7 +127,7 @@ async function loadOnReady (api: ApiPromise, injectedPromise: Promise<InjectedEx
: settings.prefix;
const tokenSymbol = properties.tokenSymbol.unwrapOr(undefined)?.toString();
const tokenDecimals = properties.tokenDecimals.unwrapOr(DEFAULT_DECIMALS).toNumber();
const isEthereum = ethereumNetworks.includes(api.runtimeVersion.specName.toString());
const isEthereum = ethereumChains.includes(api.runtimeVersion.specName.toString());
const isDevelopment = !isEthereum && (systemChainType.isDevelopment || systemChainType.isLocal || isTestChain(systemChain));
console.log(`chain: ${systemChain} (${systemChainType.toString()}), ${JSON.stringify(properties)}`);

View File

@ -1,23 +1,18 @@
// Copyright 2017-2020 @polkadot/react-api authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { KUSAMA_GENESIS, POLKADOT_GENESIS } from '@polkadot/apps-config';
import { ledgerChains } from '@polkadot/apps-config';
import { Ledger } from '@polkadot/ui-keyring';
import uiSettings from '@polkadot/ui-settings';
import { assert } from '@polkadot/util';
import { api } from './Api';
const ALLOWED_CHAINS: [string, 'kusama' | 'polkadot'][] = [
[KUSAMA_GENESIS, 'kusama'],
[POLKADOT_GENESIS, 'polkadot']
];
let ledger: Ledger | null = null;
export function isLedgerCapable (): boolean {
try {
return !!(window as unknown as { USB?: unknown }).USB && !!api && ALLOWED_CHAINS.map(([g]) => g).includes(api.genesisHash.toHex());
return !!(window as unknown as { USB?: unknown }).USB && !!api && ledgerChains.map(([g]) => g).includes(api.genesisHash.toHex());
} catch (error) {
return false;
}
@ -33,7 +28,7 @@ export function clearLedger (): void {
export function getLedger (): Ledger {
if (!ledger) {
const def = api && ALLOWED_CHAINS.find(([g]) => g === api.genesisHash.toHex());
const def = api && ledgerChains.find(([g]) => g === api.genesisHash.toHex());
assert(def, `Unable to find supported chain for ${api.genesisHash.toHex()}`);