parent
84769dc81d
commit
a2c0c8a433
@ -7,9 +7,9 @@
|
||||
"packages/*"
|
||||
],
|
||||
"resolutions": {
|
||||
"@polkadot/api": "^1.9.0-beta.1",
|
||||
"@polkadot/api": "^1.9.0-beta.7",
|
||||
"@polkadot/keyring": "^2.7.0-beta.8",
|
||||
"@polkadot/types": "^1.9.0-beta.1",
|
||||
"@polkadot/types": "^1.9.0-beta.7",
|
||||
"@polkadot/util": "^2.7.0-beta.8",
|
||||
"@polkadot/util-crypto": "^2.7.0-beta.8",
|
||||
"babel-core": "^7.0.0-bridge.0",
|
||||
@ -30,7 +30,7 @@
|
||||
"@babel/core": "^7.9.0",
|
||||
"@polkadot/dev": "^0.51.8",
|
||||
"@polkadot/ts": "^0.3.14",
|
||||
"@polkadot/typegen": "^1.9.0-beta.1",
|
||||
"@polkadot/typegen": "^1.9.0-beta.7",
|
||||
"@types/jest": "^25.1.4",
|
||||
"copy-webpack-plugin": "^5.1.1",
|
||||
"sinon-chrome": "^3.0.1"
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
"license": "Apache-2",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.9.2",
|
||||
"@polkadot/api": "^1.9.0-beta.1",
|
||||
"@polkadot/api": "^1.9.0-beta.7",
|
||||
"@polkadot/keyring": "^2.7.0-beta.8",
|
||||
"@polkadot/ui-keyring": "^0.52.0-beta.19",
|
||||
"extensionizer": "^1.0.1"
|
||||
|
||||
@ -16,29 +16,29 @@ const chains: Map<string, Chain> = new Map(
|
||||
[edgeware, kusama].map((def) => defToChain(def))
|
||||
);
|
||||
|
||||
const UNKNOWN_CHAIN: Chain = {
|
||||
hasMetadata: false,
|
||||
icon: 'polkadot',
|
||||
isUnknown: true,
|
||||
name: 'Unknown chain',
|
||||
registry: new TypeRegistry(),
|
||||
specVersion: 0,
|
||||
ss58Format: 42,
|
||||
tokenDecimals: 0,
|
||||
tokenSymbol: 'UNIT'
|
||||
};
|
||||
|
||||
function defToChain ({ chain, genesisHash, icon, metaCalls, specVersion, ss58Format, tokenDecimals, tokenSymbol, types }: ChainDef): [string, Chain] {
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
registry.register(types as any);
|
||||
|
||||
const metadata = new Metadata(registry, Buffer.from(metaCalls, 'base64'));
|
||||
const isUnknown = genesisHash === '0x';
|
||||
const metadata = metaCalls
|
||||
? new Metadata(registry, Buffer.from(metaCalls, 'base64'))
|
||||
: null;
|
||||
|
||||
registry.setChainProperties(registry.createType('ChainProperties', {
|
||||
ss58Format,
|
||||
tokenDecimals,
|
||||
tokenSymbol
|
||||
}));
|
||||
|
||||
return [genesisHash, {
|
||||
genesisHash,
|
||||
genesisHash: isUnknown
|
||||
? undefined
|
||||
: genesisHash,
|
||||
hasMetadata: !!metadata,
|
||||
isUnknown,
|
||||
icon: icon || 'substrate',
|
||||
name: chain,
|
||||
registry,
|
||||
@ -49,6 +49,17 @@ function defToChain ({ chain, genesisHash, icon, metaCalls, specVersion, ss58For
|
||||
}];
|
||||
}
|
||||
|
||||
const [, UNKNOWN_CHAIN] = defToChain({
|
||||
chain: 'Unknown chain',
|
||||
genesisHash: '0x',
|
||||
icon: 'polkadot',
|
||||
specVersion: 0,
|
||||
ss58Format: 42,
|
||||
tokenDecimals: 0,
|
||||
tokenSymbol: 'Unit',
|
||||
types: {}
|
||||
});
|
||||
|
||||
export function addChainDef (def: ChainDef): void {
|
||||
const [genesisHash, chain] = defToChain(def);
|
||||
|
||||
|
||||
@ -26,5 +26,5 @@ export interface ChainDef {
|
||||
tokenDecimals: number;
|
||||
tokenSymbol: string;
|
||||
types: Record<string, object | string>;
|
||||
metaCalls: string;
|
||||
metaCalls?: string;
|
||||
}
|
||||
|
||||
@ -3,23 +3,18 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Chain } from '@polkadot/extension-chains/types';
|
||||
import { ExtrinsicEra, ExtrinsicPayload } from '@polkadot/types/interfaces';
|
||||
import { SignerPayloadJSON } from '@polkadot/types/types';
|
||||
import { Call, ExtrinsicEra, ExtrinsicPayload } from '@polkadot/types/interfaces';
|
||||
import { AnyJson, SignerPayloadJSON } from '@polkadot/types/types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import React, { useEffect, useRef, useState } from 'react';
|
||||
import styled from 'styled-components';
|
||||
import findChain from '@polkadot/extension-chains';
|
||||
import { GenericCall } from '@polkadot/types';
|
||||
import { formatNumber, bnToBn } from '@polkadot/util';
|
||||
|
||||
interface Decoded {
|
||||
json: MethodJson | null;
|
||||
method: GenericCall | null;
|
||||
}
|
||||
|
||||
interface MethodJson {
|
||||
args: Record<string, string>;
|
||||
args: AnyJson | null;
|
||||
method: Call | null;
|
||||
}
|
||||
|
||||
interface Props {
|
||||
@ -31,24 +26,25 @@ interface Props {
|
||||
}
|
||||
|
||||
function decodeMethod (data: string, isDecoded: boolean, chain: Chain, specVersion: BN): Decoded {
|
||||
let json: MethodJson | null = null;
|
||||
let method: GenericCall | null = null;
|
||||
let args: AnyJson | null = null;
|
||||
let method: Call | null = null;
|
||||
|
||||
try {
|
||||
if (isDecoded && chain.hasMetadata && specVersion.eqn(chain.specVersion)) {
|
||||
method = new GenericCall(chain.registry, data);
|
||||
json = method.toJSON() as unknown as MethodJson;
|
||||
method = chain.registry.createType('Call', data);
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
args = (method.toHuman() as any).args;
|
||||
}
|
||||
} catch (error) {
|
||||
json = null;
|
||||
args = null;
|
||||
method = null;
|
||||
}
|
||||
|
||||
return { json, method };
|
||||
return { args, method };
|
||||
}
|
||||
|
||||
function renderMethod (data: string, { json, method }: Decoded): React.ReactNode {
|
||||
if (!json || !method) {
|
||||
function renderMethod (data: string, { args, method }: Decoded): React.ReactNode {
|
||||
if (!args || !method) {
|
||||
return (
|
||||
<tr>
|
||||
<td className='label'>method data</td>
|
||||
@ -61,18 +57,23 @@ function renderMethod (data: string, { json, method }: Decoded): React.ReactNode
|
||||
<>
|
||||
<tr>
|
||||
<td className='label'>method</td>
|
||||
<td className='data'>{method.sectionName}.{method.methodName}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td className='label'> </td>
|
||||
<td className='data'><pre>{JSON.stringify(json.args, null, 2)}</pre></td>
|
||||
<td className='data'>
|
||||
<details>
|
||||
<summary>{method.sectionName}.{method.methodName}{
|
||||
method.meta
|
||||
? `(${method.meta.args.map(({ name }) => name).join(', ')})`
|
||||
: ''
|
||||
}</summary>
|
||||
<pre>{JSON.stringify(args, null, 2)}</pre>
|
||||
</details>
|
||||
</td>
|
||||
</tr>
|
||||
{method.meta && (
|
||||
<tr>
|
||||
<td className='label'>info</td>
|
||||
<td className='data'>
|
||||
<details>
|
||||
<summary>{method.meta.documentation.join(' ')}</summary>
|
||||
<summary>{method.meta.documentation.map((d) => d.toString().trim()).join(' ')}</summary>
|
||||
</details>
|
||||
</td>
|
||||
</tr>
|
||||
@ -95,7 +96,7 @@ function mortalityAsString (era: ExtrinsicEra, hexBlockNumber: string): string {
|
||||
function Extrinsic ({ className, isDecoded, payload: { era, nonce, tip }, request: { blockNumber, genesisHash, method, specVersion: hexSpec }, url }: Props): React.ReactElement<Props> {
|
||||
const chain = useRef(findChain(genesisHash)).current;
|
||||
const specVersion = useRef(bnToBn(hexSpec)).current;
|
||||
const [decoded, setDecoded] = useState<Decoded>({ json: null, method: null });
|
||||
const [decoded, setDecoded] = useState<Decoded>({ args: null, method: null });
|
||||
|
||||
useEffect((): void => {
|
||||
setDecoded(decodeMethod(method, isDecoded, chain, specVersion));
|
||||
@ -163,7 +164,7 @@ export default styled(Extrinsic)`
|
||||
opacity: 0.5;
|
||||
padding: 0 0.5rem;
|
||||
text-align: right;
|
||||
vertical-align: middle;
|
||||
vertical-align: top;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
|
||||
100
yarn.lock
100
yarn.lock
@ -2747,41 +2747,41 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@polkadot/api-derive@npm:1.9.0-beta.1":
|
||||
version: 1.9.0-beta.1
|
||||
resolution: "@polkadot/api-derive@npm:1.9.0-beta.1"
|
||||
"@polkadot/api-derive@npm:1.9.0-beta.7":
|
||||
version: 1.9.0-beta.7
|
||||
resolution: "@polkadot/api-derive@npm:1.9.0-beta.7"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.9.2
|
||||
"@polkadot/api": 1.9.0-beta.1
|
||||
"@polkadot/rpc-core": 1.9.0-beta.1
|
||||
"@polkadot/rpc-provider": 1.9.0-beta.1
|
||||
"@polkadot/types": 1.9.0-beta.1
|
||||
"@polkadot/api": 1.9.0-beta.7
|
||||
"@polkadot/rpc-core": 1.9.0-beta.7
|
||||
"@polkadot/rpc-provider": 1.9.0-beta.7
|
||||
"@polkadot/types": 1.9.0-beta.7
|
||||
"@polkadot/util": ^2.7.0-beta.8
|
||||
"@polkadot/util-crypto": ^2.7.0-beta.8
|
||||
bn.js: ^5.1.1
|
||||
memoizee: ^0.4.14
|
||||
rxjs: ^6.5.4
|
||||
checksum: 2/842be7c2726bf62d96c951ab3bba291b789ca14505fb95a759d27ebed5ebc7d58a6fc922a3be4f91c576bc98249d21cc0c69d6fb5b0cb3e27db200afeecbba06
|
||||
checksum: 2/5c037e31e9db475e7469b55de9d440b5e103ee9cfb4984d65bcb6c23ad4a6bf53e564eaeaca69662648680c0cac1beb0bd789a2b0db40765cf0fc79a174e6605
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@polkadot/api@npm:^1.9.0-beta.1":
|
||||
version: 1.9.0-beta.1
|
||||
resolution: "@polkadot/api@npm:1.9.0-beta.1"
|
||||
"@polkadot/api@npm:^1.9.0-beta.7":
|
||||
version: 1.9.0-beta.7
|
||||
resolution: "@polkadot/api@npm:1.9.0-beta.7"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.9.2
|
||||
"@polkadot/api-derive": 1.9.0-beta.1
|
||||
"@polkadot/api-derive": 1.9.0-beta.7
|
||||
"@polkadot/keyring": ^2.7.0-beta.8
|
||||
"@polkadot/metadata": 1.9.0-beta.1
|
||||
"@polkadot/rpc-core": 1.9.0-beta.1
|
||||
"@polkadot/rpc-provider": 1.9.0-beta.1
|
||||
"@polkadot/types": 1.9.0-beta.1
|
||||
"@polkadot/metadata": 1.9.0-beta.7
|
||||
"@polkadot/rpc-core": 1.9.0-beta.7
|
||||
"@polkadot/rpc-provider": 1.9.0-beta.7
|
||||
"@polkadot/types": 1.9.0-beta.7
|
||||
"@polkadot/util": ^2.7.0-beta.8
|
||||
"@polkadot/util-crypto": ^2.7.0-beta.8
|
||||
bn.js: ^5.1.1
|
||||
eventemitter3: ^4.0.0
|
||||
rxjs: ^6.5.4
|
||||
checksum: 2/35c7869ec522c69a48d25de6485113a44d0f62390a3ddc01f1acf0b0e8fe187e530e8f57c52ab6f13264c88871d9f36059b2930d04b71dbd4e8762ba3343be83
|
||||
checksum: 2/1f3edd06b9e4002fb6ff7f8c3c65b38eb44f90af2bf1ea7a14ae43b6886df9fec80fc0af9a853398fc689f5daf3cb080f44650e6b8a5a3e869f173ce3c00975c
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@ -2876,7 +2876,7 @@ __metadata:
|
||||
resolution: "@polkadot/extension-base@workspace:packages/extension-base"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.9.2
|
||||
"@polkadot/api": ^1.9.0-beta.1
|
||||
"@polkadot/api": ^1.9.0-beta.7
|
||||
"@polkadot/keyring": ^2.7.0-beta.8
|
||||
"@polkadot/ui-keyring": ^0.52.0-beta.19
|
||||
extensionizer: ^1.0.1
|
||||
@ -2978,16 +2978,16 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@polkadot/metadata@npm:1.9.0-beta.1":
|
||||
version: 1.9.0-beta.1
|
||||
resolution: "@polkadot/metadata@npm:1.9.0-beta.1"
|
||||
"@polkadot/metadata@npm:1.9.0-beta.7":
|
||||
version: 1.9.0-beta.7
|
||||
resolution: "@polkadot/metadata@npm:1.9.0-beta.7"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.9.2
|
||||
"@polkadot/types": 1.9.0-beta.1
|
||||
"@polkadot/types": 1.9.0-beta.7
|
||||
"@polkadot/util": ^2.7.0-beta.8
|
||||
"@polkadot/util-crypto": ^2.7.0-beta.8
|
||||
bn.js: ^5.1.1
|
||||
checksum: 2/db3cbab0973217b47f8e49d102a86d4ed33ffb69bc6059b2ef41350a29bc8617180d15cc508bc865628872b89cb7a13565ffc2715f0489b92be5bd3b3707afaa
|
||||
checksum: 2/5bfb07ab94ef44065431e4c5a8b36126767e56921d798d4a3d6155dfa73eb3caf902032adcd968607ca838ab53a4360877fe0545b0e147c0f21a943f7c9f84a3
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@ -3030,35 +3030,35 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@polkadot/rpc-core@npm:1.9.0-beta.1":
|
||||
version: 1.9.0-beta.1
|
||||
resolution: "@polkadot/rpc-core@npm:1.9.0-beta.1"
|
||||
"@polkadot/rpc-core@npm:1.9.0-beta.7":
|
||||
version: 1.9.0-beta.7
|
||||
resolution: "@polkadot/rpc-core@npm:1.9.0-beta.7"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.9.2
|
||||
"@polkadot/metadata": 1.9.0-beta.1
|
||||
"@polkadot/rpc-provider": 1.9.0-beta.1
|
||||
"@polkadot/types": 1.9.0-beta.1
|
||||
"@polkadot/metadata": 1.9.0-beta.7
|
||||
"@polkadot/rpc-provider": 1.9.0-beta.7
|
||||
"@polkadot/types": 1.9.0-beta.7
|
||||
"@polkadot/util": ^2.7.0-beta.8
|
||||
memoizee: ^0.4.14
|
||||
rxjs: ^6.5.4
|
||||
checksum: 2/9f2b653dec3a645c9e87284766ca331226429a6c2924636ec928fd55214bc9f2918edc113e9090d23963fe556437a78a02f673bc306f1395a800656d4ee69adc
|
||||
checksum: 2/54314fd49fc77ff9975380cba05f486c157e5ea4e8d04649644fd442f6f4f295ce13880cc1c3dccc5539a2bda56669d13dda707583b0ee53fe27bb85cb766492
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@polkadot/rpc-provider@npm:1.9.0-beta.1":
|
||||
version: 1.9.0-beta.1
|
||||
resolution: "@polkadot/rpc-provider@npm:1.9.0-beta.1"
|
||||
"@polkadot/rpc-provider@npm:1.9.0-beta.7":
|
||||
version: 1.9.0-beta.7
|
||||
resolution: "@polkadot/rpc-provider@npm:1.9.0-beta.7"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.9.2
|
||||
"@polkadot/metadata": 1.9.0-beta.1
|
||||
"@polkadot/types": 1.9.0-beta.1
|
||||
"@polkadot/metadata": 1.9.0-beta.7
|
||||
"@polkadot/types": 1.9.0-beta.7
|
||||
"@polkadot/util": ^2.7.0-beta.8
|
||||
"@polkadot/util-crypto": ^2.7.0-beta.8
|
||||
bn.js: ^5.1.1
|
||||
eventemitter3: ^4.0.0
|
||||
isomorphic-fetch: ^2.2.1
|
||||
websocket: ^1.0.31
|
||||
checksum: 2/c7760f893aeb557098bd0854eae8ddb9868289d21cb72c59eca44d38141eee7d8c50e576909e09b7c7fa8a727203c2c385a8b0771a09f12bb1365922d51de667
|
||||
checksum: 2/4430c052775e9a8ec946eb6797a00a2702c67920a4663a6fbc61dc0281ded82249996c72587c35fe02e4c6741a4ac250cec4a437132beed904361bb7c62c1e18
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@ -3071,17 +3071,17 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@polkadot/typegen@npm:^1.9.0-beta.1":
|
||||
version: 1.9.0-beta.1
|
||||
resolution: "@polkadot/typegen@npm:1.9.0-beta.1"
|
||||
"@polkadot/typegen@npm:^1.9.0-beta.7":
|
||||
version: 1.9.0-beta.7
|
||||
resolution: "@polkadot/typegen@npm:1.9.0-beta.7"
|
||||
dependencies:
|
||||
"@babel/core": ^7.9.0
|
||||
"@babel/register": ^7.9.0
|
||||
"@babel/runtime": ^7.9.2
|
||||
"@polkadot/api": 1.9.0-beta.1
|
||||
"@polkadot/metadata": 1.9.0-beta.1
|
||||
"@polkadot/rpc-provider": 1.9.0-beta.1
|
||||
"@polkadot/types": 1.9.0-beta.1
|
||||
"@polkadot/api": 1.9.0-beta.7
|
||||
"@polkadot/metadata": 1.9.0-beta.7
|
||||
"@polkadot/rpc-provider": 1.9.0-beta.7
|
||||
"@polkadot/types": 1.9.0-beta.7
|
||||
"@polkadot/util": ^2.7.0-beta.8
|
||||
websocket: ^1.0.31
|
||||
yargs: ^15.3.1
|
||||
@ -3091,23 +3091,23 @@ __metadata:
|
||||
polkadot-types-from-defs: scripts/polkadot-types-from-defs.js
|
||||
polkadot-types-internal-interfaces: scripts/polkadot-types-internal-interfaces.js
|
||||
polkadot-types-internal-metadata: scripts/polkadot-types-internal-metadata.js
|
||||
checksum: 2/d67586b894a6cc6c734bec6a29eabe4717d3851819afa5451cc1eefe46b0d39e19dbf77eaeefb031b3b406465fe5a7de53956c9311d1a702ed7fe0bbddfa4ee5
|
||||
checksum: 2/1afd06d21811cc6d301d2435d8092de1dd9358f91159ae78d9101b908d42a32b7424caef4365a14acb44fd5423490e8061be507d0e0cedc0d3d7c72f49d63ea1
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@polkadot/types@npm:^1.9.0-beta.1":
|
||||
version: 1.9.0-beta.1
|
||||
resolution: "@polkadot/types@npm:1.9.0-beta.1"
|
||||
"@polkadot/types@npm:^1.9.0-beta.7":
|
||||
version: 1.9.0-beta.7
|
||||
resolution: "@polkadot/types@npm:1.9.0-beta.7"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.9.2
|
||||
"@polkadot/metadata": 1.9.0-beta.1
|
||||
"@polkadot/metadata": 1.9.0-beta.7
|
||||
"@polkadot/util": ^2.7.0-beta.8
|
||||
"@polkadot/util-crypto": ^2.7.0-beta.8
|
||||
"@types/bn.js": ^4.11.6
|
||||
bn.js: ^5.1.1
|
||||
memoizee: ^0.4.14
|
||||
rxjs: ^6.5.4
|
||||
checksum: 2/ed8e3e1b7343b09f56bf64a64b75c9348c41981368866eb5ed542ee12710df4a8410943f2e5994197bc86bacfb776512d4989c58b955972fdb541dea96a9d021
|
||||
checksum: 2/e71320515a9fa3864612f51300dafe7230d8c1be426f125af384c93ea55084e9e3de55dbeab1f85b77d9e00df35c6634e01e219f1e4bce384c17655475adb11b
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@ -17265,7 +17265,7 @@ __metadata:
|
||||
"@babel/core": ^7.9.0
|
||||
"@polkadot/dev": ^0.51.8
|
||||
"@polkadot/ts": ^0.3.14
|
||||
"@polkadot/typegen": ^1.9.0-beta.1
|
||||
"@polkadot/typegen": ^1.9.0-beta.7
|
||||
"@types/jest": ^25.1.4
|
||||
copy-webpack-plugin: ^5.1.1
|
||||
sinon-chrome: ^3.0.1
|
||||
|
||||
Loading…
Reference in New Issue
Block a user