Skip to content

Commit

Permalink
chore: minor changes to thorchain swapper tx status during swaps
Browse files Browse the repository at this point in the history
  • Loading branch information
woodenfurniture committed Sep 28, 2024
1 parent 1704cbd commit 299675e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
5 changes: 4 additions & 1 deletion packages/swapper/src/swappers/ThorchainSwapper/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -386,6 +386,7 @@ export const thorchainApi: SwapperApi = {
)

if (outboundTxConfirmations !== undefined && outboundTxConfirmations > 0) {
console.log({ outboundTxConfirmations, hasOutboundTx, buyTxHash })
return {
buyTxHash,
status: TxStatus.Confirmed,
Expand All @@ -396,6 +397,8 @@ export const thorchainApi: SwapperApi = {

const { message, status } = getLatestThorTxStatusMessage(data, hasOutboundTx)

console.log({ message, status })

return {
buyTxHash,
status,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,18 @@ 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]
if (obj === undefined) continue

if (!hasOutboundTx && obj.completed) {
return {
message: 'Swap finalized',
message: 'Swap finalized, awaiting transaction confirmation',
status: TxStatus.Confirmed,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const StreamingSwap = (props: StreamingSwapProps) => {
<Row>
<Row.Label>{translate('trade.streamStatus')}</Row.Label>
{totalSwapCount > 0 && (
<Row.Value>{`${attemptedSwapCount} of ${totalSwapCount}`}</Row.Value>
<Row.Value>{`${attemptedSwapCount - failedSwaps.length} of ${totalSwapCount}`}</Row.Value>
)}
</Row>
<Row>
Expand All @@ -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'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 299675e

Please sign in to comment.