// Copyright 2019-2025 @pezkuwi/extension-ui authors & contributors // SPDX-License-Identifier: Apache-2.0 import type { Chain } from '@pezkuwi/extension-chains/types'; import type { Call, ExtrinsicEra, ExtrinsicPayload } from '@pezkuwi/types/interfaces'; import type { AnyJson, SignerPayloadJSON } from '@pezkuwi/types/types'; import type { BN } from '@pezkuwi/util'; import type { TFunction } from '../../hooks/useTranslation.js'; import { convertMultilocationToUrl } from '@paraspell/xcm-analyser'; import React, { useMemo, useRef } from 'react'; import { bnToBn, formatNumber } from '@pezkuwi/util'; import { Table } from '../../components/index.js'; import { useMetadata, useTranslation } from '../../hooks/index.js'; interface Decoded { args: AnyJson | null; method: Call | null; } interface Props { className?: string; payload: ExtrinsicPayload; request: SignerPayloadJSON; url: string; } function displayDecodeVersion (message: string, chain: Chain, specVersion: BN): string { return `${message}: chain=${chain.name}, specVersion=${chain.specVersion.toString()} (request specVersion=${specVersion.toString()})`; } function decodeMethod (data: string, chain: Chain, specVersion: BN): Decoded { let args: AnyJson | null = null; let method: Call | null = null; try { if (specVersion.eqn(chain.specVersion)) { method = chain.registry.createType('Call', data); args = (method.toHuman() as { args: AnyJson }).args; } else { console.log(displayDecodeVersion('Outdated metadata to decode', chain, specVersion)); } } catch (error) { console.error(`${displayDecodeVersion('Error decoding method', chain, specVersion)}:: ${(error as Error).message}`); args = null; method = null; } return { args, method }; } function renderMethod (data: string, { args, method }: Decoded, t: TFunction): React.ReactNode { if (!args || !method) { return (
{JSON.stringify(args, null, 2)}
| {t('from')} | {url} |
| {chain ? t('chain') : t('genesis')} | {chain ? chain.name : genesisHash} |
| {t('version')} | {specVersion.toNumber()} |
| {t('nonce')} | {formatNumber(payload.nonce)} |
| {t('tip')} | {formatNumber(payload.tip)} |
| {t('assetId')} |
{humanReadableAssetId || '{...}'}{JSON.stringify(assetId, null, 2)}
|
| {t('lifetime')} | {mortalityAsString(payload.era, blockNumber, t)} |