UNPKG

@adyen/adyen-platform-experience-web

Version:

![Platform Experience header](https://github.com/Adyen/adyen-platform-experience-web/assets/7926613/18094965-9e01-450e-8dc9-ea84e6b22c2b)

47 lines (46 loc) 1.78 kB
import { createDuplexTransactionNavigator as w } from "./transactionNavigator/createDuplexTransactionNavigator.js"; import { useState as d, useRef as e, useMemo as A, useCallback as I, useEffect as m } from "../../../../../external/preact/hooks/dist/hooks.module.js"; import { useFetch as O } from "../../../../../hooks/useFetch.js"; import { useConfigContext as P } from "../../../../../core/ConfigContext/context.js"; import { EMPTY_OBJECT as N } from "../../../../../utils/value/constants.js"; const J = (s) => { const [i, y] = d(s), [t, r] = d(s.id), [C, E] = d(performance.now()), { getTransaction: a } = P().endpoints, h = e(w()), b = h.current, u = e(!1), l = e(!1), g = e(s), p = e(t), x = A(() => !!a && !!t && u.current, [t, a]), M = I( () => a(N, { path: { transactionId: t } }), [t, a] ), { data: o, error: T, isFetching: c } = O({ fetchOptions: { enabled: x }, queryFn: M }), q = I(() => r(void 0), []); return m(() => { t || r(i.id); }, [t, i]), m(() => { var v; const n = h.current, f = g.current; return f.category === "Refund" && (n.reset(f.id, (v = f.refundMetadata) == null ? void 0 : v.originalPaymentId), n.onNavigation = ({ to: F }) => { u.current = !0, E(performance.now()), F && r(F); }), () => { u.current = !1, n.onNavigation = null, n.reset(); }; }, []), m(() => { if (l.current !== c && !(l.current = c)) if (!o || T) r(p.current); else { const n = g.current; y(() => ({ ...o.id === n.id ? n : N, ...o })), p.current = t; } }, [o, T, c, t, C]), { fetchingTransaction: c, refreshTransaction: q, transaction: i, transactionNavigator: b }; }; export { J as default, J as useTransaction };