@odynn/awayz-core 0.10.23 → 0.10.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,41 @@
1
+ import { jsxs as i, Fragment as m, jsx as c } from "react/jsx-runtime";
2
+ const a = "USD", l = (r, t) => {
3
+ const n = t || a, e = new Intl.NumberFormat("en-US");
4
+ if (!r) return `${e.format(0)}${n}`;
5
+ const o = parseFloat(r.toString());
6
+ return /* @__PURE__ */ i(m, { children: [
7
+ e.format(isNaN(o) ? 0 : o),
8
+ " ",
9
+ /* @__PURE__ */ c("sub", { children: n })
10
+ ] });
11
+ }, F = (r, t) => {
12
+ const n = t || a, e = new Intl.NumberFormat("en-US", {
13
+ maximumFractionDigits: 0
14
+ });
15
+ return /* @__PURE__ */ i(m, { children: [
16
+ e.format(isNaN(r) ? 0 : r),
17
+ " ",
18
+ /* @__PURE__ */ c("sub", { children: n })
19
+ ] });
20
+ }, y = (r, t, n = 0, e = n) => {
21
+ const o = parseFloat((r == null ? void 0 : r.toString()) || "0"), s = t || a, u = new Intl.NumberFormat("en-US", {
22
+ minimumFractionDigits: e,
23
+ maximumFractionDigits: n
24
+ });
25
+ return /* @__PURE__ */ i(m, { children: [
26
+ u.format(isNaN(o) ? 0 : o),
27
+ " ",
28
+ /* @__PURE__ */ c("sub", { children: s })
29
+ ] });
30
+ }, N = (r, t = "en") => 0 .toLocaleString(t, {
31
+ style: "currency",
32
+ currency: r,
33
+ minimumFractionDigits: 0,
34
+ maximumFractionDigits: 0
35
+ }).replace(/\d/g, "").trim();
36
+ export {
37
+ F as a,
38
+ l as b,
39
+ N as c,
40
+ y as g
41
+ };
@@ -1,56 +1,62 @@
1
1
  import { jsx as r, jsxs as l } from "react/jsx-runtime";
2
- import { useQuery as R } from "@tanstack/react-query";
3
- import { g as m, a as _, b as N } from "../../cashUtils-Dlce3Uj_.js";
2
+ import { useQuery as _ } from "@tanstack/react-query";
3
+ import { g as u, a as S, b as f } from "../../cashUtils-DyxlHnod.js";
4
4
  import "../../arrayExtensions-DlcBOj5a.js";
5
- import { E as S } from "../../noRetryInstance-DNLgOg0E.js";
6
- import { useMemo as T } from "react";
7
- import { a as f } from "../../index-C8p5kinH.js";
5
+ import { E as T } from "../../noRetryInstance-DNLgOg0E.js";
6
+ import { useMemo as I } from "react";
7
+ import { a as v } from "../../index-C8p5kinH.js";
8
8
  import "react-i18next";
9
9
  import '../../assets/_styles4.css';import '../../assets/_styles2.css';import '../../assets/_styles.css';import '../../assets/_styles3.css';/* empty css */
10
10
  /* empty css */
11
11
  /* empty css */
12
- import { EInvalidAmountDisplayOption as t, EToolTipPosition as D } from "./CashValueTypes.js";
13
- import { useAwayzContext as I } from "../../hooks/useAwayzContext.js";
12
+ import { EInvalidAmountDisplayOption as t, EToolTipPosition as M } from "./CashValueTypes.js";
13
+ import { useAwayzContext as O } from "../../hooks/useAwayzContext.js";
14
14
  import "../../configs/awayzClient.js";
15
15
  /* empty css */
16
16
  import "../../context/AwayzContext.js";
17
- import { CurrencyService as M } from "../../services/currency/CurrencyService.js";
18
- import { Tooltip as O } from "../Tooltip/Tooltip.js";
19
- const x = 1e3 * 60 * 60, k = ({
17
+ import { CurrencyService as x } from "../../services/currency/CurrencyService.js";
18
+ import { Tooltip as D } from "../Tooltip/Tooltip.js";
19
+ const Y = 1e3 * 60 * 60, J = ({
20
20
  amount: i,
21
21
  currency: e,
22
- position: v = D.RIGHT,
23
- zeroDisplayOption: A = t.NA,
24
- customDisplay: y,
25
- decimalPlaces: p = 2,
26
- showConversion: g = !1,
27
- showOriginal: E = !0
22
+ position: A = M.RIGHT,
23
+ zeroDisplayOption: y = t.NA,
24
+ customDisplay: g,
25
+ decimalPlaces: s = 2,
26
+ minDecimalPlaces: d = s,
27
+ showConversion: E = !1,
28
+ showOriginal: R = !0
28
29
  }) => {
29
- var h, C;
30
- const { user: o } = I(), n = ((h = o == null ? void 0 : o.preferences) == null ? void 0 : h.currency) ?? ((C = o == null ? void 0 : o.userRegion) == null ? void 0 : C.currency), s = n !== e, { data: c, isPending: d } = R({
31
- queryKey: [S.CONVERT_CURRENCY, e, n],
32
- queryFn: () => M.convertCurrency({
30
+ var C, N;
31
+ const { user: o } = O(), n = ((C = o == null ? void 0 : o.preferences) == null ? void 0 : C.currency) ?? ((N = o == null ? void 0 : o.userRegion) == null ? void 0 : N.currency), c = n !== e, { data: a, isPending: m } = _({
32
+ queryKey: [T.CONVERT_CURRENCY, e, n],
33
+ queryFn: () => x.convertCurrency({
33
34
  baseCurrency: e,
34
35
  targetCurrency: n
35
36
  }),
36
- enabled: s && !!e && !!i,
37
- staleTime: x
38
- }), a = T(() => {
37
+ enabled: c && !!e && !!i,
38
+ staleTime: Y
39
+ }), p = I(() => {
39
40
  if (!o)
40
41
  return null;
41
- let u = typeof i == "string" ? parseFloat(i) : i;
42
- if (s) {
43
- if (d || !c) return null;
44
- u = u * c;
42
+ let h = typeof i == "string" ? parseFloat(i) : i;
43
+ if (c) {
44
+ if (m || !a) return null;
45
+ h = h * a;
45
46
  }
46
- return u;
47
- }, [i, o, d, s, c]);
48
- if (E)
49
- return /* @__PURE__ */ r("span", { className: "currency-conversion", children: m(i, e, p) });
50
- if (d && s)
47
+ return h;
48
+ }, [i, o, m, c, a]);
49
+ if (R)
50
+ return /* @__PURE__ */ r("span", { className: "currency-conversion", children: u(
51
+ i,
52
+ e,
53
+ s,
54
+ d
55
+ ) });
56
+ if (m && c)
51
57
  return /* @__PURE__ */ r("span", { className: "currency-conversion loading", children: i });
52
- if (!n || !a || a < 0)
53
- switch (A) {
58
+ if (!n || !p || p < 0)
59
+ switch (y) {
54
60
  case t.NA:
55
61
  return /* @__PURE__ */ r("span", { children: "N/A" });
56
62
  case t.HIDDEN:
@@ -58,25 +64,26 @@ const x = 1e3 * 60 * 60, k = ({
58
64
  case t.DISPLAY_AS_ZERO:
59
65
  return /* @__PURE__ */ r("span", { children: "0" });
60
66
  case t.DISPLAY_AS_ZERO_WITH_CURRENCY:
61
- return /* @__PURE__ */ r("span", { children: N(0, n ?? e) });
67
+ return /* @__PURE__ */ r("span", { children: f(0, n ?? e) });
62
68
  case t.DISPLAY_AS_ZERO_WITH_CURRENCY_NO_DECIMAL:
63
- return /* @__PURE__ */ r("span", { children: _(0, n ?? e) });
69
+ return /* @__PURE__ */ r("span", { children: S(0, n ?? e) });
64
70
  case t.CUSTOM:
65
- return /* @__PURE__ */ r("span", { children: a == 0 ? y : "N/A" });
71
+ return /* @__PURE__ */ r("span", { children: p == 0 ? g : "N/A" });
66
72
  default:
67
73
  return /* @__PURE__ */ r("span", { children: "N/A" });
68
74
  }
69
75
  return /* @__PURE__ */ l("span", { className: "currency-conversion", children: [
70
- m(
71
- a,
76
+ u(
77
+ p,
72
78
  n,
73
- p
79
+ s,
80
+ d
74
81
  ),
75
- s && g && /* @__PURE__ */ r(
76
- O,
82
+ c && E && /* @__PURE__ */ r(
83
+ D,
77
84
  {
78
- trigger: /* @__PURE__ */ r("sup", { children: /* @__PURE__ */ r(f, {}) }),
79
- position: v,
85
+ trigger: /* @__PURE__ */ r("sup", { children: /* @__PURE__ */ r(v, {}) }),
86
+ position: A,
80
87
  children: /* @__PURE__ */ l("div", { className: "currency-conversion-container", children: [
81
88
  /* @__PURE__ */ l("p", { children: [
82
89
  "Converted from ",
@@ -85,26 +92,32 @@ const x = 1e3 * 60 * 60, k = ({
85
92
  n
86
93
  ] }),
87
94
  /* @__PURE__ */ l("div", { className: "currency-conversion-amounts", children: [
88
- /* @__PURE__ */ r("div", { children: /* @__PURE__ */ r("p", { children: m(i, e, p) }) }),
89
- /* @__PURE__ */ r("div", { children: /* @__PURE__ */ r("p", { children: m(
90
- a,
95
+ /* @__PURE__ */ r("div", { children: /* @__PURE__ */ r("p", { children: u(
96
+ i,
97
+ e,
98
+ s,
99
+ d
100
+ ) }) }),
101
+ /* @__PURE__ */ r("div", { children: /* @__PURE__ */ r("p", { children: u(
102
+ p,
91
103
  n,
92
- p
104
+ s,
105
+ d
93
106
  ) }) }),
94
- /* @__PURE__ */ r("span", { className: "conversion-icon", children: /* @__PURE__ */ r(f, {}) })
107
+ /* @__PURE__ */ r("span", { className: "conversion-icon", children: /* @__PURE__ */ r(v, {}) })
95
108
  ] }),
96
109
  /* @__PURE__ */ r("div", { className: "currency-conversion-rate", children: /* @__PURE__ */ l("p", { children: [
97
110
  "Current Rate:",
98
111
  " ",
99
- c ? (
112
+ a ? (
100
113
  // only leaving 2 decimal places for the conversion rate is
101
114
  // not enough, can lead to confusion
102
115
  // use Number constructor to strip unnecessary trailing zeros
103
- `${Number((1 / c).toFixed(5))} ${e}`
116
+ `${Number((1 / a).toFixed(5))} ${e}`
104
117
  ) : "N/A",
105
118
  " ",
106
119
  "≈ ",
107
- N(1, n)
120
+ f(1, n)
108
121
  ] }) })
109
122
  ] })
110
123
  }
@@ -112,6 +125,6 @@ const x = 1e3 * 60 * 60, k = ({
112
125
  ] });
113
126
  };
114
127
  export {
115
- k as CashValue,
116
- x as CurrencyCallStaleTimeMs
128
+ J as CashValue,
129
+ Y as CurrencyCallStaleTimeMs
117
130
  };
@@ -1,4 +1,4 @@
1
- import { c as P } from "../../cashUtils-Dlce3Uj_.js";
1
+ import { c as P } from "../../cashUtils-DyxlHnod.js";
2
2
  import "../../arrayExtensions-DlcBOj5a.js";
3
3
  import { e as M, A as m, E as N } from "../../noRetryInstance-DNLgOg0E.js";
4
4
  import { a as i } from "../../keys-BcBfU51M.js";
@@ -1,84 +1,88 @@
1
- import { useQuery as n, useMutation as s } from "@tanstack/react-query";
1
+ import { useQuery as s, useMutation as i } from "@tanstack/react-query";
2
2
  import "react/jsx-runtime";
3
3
  import "../../arrayExtensions-DlcBOj5a.js";
4
- import { E as a, d as u } from "../../noRetryInstance-DNLgOg0E.js";
4
+ import { E as a, d as l } from "../../noRetryInstance-DNLgOg0E.js";
5
5
  import "react";
6
6
  import "react-i18next";
7
7
  import '../../assets/_styles4.css';import '../../assets/_styles6.css';import '../../assets/_styles5.css';import '../../assets/_styles2.css';import '../../assets/_styles.css';import '../../assets/_styles3.css';/* empty css */
8
8
  /* empty css */
9
9
  /* empty css */
10
- import { awayzClient as i } from "../../configs/awayzClient.js";
10
+ import { awayzClient as d } from "../../configs/awayzClient.js";
11
11
  /* empty css */
12
12
  /* empty css */
13
13
  import "../../index-Cv-wvFlM.js";
14
- import { useAwayzContext as c } from "../useAwayzContext.js";
14
+ import { useAwayzContext as h } from "../useAwayzContext.js";
15
15
  /* empty css */
16
16
  import "../../context/AwayzContext.js";
17
- import { WalletService as o } from "../../services/wallet/WalletService.js";
17
+ import { WalletService as n } from "../../services/wallet/WalletService.js";
18
18
  const U = {
19
19
  availablePoints: 0,
20
20
  valuePerPoint: 0,
21
21
  currency: ""
22
22
  }, z = () => {
23
- const { user: r } = c(), { data: t } = n({
23
+ const { user: r, featureFlags: c, featureFlagsLoaded: y, isAuthenticated: o } = h(), { data: t = [] } = s({
24
24
  queryKey: [a.PROGRAMS],
25
- queryFn: o.getAwards,
26
- placeholderData: []
27
- }), { data: l } = n({
25
+ queryFn: n.getAwards,
26
+ placeholderData: [],
27
+ enabled: o
28
+ }), { data: A = [] } = s({
28
29
  queryKey: [a.USER_PROGRAMS, r == null ? void 0 : r.id],
29
- queryFn: () => r != null && r.id ? o.getUserAwards(r.id) : [],
30
+ queryFn: () => r != null && r.id ? n.getUserAwards(r.id) : [],
30
31
  placeholderData: [],
31
- enabled: !!(r != null && r.id)
32
- }), { data: y } = n({
32
+ enabled: o
33
+ }), { data: S = [] } = s({
33
34
  queryKey: [a.LINKED_USER_PROGRAMS, r == null ? void 0 : r.id],
34
- queryFn: () => r != null && r.id ? o.getLinkedUserAwards(r.id) : [],
35
+ queryFn: () => r != null && r.id ? n.getLinkedUserAwards(r.id) : [],
35
36
  placeholderData: [],
36
- enabled: !!(r != null && r.id)
37
- }), { data: A } = n({
37
+ enabled: o
38
+ }), { data: g = [] } = s({
38
39
  queryKey: [a.BANKS],
39
- queryFn: o.getBanks,
40
- placeholderData: []
41
- }), { data: S } = n({
40
+ queryFn: n.getBanks,
41
+ placeholderData: [],
42
+ enabled: o
43
+ }), { data: P = [] } = s({
42
44
  queryKey: [a.CARDS],
43
- queryFn: o.getCards,
44
- placeholderData: []
45
- }), { data: g } = n({
45
+ queryFn: n.getCards,
46
+ placeholderData: [],
47
+ enabled: o
48
+ }), { data: R = [] } = s({
46
49
  queryKey: [a.USER_CARDS],
47
- queryFn: o.getUserCards,
48
- placeholderData: []
49
- }), { featureFlags: P, featureFlagsLoaded: R, isAuthenticated: p } = c(), {
50
- data: C = U,
51
- isFetching: E
52
- } = n({
50
+ queryFn: n.getUserCards,
51
+ placeholderData: [],
52
+ enabled: o
53
+ }), {
54
+ data: p = U,
55
+ isFetching: C
56
+ } = s({
53
57
  queryKey: [a.POINTS_AS_CASH],
54
- queryFn: o.getPointsAsCash,
55
- enabled: R && P.usePointsAsCashFeature && p,
58
+ queryFn: n.getPointsAsCash,
59
+ enabled: y && c.usePointsAsCashFeature && o,
56
60
  retry: !1
57
- }), { mutate: K } = s({
61
+ }), { mutate: E } = i({
58
62
  mutationFn: async (e) => {
59
- const { mainProgram: m, awardsAmount: d } = typeof e == "string" ? { mainProgram: e, awardsAmount: 0 } : e;
60
- await o.addAwardProgram(m, d);
63
+ const { mainProgram: m, awardsAmount: u } = typeof e == "string" ? { mainProgram: e, awardsAmount: 0 } : e;
64
+ await n.addAwardProgram(m, u);
61
65
  },
62
66
  onSuccess: () => {
63
- i.invalidateQueries({
67
+ d.invalidateQueries({
64
68
  queryKey: [a.LINKED_USER_PROGRAMS]
65
69
  });
66
70
  }
67
- }), { mutate: f } = s({
71
+ }), { mutate: K } = i({
68
72
  mutationFn: async (e) => {
69
- await o.removeAwardProgram(e);
73
+ await n.removeAwardProgram(e);
70
74
  },
71
75
  onSuccess: () => {
72
- i.invalidateQueries({
76
+ d.invalidateQueries({
73
77
  queryKey: [a.LINKED_USER_PROGRAMS]
74
78
  });
75
79
  }
76
- }), { mutateAsync: F } = s({
80
+ }), { mutateAsync: f } = i({
77
81
  mutationFn: async ({ mainProgram: e, awardsAmount: m }) => {
78
- const d = t == null ? void 0 : t.find((h) => h.mainProgram === e);
79
- if (!d)
82
+ const u = t == null ? void 0 : t.find((q) => q.mainProgram === e);
83
+ if (!u)
80
84
  throw new Error("Program not found");
81
- return o.setAwardPoints(d.mainProgram, m);
85
+ return n.setAwardPoints(u.mainProgram, m);
82
86
  },
83
87
  onSuccess: () => {
84
88
  [
@@ -86,20 +90,20 @@ const U = {
86
90
  a.USER_PROGRAMS,
87
91
  a.PROGRAMS
88
92
  ].forEach((e) => {
89
- i.invalidateQueries({ queryKey: [e] });
93
+ d.invalidateQueries({ queryKey: [e] });
90
94
  });
91
95
  }
92
- }), { mutateAsync: _ } = s({
93
- mutationFn: async (e) => o.addCardsToWallet(e),
96
+ }), { mutateAsync: F } = i({
97
+ mutationFn: async (e) => n.addCardsToWallet(e),
94
98
  onSuccess: () => {
95
- i.invalidateQueries({
99
+ d.invalidateQueries({
96
100
  queryKey: [a.USER_CARDS]
97
101
  });
98
102
  }
99
- }), { mutateAsync: q } = s({
100
- mutationFn: async (e) => o.removeCardsFromWallet(e),
103
+ }), { mutateAsync: _ } = i({
104
+ mutationFn: async (e) => n.removeCardsFromWallet(e),
101
105
  onSuccess: () => {
102
- i.invalidateQueries({
106
+ d.invalidateQueries({
103
107
  queryKey: [a.USER_CARDS]
104
108
  });
105
109
  }
@@ -107,28 +111,28 @@ const U = {
107
111
  return {
108
112
  // Program Management
109
113
  allPrograms: t || [],
110
- userPrograms: l || [],
111
- linkedUserPrograms: y || [],
114
+ userPrograms: A || [],
115
+ linkedUserPrograms: S || [],
112
116
  hotelPrograms: (t == null ? void 0 : t.filter(
113
- (e) => e.category.includes(u.HOTEL)
117
+ (e) => e.category.includes(l.HOTEL)
114
118
  )) || [],
115
119
  airlinePrograms: (t == null ? void 0 : t.filter(
116
- (e) => e.category.includes(u.AIRLINE)
120
+ (e) => e.category.includes(l.AIRLINE)
117
121
  )) || [],
118
122
  bankPrograms: (t == null ? void 0 : t.filter(
119
- (e) => e.category.includes(u.BANK)
123
+ (e) => e.category.includes(l.BANK)
120
124
  )) || [],
121
- updatePoints: F,
122
- addAwardProgram: K,
123
- removeAwardProgram: f,
125
+ updatePoints: f,
126
+ addAwardProgram: E,
127
+ removeAwardProgram: K,
124
128
  // Card Management
125
- banks: A || [],
126
- allCards: S || [],
127
- userCards: g || [],
128
- addCards: _,
129
- removeCards: q,
130
- pointsAsCash: C,
131
- pointsAsCashLoading: E
129
+ banks: g || [],
130
+ allCards: P || [],
131
+ userCards: R || [],
132
+ addCards: F,
133
+ removeCards: _,
134
+ pointsAsCash: p,
135
+ pointsAsCashLoading: C
132
136
  };
133
137
  };
134
138
  export {
@@ -30,9 +30,15 @@ export interface ICashValueProps {
30
30
  */
31
31
  customDisplay?: string;
32
32
  /**
33
- * Number of decimal places to display. Defaults to 0.
33
+ * Maximum number of decimal places to display. Defaults to 0.
34
34
  */
35
35
  decimalPlaces?: number;
36
+ /**
37
+ * Minimum number of decimal places to display. Defaults to `decimalPlaces`.
38
+ * Useful when you want to pad small values (e.g. 0 → "0.00") while still
39
+ * allowing more precision when the value has it (e.g. 0.1245 → "0.1245").
40
+ */
41
+ minDecimalPlaces?: number;
36
42
  /**
37
43
  * Whether to show the conversion tooltip.
38
44
  * Defaults to true, but can be set to false to hide it.
@@ -51,4 +57,4 @@ export declare const CurrencyCallStaleTimeMs: number;
51
57
  * If the original currency differs from the user's currency, it shows a conversion
52
58
  * tooltip with details about the conversion rate and original amount.
53
59
  */
54
- export declare const CashValue: ({ amount, currency, position, zeroDisplayOption, customDisplay, decimalPlaces, showConversion, showOriginal }: ICashValueProps) => import("react/jsx-runtime").JSX.Element;
60
+ export declare const CashValue: ({ amount, currency, position, zeroDisplayOption, customDisplay, decimalPlaces, minDecimalPlaces, showConversion, showOriginal }: ICashValueProps) => import("react/jsx-runtime").JSX.Element;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@odynn/awayz-core",
3
- "version": "0.10.23",
3
+ "version": "0.10.26",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
@@ -1,40 +0,0 @@
1
- import { jsxs as i, Fragment as c, jsx as m } from "react/jsx-runtime";
2
- const a = "USD", g = (r, t) => {
3
- const e = t || a, n = new Intl.NumberFormat("en-US");
4
- if (!r) return `${n.format(0)}${e}`;
5
- const o = parseFloat(r.toString());
6
- return /* @__PURE__ */ i(c, { children: [
7
- n.format(isNaN(o) ? 0 : o),
8
- " ",
9
- /* @__PURE__ */ m("sub", { children: e })
10
- ] });
11
- }, l = (r, t) => {
12
- const e = t || a, n = new Intl.NumberFormat("en-US", {
13
- maximumFractionDigits: 0
14
- });
15
- return /* @__PURE__ */ i(c, { children: [
16
- n.format(isNaN(r) ? 0 : r),
17
- " ",
18
- /* @__PURE__ */ m("sub", { children: e })
19
- ] });
20
- }, y = (r, t, e = 0) => {
21
- const n = parseFloat((r == null ? void 0 : r.toString()) || "0"), o = t || a, s = new Intl.NumberFormat("en-US", {
22
- maximumFractionDigits: e
23
- });
24
- return /* @__PURE__ */ i(c, { children: [
25
- s.format(isNaN(n) ? 0 : n),
26
- " ",
27
- /* @__PURE__ */ m("sub", { children: o })
28
- ] });
29
- }, F = (r, t = "en") => 0 .toLocaleString(t, {
30
- style: "currency",
31
- currency: r,
32
- minimumFractionDigits: 0,
33
- maximumFractionDigits: 0
34
- }).replace(/\d/g, "").trim();
35
- export {
36
- l as a,
37
- g as b,
38
- F as c,
39
- y as g
40
- };