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)

30 lines (29 loc) 1.13 kB
import { useState as B, useMemo as r, useCallback as g, useEffect as F } from "../external/.pnpm/preact@10.28.2/node_modules/preact/hooks/dist/hooks.module.js"; import { useFetch as d } from "./useFetch.js"; import { useConfigContext as C } from "../core/ConfigContext/preact/context.js"; import { isFunction as A } from "../utils/value/is.js"; import { EMPTY_OBJECT as k } from "../utils/value/constants.js"; const i = /* @__PURE__ */ new WeakMap(), x = (e, u) => { const { getBalanceAccounts: t } = C().endpoints, [n, f] = B(() => t && i.get(t)), l = r( () => !n && A(t) && u !== !1, [n, u, t] ), { data: c, isFetching: m, error: h } = d({ queryFn: g(async () => t?.(k), [t]), fetchOptions: { enabled: l, keepPrevData: !0 } }), s = n ?? c?.data, o = r( () => s?.filter((a) => !e || e === a.id), [s, e] ), p = r( () => !!e && !!s?.length && o?.length === 0, [s, e, o] ); return F(() => { if (c?.data && t) { const a = c.data; i.set(t, a), f(a); } }, [c, t]), { balanceAccounts: o, isBalanceAccountIdWrong: p, isFetching: m, error: h }; }; export { x as default };