Skip to content

Commit 08acffd

Browse files
authored
fix(one-time-payment): start polling timeout after making payment (#1161)
1 parent e8a1861 commit 08acffd

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

src/background/services/monetization.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import type {
77
StopMonetizationPayload,
88
} from '@/shared/messages';
99
import { getSender, getTabId } from '@/background/utils';
10-
import { OUTGOING_PAYMENT_POLLING_MAX_DURATION } from '@/background/config';
1110
import {
1211
ErrorWithKey,
1312
isOkState,
@@ -313,11 +312,10 @@ export class MonetizationService {
313312
throw new ErrorWithKey('pay_error_notMonetized');
314313
}
315314

316-
const signal = AbortSignal.timeout(OUTGOING_PAYMENT_POLLING_MAX_DURATION); // can use other signals as well, such as popup closed etc.
317315
const amountToSend = BigInt(
318316
(Number(amount) * 10 ** walletAddress.assetScale).toFixed(0),
319317
);
320-
const result = await paymentManager.pay(amountToSend, signal);
318+
const result = await paymentManager.pay(amountToSend);
321319

322320
const { sentAmount, debitAmount } = result.amounts;
323321
return {

src/background/services/paymentManager.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import type { PaymentSession } from './paymentSession';
88
import {
99
MIN_PAYMENT_WAIT,
1010
OUTGOING_PAYMENT_POLLING_MAX_ATTEMPTS,
11-
} from '../config';
11+
OUTGOING_PAYMENT_POLLING_MAX_DURATION,
12+
} from '@/background/config';
1213
import { bigIntMax } from '../utils';
1314
import {
1415
ErrorWithKey,
@@ -183,7 +184,7 @@ export class PaymentManager {
183184
// #endregion
184185

185186
// #region One time payment
186-
async pay(amount: bigint, signal?: AbortSignal) {
187+
async pay(amount: bigint) {
187188
const payableSessions = this.payableSessions;
188189
if (!payableSessions.length) {
189190
throw new Error('No sessions to pay');
@@ -219,6 +220,7 @@ export class PaymentManager {
219220
);
220221

221222
this.logger.debug('polling outgoing payments for completion');
223+
const signal = AbortSignal.timeout(OUTGOING_PAYMENT_POLLING_MAX_DURATION); // can combined with other signals as well, such as popup closed etc.
222224
const result = await this.getPayStatus(
223225
outgoingPaymentResults,
224226
Array.from(distribution.keys()),

0 commit comments

Comments
 (0)