Skip to content

Commit

Permalink
♻️ Consider duplicated tx as pending (#52)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
doitian authored Feb 18, 2024
1 parent 654ec01 commit 943118b
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/app/u/[wallet]/[connection]/submit-building-packet.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,38 @@ 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;

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);
}
}
Expand Down

0 comments on commit 943118b

Please sign in to comment.