diff --git a/packages/page-parachains/src/Teleport.tsx b/packages/page-parachains/src/Teleport.tsx index a765ecbea0..f930b300bd 100644 --- a/packages/page-parachains/src/Teleport.tsx +++ b/packages/page-parachains/src/Teleport.tsx @@ -4,6 +4,7 @@ import type BN from 'bn.js'; import type { LinkOption } from '@polkadot/apps-config/endpoints/types'; import type { Option } from '@polkadot/apps-config/settings/types'; +import type { XcmVersionedMultiLocation } from '@polkadot/types/lookup'; import React, { useMemo, useState } from 'react'; @@ -79,19 +80,29 @@ function Teleport ({ onClose }: Props): React.ReactElement | null { const params = useMemo( () => { - const src = isParaTeleport + // From Polkadot runtime 9110 (no destination weight) + // Get first item, it should have V0, V1, ... + const firstType = api.createType(call.meta.args[0].type.toString()); + const isCurrent = firstType.defKeys.includes('V1'); + + const dst = isParaTeleport ? { X1: 'Parent' } : { X1: { ParaChain: recipientParaId } }; - const dst = { X1: { AccountId32: { id: recipientId, network: 'Any' } } }; - const tkn = isParaTeleport + const acc = { X1: { AccountId32: { id: recipientId, network: 'Any' } } }; + const ass = isParaTeleport ? [{ ConcreteFungible: { amount, id: { X1: 'Parent' } } }] - : [{ ConcreteFungible: { amount, id: 'Here' } }]; + // forgo id - 'Here' for 9100, 'Null' for 9110 (both is the default enum value) + : [{ ConcreteFungible: { amount } }]; - return call.meta.args.length === 5 - ? [{ V0: src }, { V0: dst }, { V0: tkn }, 0, destWeight] - : [src, dst, tkn, destWeight]; + return isCurrent + ? call.meta.args.length === 5 + // Polkadot 9100 + ? [{ V0: dst }, { V0: acc }, { V0: ass }, 0, destWeight] + // Polkadot 9110 + : [{ V0: dst }, { V0: acc }, { V0: ass }, 0] + : [dst, acc, ass, destWeight]; }, - [amount, call, destWeight, isParaTeleport, recipientId, recipientParaId] + [api, amount, call, destWeight, isParaTeleport, recipientId, recipientParaId] ); const hasAvailable = !!amount && amount.gte(weightFee); diff --git a/packages/react-params/src/Param/index.tsx b/packages/react-params/src/Param/index.tsx index 63d2820179..4859dfa620 100644 --- a/packages/react-params/src/Param/index.tsx +++ b/packages/react-params/src/Param/index.tsx @@ -11,6 +11,17 @@ import { isUndefined } from '@polkadot/util'; import findComponent from './findComponent'; import Static from './Static'; +function formatJSON (input: string): string { + return input + .replace(/"/g, '') + .replace(/\\/g, '') + .replace(/:Null/g, '') + .replace(/:/g, ': ') + // .replace(/{/g, '{ ') + // .replace(/}/g, ' }') + .replace(/,/g, ', '); +} + function Param ({ className = '', defaultValue, isDisabled, isInOption, isOptional, name, onChange, onEnter, onEscape, overrides, registry, type }: Props): React.ReactElement | null { const Component = useMemo( () => findComponent(registry, type, overrides), @@ -18,9 +29,11 @@ function Param ({ className = '', defaultValue, isDisabled, isInOption, isOption ); const label = useMemo( - () => isUndefined(name) - ? `${isDisabled && isInOption ? 'Option<' : ''}${encodeTypeDef(registry, type)}${isDisabled && isInOption ? '>' : ''}` - : `${name}: ${isDisabled && isInOption ? 'Option<' : ''}${encodeTypeDef(registry, type)}${isDisabled && isInOption ? '>' : ''}`, + () => formatJSON( + isUndefined(name) + ? `${isDisabled && isInOption ? 'Option<' : ''}${encodeTypeDef(registry, type)}${isDisabled && isInOption ? '>' : ''}` + : `${name}: ${isDisabled && isInOption ? 'Option<' : ''}${encodeTypeDef(registry, type)}${isDisabled && isInOption ? '>' : ''}` + ), [isDisabled, isInOption, name, registry, type] );