From 943118b8cb2e388a41f6667d2dad9556e206c285 Mon Sep 17 00:00:00 2001 From: ian Date: Sun, 18 Feb 2024 17:32:02 +0800 Subject: [PATCH] :recycle: Consider duplicated tx as pending (#52) The submitting page will repeat sending the tx. It should ignore the error PoolRejectedDuplicatedTransactionAsPending (-1107) and consider the tx as pending instead of rejected. Closes #49 --- .../[connection]/submit-building-packet.js | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/app/u/[wallet]/[connection]/submit-building-packet.js b/src/app/u/[wallet]/[connection]/submit-building-packet.js index fb32664..1ca3f0f 100644 --- a/src/app/u/[wallet]/[connection]/submit-building-packet.js +++ b/src/app/u/[wallet]/[connection]/submit-building-packet.js @@ -9,6 +9,28 @@ function isDone({ txStatus: { status } }) { return status === "committed" || status === "rejected"; } +function considerPoolRejectedDuplicatedTransactionAsPending(state) { + const { + txStatus: { status, reason }, + } = state; + const reasonString = reason ?? ""; + if (status === "rejected" && reasonString.indexOf("-1107") !== -1) { + return { + ...state, + txStatus: { + status: "pending", + reason: null, + }, + }; + } + + return state; +} + +function decorateState(state) { + return considerPoolRejectedDuplicatedTransactionAsPending(state); +} + function sendUntilDone(tx, setState) { let aborted = false; let timeout = null; @@ -16,8 +38,9 @@ function sendUntilDone(tx, setState) { const fn = () => { sendTx(tx).then((state) => { if (!aborted) { - setState(state); - if (!isDone(state)) { + const decoratedState = decorateState(state); + setState(decoratedState); + if (!isDone(decoratedState)) { timeout = setTimeout(fn, 3000); } }