From 95e9c668ea348318cc34241bed82df239c3acf70 Mon Sep 17 00:00:00 2001 From: Antoine Estienne Date: Wed, 28 Jul 2021 20:07:09 +0100 Subject: [PATCH] Add chain type to metadata (#5887) * add chainType to metadata in the qr code * lint --- .../src/Metadata/NetworkSpecs.tsx | 24 ++++++++++++++++--- packages/page-settings/src/types.ts | 2 +- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/packages/page-settings/src/Metadata/NetworkSpecs.tsx b/packages/page-settings/src/Metadata/NetworkSpecs.tsx index 0f0bb665fc..4f80366a9d 100644 --- a/packages/page-settings/src/Metadata/NetworkSpecs.tsx +++ b/packages/page-settings/src/Metadata/NetworkSpecs.tsx @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import type { NetworkSpecsStruct } from '@polkadot/ui-settings/types'; -import type { ChainInfo } from '../types'; +import type { ChainInfo, ChainType } from '../types'; import React, { useCallback, useEffect, useReducer, useRef, useState } from 'react'; import styled from 'styled-components'; @@ -18,6 +18,11 @@ interface Props { className?: string; } +// TODO-MOONBEAM: update NetworkSpecsStruct in @polkadot/ui-settings/types +interface NetworkSpecsStructWithType extends NetworkSpecsStruct{ + chainType: ChainType +} + function getRandomColor (): string { const letters = '0123456789ABCDEF'; let color = '#'; @@ -30,6 +35,7 @@ function getRandomColor (): string { } const initialState = { + chainType: 'substrate' as ChainType, color: '#FFFFFF', decimals: 0, genesisHash: '', @@ -41,10 +47,10 @@ const initialState = { function NetworkSpecs ({ chainInfo, className }: Props): React.ReactElement { const { t } = useTranslation(); const { isApiReady, systemChain } = useApi(); - const [qrData, setQrData] = useState(initialState); + const [qrData, setQrData] = useState(initialState); const debouncedQrData = useDebounce(qrData, 500); - const reducer = (state: NetworkSpecsStruct, delta: Partial): NetworkSpecsStruct => { + const reducer = (state: NetworkSpecsStructWithType, delta: Partial): NetworkSpecsStructWithType => { const newState = { ...state, ...delta @@ -59,6 +65,7 @@ function NetworkSpecs ({ chainInfo, className }: Props): React.ReactElement { chainInfo && setNetworkSpecs({ + chainType: chainInfo.chainType, color: chainInfo.color || getRandomColor(), decimals: chainInfo.tokenDecimals, genesisHash: chainInfo.genesisHash, @@ -191,6 +198,17 @@ function NetworkSpecs ({ chainInfo, className }: Props): React.ReactElement + + + ('Chain type (ethereum compatible or regular substrate)')} + isDisabled + label={t('Chain Type')} + value={networkSpecs.chainType} + /> + + ); } diff --git a/packages/page-settings/src/types.ts b/packages/page-settings/src/types.ts index a11e31ea41..ba072c7725 100644 --- a/packages/page-settings/src/types.ts +++ b/packages/page-settings/src/types.ts @@ -3,7 +3,7 @@ import type { MetadataDef } from '@polkadot/extension-inject/types'; -type ChainType = 'substrate' | 'ethereum'; +export type ChainType = 'substrate' | 'ethereum'; export interface ChainInfo extends MetadataDef { color: string | undefined;