diff --git a/packages/apps-config/src/api/params/index.ts b/packages/apps-config/src/api/params/index.ts index e53513f7ef..7dfb5a2ba4 100644 --- a/packages/apps-config/src/api/params/index.ts +++ b/packages/apps-config/src/api/params/index.ts @@ -3,3 +3,4 @@ export * from './inflation'; export * from './proposalThresholds'; +export * from './teleport'; diff --git a/packages/apps-config/src/api/params/teleport.ts b/packages/apps-config/src/api/params/teleport.ts new file mode 100644 index 0000000000..355c182e18 --- /dev/null +++ b/packages/apps-config/src/api/params/teleport.ts @@ -0,0 +1,21 @@ +// Copyright 2017-2021 @polkadot/app-config authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import type { ApiPromise } from '@polkadot/api'; + +import { KUSAMA_GENESIS, WESTEND_GENESIS } from '../constants'; + +// 3 * BaseXcmWeight on Kusama +const KUSAMA_WEIGHT = 3 * 1_000_000_000; + +// On Rococo this is lower (3 * 100_000), but non-failing with the higher Kusama weights +const DEFAULT_WEIGHT = KUSAMA_WEIGHT; + +const KNOWN_WEIGHTS: Record = { + [KUSAMA_GENESIS]: KUSAMA_WEIGHT, + [WESTEND_GENESIS]: 3 * 10_000_000 +}; + +export function getTeleportWeight (api: ApiPromise): number { + return KNOWN_WEIGHTS[api.genesisHash.toHex()] || DEFAULT_WEIGHT; +} diff --git a/packages/page-parachains/src/Teleport.tsx b/packages/page-parachains/src/Teleport.tsx index 60a027a75c..f3e751d5db 100644 --- a/packages/page-parachains/src/Teleport.tsx +++ b/packages/page-parachains/src/Teleport.tsx @@ -7,6 +7,7 @@ import type { Option } from '@polkadot/apps-config/settings/types'; import React, { useMemo, useState } from 'react'; +import { getTeleportWeight } from '@polkadot/apps-config'; import { ChainImg, Dropdown, InputAddress, InputBalance, MarkWarning, Modal, Spinner, TxButton } from '@polkadot/react-components'; import { useApi, useApiUrl, useTeleport, useWeightFee } from '@polkadot/react-hooks'; import { Available } from '@polkadot/react-query'; @@ -18,7 +19,6 @@ interface Props { onClose: () => void; } -const DEST_WEIGHT = 3 * 1_000_000_000; // 3 * BaseXcmWeight on Kusama (on Rococo and Westend this is different) const INVALID_PARAID = Number.MAX_SAFE_INTEGER; function createOption ({ info, paraId, text }: LinkOption): Option { @@ -47,6 +47,10 @@ 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), + [api] + ); const chainOpts = useMemo( () => destinations.map(createOption), @@ -62,8 +66,8 @@ function Teleport ({ onClose }: Props): React.ReactElement | null { [destinations, recipientParaId] ); - const destinationApi = useApiUrl(url); - const weightFee = useWeightFee(DEST_WEIGHT, destinationApi); + const destApi = useApiUrl(url); + const weightFee = useWeightFee(destWeight, destApi); const params = useMemo( () => isParaTeleport @@ -71,15 +75,15 @@ function Teleport ({ onClose }: Props): React.ReactElement | null { { X1: 'Parent' }, { X1: { AccountId32: { id: recipientId, network: 'Any' } } }, [{ ConcreteFungible: { amount, id: { X1: 'Parent' } } }], - DEST_WEIGHT + destWeight ] : [ { X1: { ParaChain: recipientParaId } }, { X1: { AccountId32: { id: recipientId, network: 'Any' } } }, [{ ConcreteFungible: { amount, id: 'Here' } }], - DEST_WEIGHT + destWeight ], - [amount, isParaTeleport, recipientId, recipientParaId] + [amount, destWeight, isParaTeleport, recipientId, recipientParaId] ); const hasAvailable = !!amount && amount.gte(weightFee); @@ -139,7 +143,7 @@ function Teleport ({ onClose }: Props): React.ReactElement | null { label={t('amount')} onChange={setAmount} /> - {destinationApi + {destApi ? ( <> | null { label={t('destination transfer fee')} /> ('destination existential deposit')} /> @@ -167,7 +171,7 @@ function Teleport ({ onClose }: Props): React.ReactElement | null { ('Teleport')} onStart={onClose} params={params}