Skip to content

Commit ba3bf4d

Browse files
fix(pos-app): use server-provided pollInMs for payment status polling (#407)
1 parent 9d9dc22 commit ba3bf4d

File tree

2 files changed

+9
-17
lines changed

2 files changed

+9
-17
lines changed

dapps/pos-app/__tests__/services/hooks.test.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ describe("Payment Hooks", () => {
311311
});
312312

313313
const { result } = renderHook(
314-
() => usePaymentStatus("pay_polling", { pollingInterval: 100 }),
314+
() => usePaymentStatus("pay_polling"),
315315
{ wrapper: createWrapper() },
316316
);
317317

@@ -392,7 +392,7 @@ describe("Payment Hooks", () => {
392392
});
393393

394394
const { result } = renderHook(
395-
() => usePaymentStatus("pay_fail_poll", { pollingInterval: 100 }),
395+
() => usePaymentStatus("pay_fail_poll"),
396396
{ wrapper: createWrapper() },
397397
);
398398

@@ -461,7 +461,6 @@ describe("Payment Hooks", () => {
461461
renderHook(
462462
() =>
463463
usePaymentStatus("pay_callback", {
464-
pollingInterval: 100,
465464
onTerminalState,
466465
}),
467466
{ wrapper: createWrapper() },

dapps/pos-app/services/hooks.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,6 @@ export function useCancelPayment() {
6565
}
6666

6767
interface UsePaymentStatusOptions {
68-
/**
69-
* Polling interval in milliseconds
70-
* @default 2000 (2 seconds)
71-
*/
72-
pollingInterval?: number;
7368
/**
7469
* Whether to enable the query
7570
* @default true
@@ -87,19 +82,14 @@ interface UsePaymentStatusOptions {
8782
* Polls until payment reaches a final state (isFinal === true).
8883
* Unknown statuses from the API are normalized to "failed".
8984
* @param paymentId - The payment ID to check status for
90-
* @param options - Query options including polling interval
85+
* @param options - Query options
9186
* @returns Query result with payment status data
9287
*/
9388
export function usePaymentStatus(
9489
paymentId: string | null | undefined,
9590
options: UsePaymentStatusOptions = {},
9691
) {
97-
const {
98-
pollingInterval = 2000,
99-
enabled = true,
100-
onTerminalState,
101-
...queryOptions
102-
} = options;
92+
const { enabled = true, onTerminalState } = options;
10393

10494
const hasCalledCallback = useRef(false);
10595
const callbackRef = useRef(onTerminalState);
@@ -134,12 +124,15 @@ export function usePaymentStatus(
134124
if (data?.isFinal) {
135125
return false;
136126
}
137-
return pollingInterval;
127+
const pollInMs = data?.pollInMs;
128+
if (typeof pollInMs !== "number" || !Number.isFinite(pollInMs) || pollInMs <= 0) {
129+
return 2000;
130+
}
131+
return pollInMs;
138132
},
139133

140134
// Let failed requests retry naturally
141135
retry: 3,
142-
...queryOptions,
143136
});
144137

145138
// Handle terminal state callback

0 commit comments

Comments
 (0)