MCPcopy Create free account
hub / github.com/ICBNetwork/web3-Wallet / decodeSwapsTx

Function decodeSwapsTx

app/components/UI/TransactionElement/utils.js:667–852  ·  view source on GitHub ↗
(args)

Source from the content-addressed store, hash-verified

665}
666
667function decodeSwapsTx(args) {
668 const {
669 swapsTransactions,
670 swapsTokens,
671 conversionRate,
672 currentCurrency,
673 primaryCurrency,
674 tx: {
675 id,
676 txParams,
677 txParams: { gas, from, to },
678 hash,
679 },
680 tx,
681 contractExchangeRates,
682 assetSymbol,
683 } = args;
684 const swapTransaction = (swapsTransactions && swapsTransactions[id]) || {};
685 const totalGas = calculateTotalGas({
686 ...txParams,
687 gas: swapTransaction.gasUsed || gas,
688 });
689 const sourceToken = swapsTokens?.find(
690 ({ address }) => address === swapTransaction?.sourceToken?.address,
691 );
692 const destinationToken =
693 swapTransaction?.destinationToken?.swaps ||
694 swapsTokens?.find(
695 ({ address }) => address === swapTransaction?.destinationToken?.address,
696 );
697 if (!sourceToken || !destinationToken) return [undefined, undefined];
698
699 const renderFrom = renderFullAddress(from);
700 const renderTo = renderFullAddress(to);
701 const ticker = getTicker(args.ticker);
702 const totalEthGas = renderFromWei(totalGas);
703 const decimalSourceAmount =
704 swapTransaction.sourceAmount &&
705 renderFromTokenMinimalUnit(
706 swapTransaction.sourceAmount,
707 swapTransaction.sourceToken.decimals,
708 );
709 const decimalDestinationAmount =
710 swapTransaction.destinationToken.decimals &&
711 renderFromTokenMinimalUnit(
712 !!swapTransaction?.receivedDestinationAmount &&
713 swapTransaction?.receivedDestinationAmount > 0
714 ? swapTransaction.receivedDestinationAmount
715 : swapTransaction.destinationAmount,
716 swapTransaction.destinationToken.decimals,
717 );
718 let totalAmountForEthSourceTokenFormatted;
719 if (sourceToken.symbol === 'ETH') {
720 const totalAmountForEthSourceToken =
721 Number(!isNaN(totalEthGas) ? totalEthGas : 0) +
722 Number(decimalSourceAmount);
723 totalAmountForEthSourceTokenFormatted = `${limitToMaximumDecimalPlaces(
724 totalAmountForEthSourceToken,

Callers 1

decodeTransactionFunction · 0.85

Calls 14

renderFullAddressFunction · 0.90
getTickerFunction · 0.90
renderFromWeiFunction · 0.90
stringsFunction · 0.90
isSwapsNativeAssetFunction · 0.90
safeToChecksumAddressFunction · 0.90
balanceToFiatNumberFunction · 0.90
addCurrencySymbolFunction · 0.90
weiToFiatNumberFunction · 0.90
weiToFiatFunction · 0.90

Tested by

no test coverage detected