Skip to content

Commit

Permalink
Merge pull request #1316 from AmbireTech/fix/always-pending-active-ro…
Browse files Browse the repository at this point in the history
…ute-due-to-a-failed-txn

Fix / Always Pending Active Route due to a Failed Transaction
  • Loading branch information
sonytooo authored Feb 19, 2025
2 parents a9aa0c7 + 059bb68 commit ade6cd9
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/controllers/swapAndBridge/swapAndBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1354,16 +1354,24 @@ export class SwapAndBridgeController extends EventEmitter {
if (!activeRoute) return

let shouldUpdateActiveRouteStatus = false
if (activeRoute.route.fromChainId === activeRoute.route.toChainId)
shouldUpdateActiveRouteStatus = true

const isSwap = activeRoute.route.fromChainId === activeRoute.route.toChainId

// force update the active route status if the route is of type 'swap'
if (isSwap) shouldUpdateActiveRouteStatus = true

// force update the active route status if the last tx of a 'bridge' is of type 'swap'
if (activeRoute.route.currentUserTxIndex + 1 === activeRoute.route.totalUserTx) {
const tx = activeRoute.route.userTxs[activeRoute.route.currentUserTxIndex]
if (!tx) return

if (tx.userTxType === 'dex-swap') shouldUpdateActiveRouteStatus = true
}

// force update the active route with an error message if the tx fails (for both swap and bridge)
if (opStatus === AccountOpStatus.Failure || opStatus === AccountOpStatus.Rejected)
shouldUpdateActiveRouteStatus = true

if (!shouldUpdateActiveRouteStatus) return

if (opStatus === AccountOpStatus.Success) {
Expand Down

0 comments on commit ade6cd9

Please sign in to comment.