add chains in metadata (#632)

This commit is contained in:
Thibaut Sardan
2021-01-26 15:21:50 +01:00
committed by GitHub
parent aa8c45584a
commit 252244ea27
2 changed files with 20 additions and 4 deletions
@@ -1,8 +1,9 @@
// Copyright 2019-2021 @polkadot/extension-ui authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { useRef } from 'react';
import { useEffect, useMemo, useState } from 'react';
import { getAllMetatdata } from '../messaging';
import chains from '../util/chains';
import useTranslation from './useTranslation';
@@ -13,8 +14,17 @@ interface Option {
export default function (): Option[] {
const { t } = useTranslation();
const [metadataChains, setMetadatachains] = useState<Option[]>([]);
const { current: hashes } = useRef([
useEffect(() => {
getAllMetatdata().then((metadataDefs) => {
const res = metadataDefs.map((metadata) => ({ text: metadata.chain, value: metadata.genesisHash }));
setMetadatachains(res);
}).catch(console.error);
}, []);
const hashes = useMemo(() => [
{
text: t('Allow use on any chain'),
value: ''
@@ -22,8 +32,9 @@ export default function (): Option[] {
...chains.map(({ chain, genesisHash }) => ({
text: chain,
value: genesisHash
}))
]);
})),
...metadataChains.filter(({ value }) => !chains.find(({ genesisHash }) => genesisHash === value))
], [metadataChains, t]);
return hashes;
}
+5
View File
@@ -10,6 +10,7 @@ import type { KeypairType } from '@polkadot/util-crypto/types';
import { PORT_EXTENSION } from '@polkadot/extension-base/defaults';
import { metadataExpand } from '@polkadot/extension-chains';
import chrome from '@polkadot/extension-inject/chrome';
import { MetadataDef } from '@polkadot/extension-inject/types';
import allChains from './util/chains';
import { getSavedMeta, setSavedMeta } from './MetadataCache';
@@ -129,6 +130,10 @@ export async function createSeed (length?: SeedLengths, type?: KeypairType): Pro
return sendMessage('pri(seed.create)', { length, type });
}
export async function getAllMetatdata () : Promise<MetadataDef[]> {
return sendMessage('pri(metadata.list)');
}
export async function getMetadata (genesisHash?: string | null, isPartial = false): Promise<Chain | null> {
if (!genesisHash) {
return null;