Add chain genesis, lookups for toggle (#247)

This commit is contained in:
Jaco Greeff
2019-11-29 10:54:49 +01:00
committed by GitHub
parent afbf853a54
commit b3f255a2b9
2 changed files with 22 additions and 2 deletions
+7 -2
View File
@@ -8,6 +8,7 @@ import { AddressSubject, SingleAddress } from './observable/types';
import { CreateResult, KeyringAddress, KeyringAddressType, KeyringItemType, KeyringJson, KeyringJson$Meta, KeyringOptions, KeyringStruct } from './types';
import createPair from '@polkadot/keyring/pair';
import chains from '@polkadot/ui-settings/defaults/chains';
import { hexToU8a, isHex, isString } from '@polkadot/util';
import env from './observable/development';
@@ -219,10 +220,14 @@ export class Keyring extends Base implements KeyringStruct {
private allowGenesis (json?: KeyringJson | { meta: KeyringJson$Meta } | null): boolean {
if (json && json.meta && this.genesisHash) {
const hashes: (string | null | undefined)[] = Object.values(chains).find((hashes): boolean =>
hashes.includes(this.genesisHash || '')
) || [this.genesisHash];
if (json.meta.genesisHash) {
return this.genesisHash === json.meta.genesisHash;
return hashes.includes(json.meta.genesisHash);
} else if (json.meta.contract) {
return this.genesisHash === json.meta.contract.genesisHash;
return hashes.includes(json.meta.contract.genesisHash);
}
}