Add chainType to chainInfo (#5766)

* add chainType

* Update packages/page-settings/src/types.ts

Co-authored-by: Jaco <jacogr@gmail.com>

Co-authored-by: Jaco <jacogr@gmail.com>
This commit is contained in:
Antoine Estienne 2021-07-05 15:02:48 +02:00 committed by GitHub
parent 3faf445e55
commit e55a18689b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

View File

@ -3,6 +3,9 @@
import type { MetadataDef } from '@polkadot/extension-inject/types';
type ChainType = 'substrate' | 'ethereum';
export interface ChainInfo extends MetadataDef {
color: string | undefined;
chainType: ChainType;
}

View File

@ -12,9 +12,10 @@ import { useApi } from '@polkadot/react-hooks';
import { getSpecTypes } from '@polkadot/types-known';
import { formatBalance, isNumber } from '@polkadot/util';
function createInfo (api: ApiPromise, systemChain: string, systemName: string, specName: string): ChainInfo {
function createInfo (api: ApiPromise, systemChain: string, systemName: string, specName: string, isEthereum: boolean): ChainInfo {
return {
chain: systemChain,
chainType: isEthereum ? 'ethereum' : 'substrate',
color: getSystemColor(systemChain, systemName, specName),
genesisHash: api.genesisHash.toHex(),
icon: getSystemIcon(systemName, specName),
@ -28,12 +29,12 @@ function createInfo (api: ApiPromise, systemChain: string, systemName: string, s
}
export default function useChainInfo (): ChainInfo | null {
const { api, isApiReady, specName, systemChain, systemName } = useApi();
const { api, isApiReady, isEthereum, specName, systemChain, systemName } = useApi();
return useMemo(
() => isApiReady
? createInfo(api, systemChain, systemName, specName)
? createInfo(api, systemChain, systemName, specName, isEthereum)
: null,
[api, isApiReady, specName, systemChain, systemName]
[api, isApiReady, specName, systemChain, systemName, isEthereum]
);
}