commit 09f67371c36bbe818d467b654a30abe91b9aad85
parent fab425b7a3e44fff1b7046e7440c1e4bd5d702fa
Author: Sebastian <sebasjm@taler-systems.com>
Date: Mon, 27 Jul 2026 15:03:41 -0300
fix long polling wait
Diffstat:
1 file changed, 30 insertions(+), 21 deletions(-)
diff --git a/packages/taler-merchant-webui/src/hooks/order.ts b/packages/taler-merchant-webui/src/hooks/order.ts
@@ -118,6 +118,7 @@ export function useInstanceOrders(args?: InstanceOrderFilter) {
const cacheKey = [
pointer.id,
+ pointer.order,
args?.paid,
args?.refunded,
args?.wired,
@@ -125,36 +126,44 @@ export function useInstanceOrders(args?: InstanceOrderFilter) {
"listOrders",
];
- type Res =
- | undefined
- | Awaited<ReturnType<typeof lib.instance.listOrders>>;
+ type Res = undefined | Awaited<ReturnType<typeof lib.instance.listOrders>>;
const result = useLongPolling(
- async (ct, latestStatus, args): Promise<Res> => {
- const noRes = latestStatus === undefined || latestStatus.type === "fail"
- const prev = noRes ? [] : latestStatus.body.orders
+ async (
+ ct,
+ latestStatus,
+ [offset, order, paid, refunded, wired, date],
+ ): Promise<Res> => {
+ // either first request or the last one had an error
+ const skipLongPoll =
+ latestStatus === undefined || latestStatus.type === "fail";
const params: ListOrdersRequestParams = {
- limit: 1,
- order: "asc",
- offset: args[0],
- paid: args[1],
- refunded: args[2],
- wired: args[3],
- date: args[4],
+ limit: PAGINATED_LIST_REQUEST,
+ order,
+ offset,
+ paid,
+ refunded,
+ wired,
+ date,
};
+ if (!skipLongPoll) {
+ // wait for a new order to arrive before getting the result
+ const result = await lib.instance.listOrders(token, {
+ ...params,
+ limit: 1,
+ order: "asc",
+ timeout: LONG_POLL_DELAY,
+ ct,
+ });
+ // fail fast, nothing new to report
+ if (result.type === "fail" || !result.body.orders.length) return latestStatus;
+ }
const result = await lib.instance.listOrders(token, {
...params,
- timeout: noRes ? undefined : LONG_POLL_DELAY,
ct,
});
- const merged =
- result.type === "fail" || result.body.orders.length === 0
- ? prev
- : [...result.body.orders, ...prev];
-
- const newResult = opFixedSuccess(dummyHttpResponse, { orders: merged });
- return newResult;
+ return result;
},
{ minTime: LONG_POLL_DELAY, deps: cacheKey },
);