From 299675ed9b8cb440a0237e96a9753f57096bb2d0 Mon Sep 17 00:00:00 2001 From: woodenfurniture <125113430+woodenfurniture@users.noreply.github.com> Date: Sat, 28 Sep 2024 18:22:45 +1000 Subject: [PATCH 1/2] chore: minor changes to thorchain swapper tx status during swaps --- .../swapper/src/swappers/ThorchainSwapper/endpoints.ts | 5 ++++- .../ThorchainSwapper/utils/getLatestThorTxStatusMessage.ts | 7 +++++-- .../MultiHopTradeConfirm/components/StreamingSwap.tsx | 4 ++-- .../hooks/useThorStreamingProgress.tsx | 6 ++++-- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/packages/swapper/src/swappers/ThorchainSwapper/endpoints.ts b/packages/swapper/src/swappers/ThorchainSwapper/endpoints.ts index 70550b27d74..dd1458eb4e9 100644 --- a/packages/swapper/src/swappers/ThorchainSwapper/endpoints.ts +++ b/packages/swapper/src/swappers/ThorchainSwapper/endpoints.ts @@ -373,7 +373,7 @@ export const thorchainApi: SwapperApi = { } const latestOutTx = data.out_txs?.[data.out_txs.length - 1] - const hasOutboundTx = latestOutTx?.chain !== 'THOR' + const hasOutboundTx = latestOutTx !== undefined && latestOutTx.chain !== 'THOR' const buyTxHash = parseThorBuyTxHash(txHash, latestOutTx) @@ -386,6 +386,7 @@ export const thorchainApi: SwapperApi = { ) if (outboundTxConfirmations !== undefined && outboundTxConfirmations > 0) { + console.log({ outboundTxConfirmations, hasOutboundTx, buyTxHash }) return { buyTxHash, status: TxStatus.Confirmed, @@ -396,6 +397,8 @@ export const thorchainApi: SwapperApi = { const { message, status } = getLatestThorTxStatusMessage(data, hasOutboundTx) + console.log({ message, status }) + return { buyTxHash, status, diff --git a/packages/swapper/src/swappers/ThorchainSwapper/utils/getLatestThorTxStatusMessage.ts b/packages/swapper/src/swappers/ThorchainSwapper/utils/getLatestThorTxStatusMessage.ts index e47e4c99b8f..6e540f6b49f 100644 --- a/packages/swapper/src/swappers/ThorchainSwapper/utils/getLatestThorTxStatusMessage.ts +++ b/packages/swapper/src/swappers/ThorchainSwapper/utils/getLatestThorTxStatusMessage.ts @@ -61,7 +61,10 @@ export const getLatestThorTxStatusMessage = ( } } - return { message: obj.pending ? 'Swap pending' : 'Swap complete', status: TxStatus.Pending } + return { + message: obj.pending ? 'Swap pending' : 'Swap complete, awaiting finalization', + status: TxStatus.Pending, + } } case 'swap_finalised': { const obj = response.stages[key] @@ -69,7 +72,7 @@ export const getLatestThorTxStatusMessage = ( if (!hasOutboundTx && obj.completed) { return { - message: 'Swap finalized', + message: 'Swap finalized, awaiting transaction confirmation', status: TxStatus.Confirmed, } } diff --git a/src/components/MultiHopTrade/components/MultiHopTradeConfirm/components/StreamingSwap.tsx b/src/components/MultiHopTrade/components/MultiHopTradeConfirm/components/StreamingSwap.tsx index 5112be1351b..05d30593848 100644 --- a/src/components/MultiHopTrade/components/MultiHopTradeConfirm/components/StreamingSwap.tsx +++ b/src/components/MultiHopTrade/components/MultiHopTradeConfirm/components/StreamingSwap.tsx @@ -26,7 +26,7 @@ export const StreamingSwap = (props: StreamingSwapProps) => { {translate('trade.streamStatus')} {totalSwapCount > 0 && ( - {`${attemptedSwapCount} of ${totalSwapCount}`} + {`${attemptedSwapCount - failedSwaps.length} of ${totalSwapCount}`} )} @@ -36,7 +36,7 @@ export const StreamingSwap = (props: StreamingSwapProps) => { size='sm' min={0} max={totalSwapCount} - value={attemptedSwapCount} + value={attemptedSwapCount - failedSwaps.length} hasStripe={!isComplete} isAnimated={!isComplete} colorScheme={isComplete ? 'green' : 'blue'} diff --git a/src/components/MultiHopTrade/components/MultiHopTradeConfirm/hooks/useThorStreamingProgress.tsx b/src/components/MultiHopTrade/components/MultiHopTradeConfirm/hooks/useThorStreamingProgress.tsx index bf8ef51bdc0..d9c7c260322 100644 --- a/src/components/MultiHopTrade/components/MultiHopTradeConfirm/hooks/useThorStreamingProgress.tsx +++ b/src/components/MultiHopTrade/components/MultiHopTradeConfirm/hooks/useThorStreamingProgress.tsx @@ -153,9 +153,11 @@ export const useThorStreamingProgress = ( }, [cancelPolling, dispatch, hopIndex, poll, sellTxHash, confirmedTradeId]) const result = useMemo(() => { + const numSuccessfulSwaps = + (streamingSwapMeta?.attemptedSwapCount ?? 0) - (streamingSwapMeta?.failedSwaps?.length ?? 0) + const isComplete = - streamingSwapMeta !== undefined && - streamingSwapMeta.attemptedSwapCount === streamingSwapMeta.totalSwapCount + streamingSwapMeta !== undefined && numSuccessfulSwaps >= streamingSwapMeta.totalSwapCount return { isComplete, From 3b521cac9f3a2975e82bb5c66317c57f1a785e29 Mon Sep 17 00:00:00 2001 From: woodenfurniture <125113430+woodenfurniture@users.noreply.github.com> Date: Sat, 28 Sep 2024 18:32:02 +1000 Subject: [PATCH 2/2] chore: cleaup --- packages/swapper/src/swappers/ThorchainSwapper/endpoints.ts | 4 ---- .../ThorchainSwapper/utils/getLatestThorTxStatusMessage.ts | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/swapper/src/swappers/ThorchainSwapper/endpoints.ts b/packages/swapper/src/swappers/ThorchainSwapper/endpoints.ts index dd1458eb4e9..40442034733 100644 --- a/packages/swapper/src/swappers/ThorchainSwapper/endpoints.ts +++ b/packages/swapper/src/swappers/ThorchainSwapper/endpoints.ts @@ -386,7 +386,6 @@ export const thorchainApi: SwapperApi = { ) if (outboundTxConfirmations !== undefined && outboundTxConfirmations > 0) { - console.log({ outboundTxConfirmations, hasOutboundTx, buyTxHash }) return { buyTxHash, status: TxStatus.Confirmed, @@ -396,9 +395,6 @@ export const thorchainApi: SwapperApi = { } const { message, status } = getLatestThorTxStatusMessage(data, hasOutboundTx) - - console.log({ message, status }) - return { buyTxHash, status, diff --git a/packages/swapper/src/swappers/ThorchainSwapper/utils/getLatestThorTxStatusMessage.ts b/packages/swapper/src/swappers/ThorchainSwapper/utils/getLatestThorTxStatusMessage.ts index 6e540f6b49f..8f9dbe97b45 100644 --- a/packages/swapper/src/swappers/ThorchainSwapper/utils/getLatestThorTxStatusMessage.ts +++ b/packages/swapper/src/swappers/ThorchainSwapper/utils/getLatestThorTxStatusMessage.ts @@ -72,7 +72,7 @@ export const getLatestThorTxStatusMessage = ( if (!hasOutboundTx && obj.completed) { return { - message: 'Swap finalized, awaiting transaction confirmation', + message: undefined, // undefined because the tx is complete and no message will be displayed status: TxStatus.Confirmed, } }