Add chain type overrides (#150)
This commit is contained in:
parent
9825f298e0
commit
8aba99fc9c
File diff suppressed because one or more lines are too long
@ -8,11 +8,11 @@ import { Chain } from './types';
|
|||||||
// imports chain details, generally metadata. For the generation of these,
|
// imports chain details, generally metadata. For the generation of these,
|
||||||
// inside the api, run `yarn chain:info [--ws <url>]`
|
// inside the api, run `yarn chain:info [--ws <url>]`
|
||||||
import alexander from './alexander';
|
import alexander from './alexander';
|
||||||
import kusama from './kusama';
|
import kusamaCC1 from './kusama-cc1';
|
||||||
|
|
||||||
const chains: Map<string, Chain> = new Map(
|
const chains: Map<string, Chain> = new Map(
|
||||||
[alexander, kusama].map(
|
[alexander, kusamaCC1].map(
|
||||||
({ chain, genesisHash, metaCalls, ss58Format, tokenDecimals, tokenSymbol }): [string, Chain] => [
|
({ chain, genesisHash, metaCalls, specVersion, ss58Format, tokenDecimals, tokenSymbol, types }): [string, Chain] => [
|
||||||
genesisHash,
|
genesisHash,
|
||||||
{
|
{
|
||||||
genesisHash,
|
genesisHash,
|
||||||
@ -20,9 +20,11 @@ const chains: Map<string, Chain> = new Map(
|
|||||||
? new Metadata(Buffer.from(metaCalls, 'base64'))
|
? new Metadata(Buffer.from(metaCalls, 'base64'))
|
||||||
: undefined,
|
: undefined,
|
||||||
name: chain,
|
name: chain,
|
||||||
|
specVersion,
|
||||||
ss58Format,
|
ss58Format,
|
||||||
tokenDecimals,
|
tokenDecimals,
|
||||||
tokenSymbol
|
tokenSymbol,
|
||||||
|
types: types || {}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
@ -30,9 +32,11 @@ const chains: Map<string, Chain> = new Map(
|
|||||||
|
|
||||||
const UNKNOWN_CHAIN: Chain = {
|
const UNKNOWN_CHAIN: Chain = {
|
||||||
name: 'Any',
|
name: 'Any',
|
||||||
|
specVersion: 0,
|
||||||
ss58Format: 42,
|
ss58Format: 42,
|
||||||
tokenDecimals: 0,
|
tokenDecimals: 0,
|
||||||
tokenSymbol: 'UNIT'
|
tokenSymbol: 'UNIT',
|
||||||
|
types: {}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function findChain (genesisHash?: string | null): Chain {
|
export default function findChain (genesisHash?: string | null): Chain {
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -8,7 +8,10 @@ export interface Chain {
|
|||||||
name: string;
|
name: string;
|
||||||
genesisHash?: string;
|
genesisHash?: string;
|
||||||
meta?: Metadata;
|
meta?: Metadata;
|
||||||
|
specVersion: number;
|
||||||
ss58Format: number;
|
ss58Format: number;
|
||||||
tokenDecimals: number;
|
tokenDecimals: number;
|
||||||
tokenSymbol: string;
|
tokenSymbol: string;
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
types: Record<string, any>;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
import { Chain } from '@polkadot/extension-chains/types';
|
||||||
import { BlockNumber, ExtrinsicEra, ExtrinsicPayload } from '@polkadot/types/interfaces';
|
import { BlockNumber, ExtrinsicEra, ExtrinsicPayload } from '@polkadot/types/interfaces';
|
||||||
import { SignerPayloadJSON } from '@polkadot/types/types';
|
import { SignerPayloadJSON } from '@polkadot/types/types';
|
||||||
|
|
||||||
@ -9,7 +10,7 @@ import React from 'react';
|
|||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import fromMetadata from '@polkadot/api-metadata/extrinsics/fromMetadata';
|
import fromMetadata from '@polkadot/api-metadata/extrinsics/fromMetadata';
|
||||||
import findChain from '@polkadot/extension-chains';
|
import findChain from '@polkadot/extension-chains';
|
||||||
import { createType, GenericCall, Metadata } from '@polkadot/types';
|
import { createType, GenericCall, getTypeRegistry } from '@polkadot/types';
|
||||||
import { formatNumber } from '@polkadot/util';
|
import { formatNumber } from '@polkadot/util';
|
||||||
|
|
||||||
interface MethodJson {
|
interface MethodJson {
|
||||||
@ -25,10 +26,7 @@ interface Props {
|
|||||||
url: string;
|
url: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderMethod (data: string, meta?: Metadata | null): React.ReactNode {
|
function renderMethod (data: string, isDecoded: boolean, chain?: Chain): React.ReactNode {
|
||||||
let json: MethodJson;
|
|
||||||
let method: GenericCall;
|
|
||||||
|
|
||||||
const base = (
|
const base = (
|
||||||
<tr>
|
<tr>
|
||||||
<td className='label'>method data</td>
|
<td className='label'>method data</td>
|
||||||
@ -36,12 +34,16 @@ function renderMethod (data: string, meta?: Metadata | null): React.ReactNode {
|
|||||||
</tr>
|
</tr>
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!meta) {
|
if (!isDecoded || !chain || !chain.meta) {
|
||||||
return base;
|
return base;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let json: MethodJson;
|
||||||
|
let method: GenericCall;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
GenericCall.injectMethods(fromMetadata(meta));
|
getTypeRegistry().register(chain.types);
|
||||||
|
GenericCall.injectMethods(fromMetadata(chain.meta));
|
||||||
|
|
||||||
method = new GenericCall(data);
|
method = new GenericCall(data);
|
||||||
json = method.toJSON() as unknown as MethodJson;
|
json = method.toJSON() as unknown as MethodJson;
|
||||||
@ -110,7 +112,7 @@ function Details ({ className, isDecoded, payload, request, url }: Props): React
|
|||||||
<td className='data'>{formatNumber(tip)}</td>
|
<td className='data'>{formatNumber(tip)}</td>
|
||||||
</tr>
|
</tr>
|
||||||
)}
|
)}
|
||||||
{renderMethod(method, isDecoded ? chain.meta : null)}
|
{renderMethod(method, isDecoded, chain)}
|
||||||
<tr>
|
<tr>
|
||||||
<td className='label'>lifetime</td>
|
<td className='label'>lifetime</td>
|
||||||
<td className='data'>{renderMortality(era, blockNumber)}</td>
|
<td className='data'>{renderMortality(era, blockNumber)}</td>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user