Skip to content

Commit

Permalink
refactor: pass chain data to transaction instead of chain id
Browse files Browse the repository at this point in the history
  • Loading branch information
tomjeatt committed Jul 3, 2023
1 parent db24f6a commit 96b0ea3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
useForm
} from '@/lib/form';
import { useSubstrateSecureState } from '@/lib/substrate';
import { Chains } from '@/types/chains';
import { ChainData, Chains } from '@/types/chains';
import { getTokenPrice } from '@/utils/helpers/prices';
import { useGetCurrencies } from '@/utils/hooks/api/use-get-currencies';
import { useGetPrices } from '@/utils/hooks/api/use-get-prices';
Expand Down Expand Up @@ -90,8 +90,12 @@ const CrossChainTransferForm = (): JSX.Element => {
true
);

const fromChain = formData[CROSS_CHAIN_TRANSFER_FROM_FIELD] as ChainName;
const toChain = formData[CROSS_CHAIN_TRANSFER_TO_FIELD] as ChainName;
const fromChain = originatingChains?.find(
(chain) => chain.id === formData[CROSS_CHAIN_TRANSFER_FROM_FIELD]
) as ChainData;
const toChain = destinationChains.find(
(chain) => chain.id === formData[CROSS_CHAIN_TRANSFER_TO_FIELD]
) as ChainData;

transaction.execute(adapter, fromChain, toChain, address, transferAmount);
};
Expand Down
2 changes: 1 addition & 1 deletion src/utils/hooks/transaction/extrinsics/xcm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const getXCMExtrinsic = async (params: XCMActions): Promise<ExtrinsicData> => {
const transferAmountDecimals = transferAmount.currency.decimals;
const tx = adapter.createTx({
amount: FixedPointNumber.fromInner(transferAmountString, transferAmountDecimals),
to: toChain,
to: toChain.id,
token: transferAmount.currency.ticker,
address
} as CrossChainTransferParams);
Expand Down
7 changes: 4 additions & 3 deletions src/utils/hooks/transaction/types/xcm.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { ChainName } from '@interlay/bridge';
import { BaseCrossChainAdapter } from '@interlay/bridge/build/base-chain-adapter';
import { CurrencyExt } from '@interlay/interbtc-api';
import { MonetaryAmount } from '@interlay/monetary-js';

import { ChainData } from '@/types/chains';

import { Transaction, TransactionAction } from '.';

interface XCMTransferAction extends TransactionAction {
type: Transaction.XCM_TRANSFER;
args: [
adapter: BaseCrossChainAdapter,
fromChain: ChainName,
toChain: ChainName,
fromChain: ChainData,
toChain: ChainData,
destinatary: string,
transferAmount: MonetaryAmount<CurrencyExt>
];
Expand Down
4 changes: 2 additions & 2 deletions src/utils/hooks/transaction/utils/description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ const getTranslationArgs = (
args: {
amount: transferAmount.toHuman(),
currency: transferAmount.currency.ticker,
fromChain: fromChain.toUpperCase(),
toChain: toChain.toUpperCase()
fromChain: fromChain.display,
toChain: toChain.display
}
};
}
Expand Down

0 comments on commit 96b0ea3

Please sign in to comment.