taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit 1d3ca6ef67344819839e8baef64409bc67d924b1
parent 07b79506c9cb29b35757b52c64a4cd0c542154f2
Author: Sebastian <sebasjm@taler-systems.com>
Date:   Thu,  5 Feb 2026 11:44:53 -0300

fix #9955

Diffstat:
Mpackages/merchant-backoffice-ui/src/hooks/order.ts | 67++++++++++++++++++++++++++++++++++++++++---------------------------
1 file changed, 40 insertions(+), 27 deletions(-)

diff --git a/packages/merchant-backoffice-ui/src/hooks/order.ts b/packages/merchant-backoffice-ui/src/hooks/order.ts @@ -19,6 +19,8 @@ import { PAGINATED_LIST_REQUEST } from "../utils/constants.js"; import { AbsoluteTime, AccessToken, + ListOrdersRequestParams, + TalerError, TalerHttpError, TalerMerchantManagementResultByMethod } from "@gnu-taler/taler-util"; @@ -109,48 +111,59 @@ export function useInstanceOrders( updatePosition: (d: string | undefined) => void = () => { }, ) { const { state, lib } = useSessionContext(); - - async function fetcher([token, o, p, r, w, d]: [ - AccessToken, - string, - boolean, - boolean, - boolean, - AbsoluteTime, - ]) { - return await lib.instance.listOrders(token, { + const token = state.token! + const params: ListOrdersRequestParams = { limit: PAGINATED_LIST_REQUEST, - offset: o, + offset: args?.position, order: "dec", - paid: p, - refunded: r, - wired: w, - date: d, - }); + paid: args?.paid, + refunded: args?.refunded, + wired: args?.wired, + date: args?.date, + } + async function fetcher([]) { + return await lib.instance.listOrders(token, params); } - const { data, error } = useSWR< - TalerMerchantManagementResultByMethod<"listOrders">, - TalerHttpError - >( - [ - state.token, + const cacheKey = [ args?.position, args?.paid, args?.refunded, args?.wired, args?.date, "listOrders", - ], + ]; + + const { data, error } = useSWR< + TalerMerchantManagementResultByMethod<"listOrders">, + TalerHttpError + >( + cacheKey, fetcher, ); - if (error) return error; - if (data === undefined) return undefined; - if (data.type !== "ok") return data; + const result = useLongPolling( + data, + (result) => { + if (!result || result.type === "fail") return undefined; + return result.body + }, + async (latestStatus) => { + const r = await lib.instance.listOrders(token, {...params, timeout: LONG_POLL_DELAY}); + mutate(r, { revalidate: false }) + return r + }, + cacheKey, + { minTime: LONG_POLL_DELAY } + ); + + + if (error || result instanceof TalerError) return error; + if (result === undefined) return undefined; + if (result.type !== "ok") return result; return buildPaginatedResult( - data.body.orders, + result.body.orders, args?.position, updatePosition, (d) => String(d.row_id),