From b6b7c206f3f998700fa42591f7648aecdd107caf Mon Sep 17 00:00:00 2001 From: Jaco Date: Fri, 8 Oct 2021 13:56:58 +0300 Subject: [PATCH] Cater for versioned teleport (#6260) --- packages/page-parachains/src/Teleport.tsx | 46 ++++++++++++----------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/packages/page-parachains/src/Teleport.tsx b/packages/page-parachains/src/Teleport.tsx index f3e751d5db..a765ecbea0 100644 --- a/packages/page-parachains/src/Teleport.tsx +++ b/packages/page-parachains/src/Teleport.tsx @@ -47,8 +47,16 @@ function Teleport ({ onClose }: Props): React.ReactElement | null { const [senderId, setSenderId] = useState(null); const [recipientParaId, setParaId] = useState(INVALID_PARAID); const { allowTeleport, destinations, isParaTeleport, oneWay } = useTeleport(); - const destWeight = useMemo( - () => getTeleportWeight(api), + + const [destWeight, call] = useMemo( + () => [ + getTeleportWeight(api), + ( + (api.tx.xcm && api.tx.xcm.teleportAssets) || + (api.tx.xcmPallet && api.tx.xcmPallet.teleportAssets) || + (api.tx.polkadotXcm && api.tx.polkadotXcm.teleportAssets) + ) + ], [api] ); @@ -70,20 +78,20 @@ function Teleport ({ onClose }: Props): React.ReactElement | null { const weightFee = useWeightFee(destWeight, destApi); const params = useMemo( - () => isParaTeleport - ? [ - { X1: 'Parent' }, - { X1: { AccountId32: { id: recipientId, network: 'Any' } } }, - [{ ConcreteFungible: { amount, id: { X1: 'Parent' } } }], - destWeight - ] - : [ - { X1: { ParaChain: recipientParaId } }, - { X1: { AccountId32: { id: recipientId, network: 'Any' } } }, - [{ ConcreteFungible: { amount, id: 'Here' } }], - destWeight - ], - [amount, destWeight, isParaTeleport, recipientId, recipientParaId] + () => { + const src = isParaTeleport + ? { X1: 'Parent' } + : { X1: { ParaChain: recipientParaId } }; + const dst = { X1: { AccountId32: { id: recipientId, network: 'Any' } } }; + const tkn = isParaTeleport + ? [{ ConcreteFungible: { amount, id: { X1: 'Parent' } } }] + : [{ ConcreteFungible: { amount, id: 'Here' } }]; + + return call.meta.args.length === 5 + ? [{ V0: src }, { V0: dst }, { V0: tkn }, 0, destWeight] + : [src, dst, tkn, destWeight]; + }, + [amount, call, destWeight, isParaTeleport, recipientId, recipientParaId] ); const hasAvailable = !!amount && amount.gte(weightFee); @@ -175,11 +183,7 @@ function Teleport ({ onClose }: Props): React.ReactElement | null { label={t('Teleport')} onStart={onClose} params={params} - tx={ - (api.tx.xcm && api.tx.xcm.teleportAssets) || - (api.tx.xcmPallet && api.tx.xcmPallet.teleportAssets) || - (api.tx.polkadotXcm && api.tx.polkadotXcm.teleportAssets) - } + tx={call} />