From 67de92a94e261076cf3592edb9c63ba1d0f81486 Mon Sep 17 00:00:00 2001 From: IF <139582705+infiniteflower@users.noreply.github.com> Date: Thu, 14 Nov 2024 15:56:51 -0500 Subject: [PATCH] chore: show pending and bridge amount for STX in tx details --- ui/helpers/utils/token-util.js | 3 +- ui/pages/bridge/hooks/useHandleBridgeTx.ts | 7 ++ .../transaction-details.tsx | 70 ++++++++++++++++--- 3 files changed, 68 insertions(+), 12 deletions(-) diff --git a/ui/helpers/utils/token-util.js b/ui/helpers/utils/token-util.js index f64f74f62fa6..10beae68b39e 100644 --- a/ui/helpers/utils/token-util.js +++ b/ui/helpers/utils/token-util.js @@ -217,7 +217,8 @@ export function getTokenFiatAmount( if ( conversionRate <= 0 || !contractExchangeRate || - tokenAmount === undefined + tokenAmount === undefined || + tokenAmount === false ) { return undefined; } diff --git a/ui/pages/bridge/hooks/useHandleBridgeTx.ts b/ui/pages/bridge/hooks/useHandleBridgeTx.ts index e7795c2d2ce5..0d33b8248e13 100644 --- a/ui/pages/bridge/hooks/useHandleBridgeTx.ts +++ b/ui/pages/bridge/hooks/useHandleBridgeTx.ts @@ -33,10 +33,17 @@ export default function useHandleBridgeTx() { // estimatedBaseFee: decEstimatedBaseFee, // swapMetaData, type: TransactionType.bridge, + + sourceTokenAmount: quoteResponse.quote.srcTokenAmount, sourceTokenSymbol: quoteResponse.quote.srcAsset.symbol, + sourceTokenDecimals: quoteResponse.quote.srcAsset.decimals, + sourceTokenAddress: quoteResponse.quote.srcAsset.address, + + destinationTokenAmount: quoteResponse.quote.destTokenAmount, destinationTokenSymbol: quoteResponse.quote.destAsset.symbol, destinationTokenDecimals: quoteResponse.quote.destAsset.decimals, destinationTokenAddress: quoteResponse.quote.destAsset.address, + approvalTxId, // this is the decimal (non atomic) amount (not USD value) of source token to swap swapTokenValue: sentAmountDec, diff --git a/ui/pages/bridge/transaction-details/transaction-details.tsx b/ui/pages/bridge/transaction-details/transaction-details.tsx index 788c7b46f800..5cb5a3fb86db 100644 --- a/ui/pages/bridge/transaction-details/transaction-details.tsx +++ b/ui/pages/bridge/transaction-details/transaction-details.tsx @@ -26,7 +26,10 @@ import UserPreferencedCurrencyDisplay from '../../../components/app/user-prefere import { EtherDenomination } from '../../../../shared/constants/common'; import { PRIMARY, SECONDARY } from '../../../helpers/constants/common'; import CurrencyDisplay from '../../../components/ui/currency-display/currency-display.component'; -import { StatusTypes } from '../../../../shared/types/bridge-status'; +import { + BridgeHistoryItem, + StatusTypes, +} from '../../../../shared/types/bridge-status'; import { AlignItems, Display, @@ -63,6 +66,51 @@ const getBlockExplorerUrl = ( return `${rootUrl}/tx/${txHash}`; }; +const getBridgeHistoryItem = ( + srcTxHashOrTxId: string | undefined, + bridgeHistory: Record, + srcChainTxMeta: TransactionMeta | undefined, +) => { + if (!srcTxHashOrTxId) { + return undefined; + } + + const historyItemFromUrlParamHash = bridgeHistory[srcTxHashOrTxId]; + const historyItemFromTxMetaHash = srcChainTxMeta?.hash + ? bridgeHistory[srcChainTxMeta?.hash] + : undefined; + + return historyItemFromUrlParamHash || historyItemFromTxMetaHash; +}; + +const getBridgeAmount = ({ + bridgeHistoryItem, + srcChainTxMeta, +}: { + bridgeHistoryItem?: BridgeHistoryItem; + srcChainTxMeta?: TransactionMeta; +}) => { + if (bridgeHistoryItem) { + return `${calcTokenAmount( + bridgeHistoryItem.quote.srcTokenAmount, + bridgeHistoryItem.quote.srcAsset.decimals, + ).toFixed()} ${bridgeHistoryItem.quote.srcAsset.symbol}`; + } + + if ( + srcChainTxMeta && + srcChainTxMeta.sourceTokenAmount && + srcChainTxMeta.sourceTokenDecimals + ) { + return `${calcTokenAmount( + srcChainTxMeta.sourceTokenAmount, + srcChainTxMeta.sourceTokenDecimals, + ).toFixed()} ${srcChainTxMeta.sourceTokenSymbol}`; + } + + return undefined; +}; + const StatusToColorMap: Record = { [StatusTypes.PENDING]: TextColor.warningDefault, [StatusTypes.COMPLETE]: TextColor.successDefault, @@ -81,9 +129,6 @@ const CrossChainSwapTxDetails = () => { selectedAddressTxListSelector, ) as TransactionMeta[]; - const bridgeHistoryItem = srcTxHashOrTxId - ? bridgeHistory[srcTxHashOrTxId] - : undefined; const networkConfigurationsByChainId = useSelector( getNetworkConfigurationsByChainId, ); @@ -91,6 +136,12 @@ const CrossChainSwapTxDetails = () => { const srcChainTxMeta = selectedAddressTxList.find( (tx) => tx.hash === srcTxHashOrTxId || tx.id === srcTxHashOrTxId, ); + // Even if user is still on /tx-details/txMetaId, we want to be able to show the bridge history item + const bridgeHistoryItem = getBridgeHistoryItem( + srcTxHashOrTxId, + bridgeHistory, + srcChainTxMeta, + ); const { srcNetworkConfiguration, destNetworkConfiguration } = useBridgeChainInfo({ @@ -109,7 +160,9 @@ const CrossChainSwapTxDetails = () => { destTxHash, ); - const status = bridgeHistoryItem?.status.status; + const status = bridgeHistoryItem + ? bridgeHistoryItem?.status.status + : StatusTypes.PENDING; const destChainIconUrl = destNetworkConfiguration ? CHAIN_ID_TO_NETWORK_IMAGE_URL_MAP[ @@ -127,12 +180,7 @@ const CrossChainSwapTxDetails = () => { }) : undefined; - const bridgeAmount = bridgeHistoryItem - ? `${calcTokenAmount( - bridgeHistoryItem.quote.srcTokenAmount, - bridgeHistoryItem.quote.srcAsset.decimals, - ).toFixed()} ${bridgeHistoryItem.quote.srcAsset.symbol}` - : undefined; + const bridgeAmount = getBridgeAmount({ bridgeHistoryItem, srcChainTxMeta }); return (