From 78a6c3f9bce6c90a7bda558f30c3919cd72c9681 Mon Sep 17 00:00:00 2001 From: gomes <17035424+gomesalexandre@users.noreply.github.com> Date: Thu, 18 Dec 2025 00:31:24 +0300 Subject: [PATCH] feat: upsert second-class Txs --- .../useSendActionSubscriber.tsx | 21 +++++++- .../useSwapActionSubscriber.tsx | 48 ++++++++++++++++++- 2 files changed, 66 insertions(+), 3 deletions(-) diff --git a/src/hooks/useActionCenterSubscribers/useSendActionSubscriber.tsx b/src/hooks/useActionCenterSubscribers/useSendActionSubscriber.tsx index c411c82abe8..414b5911e65 100644 --- a/src/hooks/useActionCenterSubscribers/useSendActionSubscriber.tsx +++ b/src/hooks/useActionCenterSubscribers/useSendActionSubscriber.tsx @@ -9,6 +9,7 @@ import { useNotificationToast } from '../useNotificationToast' import { useActionCenterContext } from '@/components/Layout/Header/ActionCenter/ActionCenterContext' import { GenericTransactionNotification } from '@/components/Layout/Header/ActionCenter/components/Notifications/GenericTransactionNotification' import { SECOND_CLASS_CHAINS } from '@/constants/chains' +import { getChainAdapterManager } from '@/context/PluginProvider/chainAdapterSingleton' import { getMonadTransactionStatus } from '@/lib/utils/monad' import { getPlasmaTransactionStatus } from '@/lib/utils/plasma' import { getSuiTransactionStatus } from '@/lib/utils/sui' @@ -18,6 +19,7 @@ import { selectPendingWalletSendActions } from '@/state/slices/actionSlice/selec import { ActionStatus } from '@/state/slices/actionSlice/types' import { portfolioApi } from '@/state/slices/portfolioSlice/portfolioSlice' import { selectTxs } from '@/state/slices/selectors' +import { txHistory } from '@/state/slices/txHistorySlice/txHistorySlice' import { serializeTxIndex } from '@/state/slices/txHistorySlice/utils' import { useAppDispatch, useAppSelector } from '@/state/store' @@ -146,6 +148,23 @@ export const useSendActionSubscriber = () => { } if (isConfirmed) { + // Parse and upsert Tx for second-class chains + try { + const adapter = getChainAdapterManager().get(chainId) + if (adapter?.parseTx) { + const parsedTx = await adapter.parseTx(txHash, accountAddress) + dispatch( + txHistory.actions.onMessage({ + message: parsedTx, + accountId, + }), + ) + } + } catch (error) { + // Silent fail - Tx just won't show in history + console.error('Failed to parse and upsert Tx:', error) + } + completeAction(action) const intervalId = pollingIntervalsRef.current.get(pollingKey) @@ -173,7 +192,7 @@ export const useSendActionSubscriber = () => { completeAction(action) }) - }, [txs, pendingSendActions, completeAction]) + }, [txs, pendingSendActions, completeAction, dispatch]) useEffect(() => { const intervals = pollingIntervalsRef.current diff --git a/src/hooks/useActionCenterSubscribers/useSwapActionSubscriber.tsx b/src/hooks/useActionCenterSubscribers/useSwapActionSubscriber.tsx index 91e732b3302..dfcca3b63e3 100644 --- a/src/hooks/useActionCenterSubscribers/useSwapActionSubscriber.tsx +++ b/src/hooks/useActionCenterSubscribers/useSwapActionSubscriber.tsx @@ -27,6 +27,7 @@ import { useActionCenterContext } from '@/components/Layout/Header/ActionCenter/ import { SwapNotification } from '@/components/Layout/Header/ActionCenter/components/Notifications/SwapNotification' import { getConfig } from '@/config' import { SECOND_CLASS_CHAINS } from '@/constants/chains' +import { getChainAdapterManager } from '@/context/PluginProvider/chainAdapterSingleton' import { queryClient } from '@/context/QueryClientProvider/queryClient' import { useFeatureFlag } from '@/hooks/useFeatureFlag/useFeatureFlag' import { getTxLink } from '@/lib/getTxLink' @@ -42,6 +43,7 @@ import { portfolioApi } from '@/state/slices/portfolioSlice/portfolioSlice' import { swapSlice } from '@/state/slices/swapSlice/swapSlice' import { selectConfirmedTradeExecution } from '@/state/slices/tradeQuoteSlice/selectors' import { tradeQuoteSlice } from '@/state/slices/tradeQuoteSlice/tradeQuoteSlice' +import { txHistory } from '@/state/slices/txHistorySlice/txHistorySlice' import { store, useAppDispatch, useAppSelector } from '@/state/store' const swapStatusToActionStatus = { @@ -273,11 +275,53 @@ export const useSwapActionSubscriber = () => { }), ) - const { getAccount } = portfolioApi.endpoints - + // Parse and upsert Txs for second-class chains const sellChainId = fromAccountId(swap.sellAccountId).chainId const isSellSecondClassChain = SECOND_CLASS_CHAINS.includes(sellChainId as KnownChainIds) + if (isSellSecondClassChain && swap.sellTxHash) { + try { + const adapter = getChainAdapterManager().get(sellChainId) + const { account: sellAddress } = fromAccountId(swap.sellAccountId) + if (adapter?.parseTx) { + const parsedSellTx = await adapter.parseTx(swap.sellTxHash, sellAddress) + dispatch( + txHistory.actions.onMessage({ + message: parsedSellTx, + accountId: swap.sellAccountId, + }), + ) + } + } catch (error) { + console.error('Failed to parse and upsert sell Tx:', error) + } + } + + if (buyTxHash && swap.buyAccountId) { + const buyChainId = fromAccountId(swap.buyAccountId).chainId + const isBuySecondClassChain = SECOND_CLASS_CHAINS.includes(buyChainId as KnownChainIds) + + if (isBuySecondClassChain) { + try { + const adapter = getChainAdapterManager().get(buyChainId) + const { account: buyAddress } = fromAccountId(swap.buyAccountId) + if (adapter?.parseTx) { + const parsedBuyTx = await adapter.parseTx(buyTxHash, buyAddress) + dispatch( + txHistory.actions.onMessage({ + message: parsedBuyTx, + accountId: swap.buyAccountId, + }), + ) + } + } catch (error) { + console.error('Failed to parse and upsert buy Tx:', error) + } + } + } + + const { getAccount } = portfolioApi.endpoints + if (isSellSecondClassChain) { dispatch( getAccount.initiate(