@adyen/adyen-platform-experience-web
Version:

26 lines (25 loc) • 974 B
JavaScript
import { useFetch as h } from "./useFetch.js";
import { useMemo as s } from "../external/preact/hooks/dist/hooks.module.js";
import { useConfigContext as p } from "../core/ConfigContext/context.js";
import { EMPTY_OBJECT as u } from "../utils/value/constants.js";
const y = (t, i) => {
const { getBalanceAccounts: o } = p().endpoints, { data: e, isFetching: m, error: f } = h(
s(
() => ({
fetchOptions: { enabled: !!o && (i ?? !0), keepPrevData: !0 },
queryFn: async () => o == null ? void 0 : o(u)
}),
[o]
)
), r = s(
() => e == null ? void 0 : e.data.filter((n) => t ? n.id === t : !0),
[e == null ? void 0 : e.data, t]
), g = s(
() => !!t && !!(e != null && e.data.length) && (r == null ? void 0 : r.length) === 0,
[r == null ? void 0 : r.length, e == null ? void 0 : e.data.length, t]
);
return { balanceAccounts: r, isBalanceAccountIdWrong: g, isFetching: m, error: f };
};
export {
y as default
};