diff --git a/src/renderer/entities/transaction/ui/XcmFee/XcmFee.tsx b/src/renderer/entities/transaction/ui/XcmFee/XcmFee.tsx index c00b6c875..3071f505c 100644 --- a/src/renderer/entities/transaction/ui/XcmFee/XcmFee.tsx +++ b/src/renderer/entities/transaction/ui/XcmFee/XcmFee.tsx @@ -50,13 +50,11 @@ export const XcmFee = memo( return; } - const originChainId = transaction.chainId; - const destinationChainId = transaction.args.destinationChain; - const configChain = config.chains.find((c) => c.chainId === toLocalChainId(originChainId)); + const originChainId = toLocalChainId(transaction.chainId); + const destinationChainId = toLocalChainId(transaction.args.destinationChain); + const configChain = config.chains.find((c) => c.chainId === originChainId); const configAsset = configChain?.assets.find((a) => a.assetId === asset.assetId); - const configXcmTransfer = configAsset?.xcmTransfers.find( - (t) => t.destination.chainId === toLocalChainId(destinationChainId), - ); + const configXcmTransfer = configAsset?.xcmTransfers.find((t) => t.destination.chainId === destinationChainId); if (originChainId && configXcmTransfer && configAsset) { xcmService diff --git a/src/renderer/features/operations/OperationsValidation/lib/transfer-rules.ts b/src/renderer/features/operations/OperationsValidation/lib/transfer-rules.ts index 813b4573d..578918092 100644 --- a/src/renderer/features/operations/OperationsValidation/lib/transfer-rules.ts +++ b/src/renderer/features/operations/OperationsValidation/lib/transfer-rules.ts @@ -59,7 +59,8 @@ export const TransferRules = { incorrectRecipient: { name: 'incorrectRecipient', errorText: 'transfer.incorrectRecipientError', - validator: validateAddress, + // Second argument for validator is form data, but we need chain + validator: (destination: string) => validateAddress(destination), }, }, amount: { diff --git a/src/renderer/pages/Operations/components/ActionSteps/Confirmation.tsx b/src/renderer/pages/Operations/components/ActionSteps/Confirmation.tsx index 114fa7fe0..e6ad9e2ad 100644 --- a/src/renderer/pages/Operations/components/ActionSteps/Confirmation.tsx +++ b/src/renderer/pages/Operations/components/ActionSteps/Confirmation.tsx @@ -69,8 +69,8 @@ export const Confirmation = ({ api, tx, account, chain, signAccount, feeTx, onSi }); useEffect(() => { - xcmTransferModel.events.xcmConfigLoaded(); - }, []); + xcmTransferModel.events.xcmStarted({ chain, asset }); + }, [chain, asset]); return (
diff --git a/src/renderer/pages/Operations/components/Operation.tsx b/src/renderer/pages/Operations/components/Operation.tsx index 518f6860a..181679fed 100644 --- a/src/renderer/pages/Operations/components/Operation.tsx +++ b/src/renderer/pages/Operations/components/Operation.tsx @@ -25,8 +25,8 @@ const Operation = ({ tx, account }: Props) => { const approvals = events?.filter((e) => e.status === 'SIGNED') || []; const initEvent = approvals.find((e) => e.accountId === tx.depositor); const date = new Date(tx.dateCreated || initEvent?.dateCreated || Date.now()); - const asset = - tx.transaction && getAssetById(tx.transaction.args.asset, chainsService.getChainById(tx.chainId)?.assets); + const assetId = tx.transaction && (tx.transaction.args.assetId || tx.transaction.args.asset); + const asset = getAssetById(assetId, chainsService.getChainById(tx.chainId)?.assets); const amount = tx.transaction && getTransactionAmount(tx.transaction); return ( diff --git a/src/renderer/pages/Operations/components/TransactionAmount.tsx b/src/renderer/pages/Operations/components/TransactionAmount.tsx index 38e0397d1..d5a4bd8ec 100644 --- a/src/renderer/pages/Operations/components/TransactionAmount.tsx +++ b/src/renderer/pages/Operations/components/TransactionAmount.tsx @@ -11,7 +11,8 @@ type Props = { }; export const TransactionAmount = ({ tx, className }: Props) => { - const asset = tx && getAssetById(tx.args.asset, chainsService.getChainById(tx.chainId)?.assets); + const assetId = tx?.args.assetId || tx?.args.asset; + const asset = getAssetById(assetId, chainsService.getChainById(tx.chainId)?.assets); const value = getTransactionAmount(tx); if (!asset || !value) { diff --git a/src/renderer/shared/api/xcm/service/xcmService.ts b/src/renderer/shared/api/xcm/service/xcmService.ts index bae174994..adcbea648 100644 --- a/src/renderer/shared/api/xcm/service/xcmService.ts +++ b/src/renderer/shared/api/xcm/service/xcmService.ts @@ -1,4 +1,5 @@ import { type ApiPromise } from '@polkadot/api'; +import { type SubmittableExtrinsic } from '@polkadot/api/types'; import { BN, BN_TEN } from '@polkadot/util'; import { camelCase, get } from 'lodash'; @@ -339,20 +340,19 @@ function getParentChain(chain: Chain, chains: Record) { async function getDeliveryFeeFromConfig({ config, originChain, + destinationChain, originApi, - parentApi, destinationChainId, - txBytesLength, + extrinsic, }: { config: XcmConfig; originChain: string; + destinationChain: Chain; originApi: ApiPromise; - parentApi: ApiPromise; destinationChainId: number; - txBytesLength: number; + extrinsic: SubmittableExtrinsic<'promise'>; }): Promise { - const RELAYCHAINS = [1000, 2000]; - const direction = RELAYCHAINS.includes(destinationChainId) ? 'toParent' : 'toParachain'; + const direction = destinationChain.parentId ? 'toParachain' : 'toParent'; const deliveryFeeConfig = config.networkDeliveryFee[originChain]?.[direction]; @@ -362,7 +362,7 @@ async function getDeliveryFeeFromConfig({ if (direction === 'toParent') { deliveryFactor = ( - await parentApi.query[camelCase(deliveryFeeConfig.factorPallet)].upwardDeliveryFeeFactor() + await originApi.query[camelCase(deliveryFeeConfig.factorPallet)].upwardDeliveryFeeFactor() ).toString(); } else { deliveryFactor = ( @@ -370,9 +370,9 @@ async function getDeliveryFeeFromConfig({ ).toString(); } - const weight = new BN(txBytesLength).add(SET_TOPIC_SIZE); + const weight = new BN(extrinsic.length).add(SET_TOPIC_SIZE); const feeSize = new BN(deliveryFeeConfig.sizeBase).add(weight.mul(new BN(deliveryFeeConfig.sizeFactor))); - const deliveryFee = new BN(deliveryFactor).div(new BN(BN_TEN).pow(FACTOR_MULTIPLIER)).mul(feeSize); + const deliveryFee = feeSize.mul(new BN(deliveryFactor)).div(BN_TEN.pow(FACTOR_MULTIPLIER)); return deliveryFee; } diff --git a/src/renderer/widgets/Transfer/model/form-model.ts b/src/renderer/widgets/Transfer/model/form-model.ts index aea26b9cf..5c9bfa52a 100644 --- a/src/renderer/widgets/Transfer/model/form-model.ts +++ b/src/renderer/widgets/Transfer/model/form-model.ts @@ -432,28 +432,40 @@ const $extrinsic = combine( }, ); +const $xcmChain = combine( + { + chains: networkModel.$chains, + xcmChainId: xcmTransferModel.$xcmChainId, + }, + ({ chains, xcmChainId }) => { + if (!xcmChainId) return null; + + return chains[xcmChainId] ?? null; + }, +); + const getDeliveryFeeFx = createEffect( async ({ config, parachainId, api, - parentApi, extrinsic, + destinationChain, }: { config: XcmConfig | null; parachainId: number | null; api: ApiPromise | null; - parentApi: ApiPromise | null; extrinsic?: SubmittableExtrinsic<'promise'> | null; + destinationChain: Chain | null; }) => { - if (config && api && parentApi && parachainId && extrinsic) { + if (config && api && parachainId && extrinsic && destinationChain) { return xcmService.getDeliveryFeeFromConfig({ config, originChain: toLocalChainId(api.genesisHash.toHex()) || '', originApi: api, - parentApi, destinationChainId: parachainId, - txBytesLength: extrinsic.encodedLength, + extrinsic, + destinationChain, }); } else { return BN_ZERO; @@ -678,10 +690,10 @@ sample({ clock: $extrinsic, source: { api: $api, - parentApi: xcmTransferModel.$parentChainApi, parachainId: xcmTransferModel.$xcmParaId, config: xcmTransferModel.$config, extrinsic: $extrinsic, + destinationChain: $xcmChain, }, target: getDeliveryFeeFx, }); diff --git a/src/renderer/widgets/Transfer/model/xcm-transfer-model.ts b/src/renderer/widgets/Transfer/model/xcm-transfer-model.ts index 8cb05e2ce..b0a62e883 100644 --- a/src/renderer/widgets/Transfer/model/xcm-transfer-model.ts +++ b/src/renderer/widgets/Transfer/model/xcm-transfer-model.ts @@ -19,7 +19,7 @@ const destinationChanged = createEvent(); const $config = createStore(null); const $networkStore = restore(xcmStarted, null); -const $xcmChain = restore(xcmChainSelected, null); +const $xcmChainId = restore(xcmChainSelected, null); const $xcmFee = restore(xcmFeeChanged, '0'); const $isXcmFeeLoading = restore(isXcmFeeLoadingChanged, true); const $xcmParaId = createStore(null); @@ -70,15 +70,13 @@ const $transferDirections = combine( const $transferDirection = combine( { - xcmChain: $xcmChain, + xcmChainId: $xcmChainId, xcmAsset: $xcmAsset, }, - ({ xcmChain, xcmAsset }) => { - if (!xcmChain || !xcmAsset) return undefined; + ({ xcmChainId, xcmAsset }) => { + if (!xcmChainId || !xcmAsset) return undefined; - const xcmChainId = toLocalChainId(xcmChain); - - return xcmAsset?.xcmTransfers.find((t) => t.destination.chainId === xcmChainId); + return xcmAsset?.xcmTransfers.find((t) => t.destination.chainId === toLocalChainId(xcmChainId)); }, { skipVoid: false }, ); @@ -209,40 +207,25 @@ const $xcmData = combine( api: $api, xcmFee: $xcmFee, xcmAsset: $txAsset, - xcmChain: $xcmChain, + xcmChainId: $xcmChainId, xcmWeight: $xcmWeight, xcmDest: $txDestination, xcmBeneficiary: $txBeneficiary, transferDirection: $transferDirection, }, - ({ api, xcmChain, transferDirection, ...rest }) => { - if (!api || !transferDirection || !xcmChain) return undefined; + ({ api, xcmChainId, transferDirection, ...rest }) => { + if (!api || !transferDirection || !xcmChainId) return undefined; const transactionType = xcmTransferUtils.getXcmTransferType(api, transferDirection.type); return { transactionType, - args: { destinationChain: xcmChain, ...rest }, + args: { destinationChain: xcmChainId, ...rest }, }; }, { skipVoid: false }, ); -const $parentChainApi = combine( - { - network: $networkStore, - chains: networkModel.$chains, - apis: networkModel.$apis, - }, - ({ network, chains, apis }) => { - if (!chains || !apis || !network) return null; - - const parentChain = xcmService.getParentChain(network.chain, chains); - - return apis[parentChain.chainId] ?? null; - }, -); - sample({ clock: xcmStarted, target: xcmConfigLoaded, @@ -281,12 +264,12 @@ sample({ export const xcmTransferModel = { $config, $apiDestination, - $parentChainApi, $xcmData, $xcmFee, $isXcmFeeLoading, $transferDirections, $xcmParaId, + $xcmChainId, events: { xcmStarted,