Skip to content

Commit 30ab2cf

Browse files
authored
Merge pull request #2379 from AmbireTech/fix/dapp-return-correct-tx-id
Return the correct txnId to the dapp in the case of a 4337 txnId replacement
2 parents 8f59551 + b9c378d commit 30ab2cf

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

src/controllers/activity/activity.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1416,7 +1416,7 @@ export class ActivityController extends EventEmitter implements IActivityControl
14161416
if (counter >= 30) return activityAccountOp.txnId
14171417

14181418
// eslint-disable-next-line @typescript-eslint/no-floating-promises
1419-
await wait(1000)
1419+
await wait(2000)
14201420
return this.getConfirmedTxId(submittedAccountOp, counter + 1)
14211421
}
14221422

src/controllers/main/main.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,9 +1021,12 @@ export class MainController extends EventEmitter implements IMainController {
10211021
const txnId = await this.activity.getConfirmedTxId(submittedAccountOp)
10221022
dappHandlers.forEach((handler) => {
10231023
if (txnId) {
1024-
// If the call has a txnId, resolve the promise with it.
1025-
// This could happen when an EOA account is broadcasting multiple transactions.
1026-
handler.promise.resolve({ hash: handler.txnId || txnId })
1024+
// for MultipleTxns, the correct txnId is passed to the handler;
1025+
// otherwise, use the confirmed txnId
1026+
const finalTxnId =
1027+
submittedAccountOp.identifiedBy.type === 'MultipleTxns' ? handler.txnId || txnId : txnId
1028+
1029+
handler.promise.resolve({ hash: finalTxnId })
10271030
} else {
10281031
handler.promise.reject(
10291032
ethErrors.rpc.transactionRejected({
@@ -1750,7 +1753,13 @@ export class MainController extends EventEmitter implements IMainController {
17501753
if (dappPromise.meta.isWalletSendCalls) {
17511754
dappPromise.resolve({ hash: getDappIdentifier(submittedAccountOp) })
17521755
} else {
1753-
dappHandlers.push({ promise: dappPromise, txnId: submittedAccountOp.txnId })
1756+
// if the submittedAccountOp identifier is MultipleTxns,
1757+
// the txnId for the dappPromise will be in the call itself
1758+
const submittedCall = submittedAccountOp.calls.find(
1759+
(call) => call.dappPromiseId === dappPromise.id
1760+
)
1761+
1762+
dappHandlers.push({ promise: dappPromise, txnId: submittedCall?.txnId })
17541763
}
17551764
})
17561765

0 commit comments

Comments
 (0)