Skip to content

Commit

Permalink
Do not retrigger "approved" for a given transaction until a minute ha…
Browse files Browse the repository at this point in the history
…s elapsed
  • Loading branch information
j3k0 committed Dec 1, 2024
1 parent 92418b3 commit 71a071c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/ts/internal/adapter-listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,14 @@ namespace CdvPurchase
// Retrigger "approved", so validation is rerun on potential update.
if (transaction.state === TransactionState.APPROVED) {
// prevent calling approved twice in a very short period (60 seconds).
if ((this.lastCallTimeForState[tokenWithState] | 0) < now - 60000) {
const lastCalled = this.lastCallTimeForState[tokenWithState] ?? 0;
if (now - lastCalled > 60000) {
this.lastCallTimeForState[tokenWithState] = now;
this.delegate.approvedCallbacks.trigger(transaction, 'adapterListener_receiptsUpdated_approved');
}
else {
this.log.debug(`Skipping ${tokenWithState}, because it has been last called ${lastCalled > 0 ? Math.round(now - lastCalled) + 'ms ago (' + now + '-' + lastCalled + ')' : 'never'}`);
}
}
else if (lastState !== transaction.state) {
if (transaction.state === TransactionState.INITIATED) {
Expand Down

0 comments on commit 71a071c

Please sign in to comment.