@odynn/awayz-core 0.9.29 → 0.9.31

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,34 @@
1
+ import { D as o } from "./index-BlYZu1Ej.js";
2
+ const c = (r, t) => {
3
+ var e = new Intl.NumberFormat("en-US", {
4
+ style: "currency",
5
+ currency: t ?? o
6
+ });
7
+ if (!r) return e.format(0);
8
+ const n = parseFloat(r.toString());
9
+ return e.format(n);
10
+ }, i = (r, t) => {
11
+ var e = new Intl.NumberFormat("en-US", {
12
+ style: "currency",
13
+ currency: t ?? o
14
+ });
15
+ return e.format(Math.round(r)).toString().split(".")[0];
16
+ }, u = (r, t, e = 0) => {
17
+ const n = parseFloat((r == null ? void 0 : r.toString()) || "0");
18
+ return new Intl.NumberFormat("en-US", {
19
+ style: "currency",
20
+ currency: t ?? o,
21
+ maximumFractionDigits: e
22
+ }).format(isNaN(n) ? 0 : n);
23
+ }, y = (r, t = "en") => 0 .toLocaleString(t, {
24
+ style: "currency",
25
+ currency: r,
26
+ minimumFractionDigits: 0,
27
+ maximumFractionDigits: 0
28
+ }).replace(/\d/g, "").trim();
29
+ export {
30
+ i as a,
31
+ c as b,
32
+ y as c,
33
+ u as g
34
+ };
@@ -1,107 +1,106 @@
1
- import { jsx as e, jsxs as p } from "react/jsx-runtime";
2
- import { useQuery as R } from "@tanstack/react-query";
1
+ import { jsx as r, jsxs as l } from "react/jsx-runtime";
2
+ import { useQuery as E } from "@tanstack/react-query";
3
3
  import "../../arrayExtensions-DlcBOj5a.js";
4
- import { E as g, g as _, a as C, b as u } from "../../cashUtils-CrBZrS6N.js";
5
- import { E as S } from "../../noRetryInstance-DKhe8ju0.js";
6
- import { useMemo as T } from "react";
4
+ import { g as m, a as R, b as C } from "../../cashUtils-DB_r0g-F.js";
5
+ import { E as _ } from "../../noRetryInstance-DKhe8ju0.js";
6
+ import { useMemo as S } from "react";
7
7
  import { a as N } from "../../index-C8p5kinH.js";
8
8
  import "react-i18next";
9
9
  import '../../assets/_styles3.css';import '../../assets/_styles.css';import '../../assets/_styles2.css';/* empty css */
10
10
  import "../../_styles.flight-booking-CaUgKcMC.js";
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 o, EToolTipPosition as T } from "./CashValueTypes.js";
13
+ import { useAwayzContext as D } from "../../hooks/useAwayzContext.js";
14
14
  import "../../configs/awayzClient.js";
15
15
  /* empty css */
16
16
  import "../../context/AwayzContext.js";
17
- import { CurrencyService as x } from "../../services/currency/CurrencyService.js";
17
+ import { CurrencyService as I } from "../../services/currency/CurrencyService.js";
18
18
  import { Tooltip as M } from "../Tooltip/Tooltip.js";
19
- const O = 1e3 * 60 * 60, B = ({
19
+ const O = 1e3 * 60 * 60, G = ({
20
20
  amount: i,
21
- currency: r,
22
- position: f = D.RIGHT,
23
- zeroDisplayOption: A = t.NA,
24
- customDisplay: E,
25
- decimalPlaces: m = 2,
26
- showConversion: v = !1,
27
- addBuffer: y = !0
21
+ currency: e,
22
+ position: f = T.RIGHT,
23
+ zeroDisplayOption: v = o.NA,
24
+ customDisplay: A,
25
+ decimalPlaces: p = 2,
26
+ showConversion: y = !1,
27
+ showOriginal: g = !1
28
28
  }) => {
29
29
  var h;
30
- const { user: s } = I(), n = ((h = s == null ? void 0 : s.preferences) == null ? void 0 : h.currency) ?? r, a = n !== r, { data: c, isPending: d } = R({
31
- queryKey: [S.CONVERT_CURRENCY, r, n],
32
- queryFn: async () => {
33
- const o = await x.convertCurrency({
34
- baseCurrency: r,
35
- targetCurrency: n
36
- });
37
- return y ? o * (1 + g) : o;
38
- },
39
- enabled: a && !!r && !!i,
30
+ const { user: s } = D(), n = ((h = s == null ? void 0 : s.preferences) == null ? void 0 : h.currency) ?? e, t = n !== e, { data: c, isPending: d } = E({
31
+ queryKey: [_.CONVERT_CURRENCY, e, n],
32
+ queryFn: () => I.convertCurrency({
33
+ baseCurrency: e,
34
+ targetCurrency: n
35
+ }),
36
+ enabled: t && !!e && !!i,
40
37
  staleTime: O
41
- }), l = T(() => {
38
+ }), a = S(() => {
42
39
  if (!s)
43
40
  return null;
44
- let o = typeof i == "string" ? parseFloat(i) : i;
45
- if (a) {
41
+ let u = typeof i == "string" ? parseFloat(i) : i;
42
+ if (t) {
46
43
  if (d || !c) return null;
47
- o = o * c;
44
+ u = u * c;
48
45
  }
49
- return o;
50
- }, [i, s, d, a, c]);
51
- if (d && a)
52
- return /* @__PURE__ */ e("span", { className: "currency-conversion loading", children: i });
53
- if (!n || !l || l < 0)
54
- switch (A) {
55
- case t.NA:
56
- return /* @__PURE__ */ e("span", { children: "N/A" });
57
- case t.HIDDEN:
58
- return /* @__PURE__ */ e("span", { className: "hidden", children: "N/A" });
59
- case t.DISPLAY_AS_ZERO:
60
- return /* @__PURE__ */ e("span", { children: "0" });
61
- case t.DISPLAY_AS_ZERO_WITH_CURRENCY:
62
- return /* @__PURE__ */ e("span", { children: C(0, n ?? r) });
63
- case t.DISPLAY_AS_ZERO_WITH_CURRENCY_NO_DECIMAL:
64
- return /* @__PURE__ */ e("span", { children: _(0, n ?? r) });
65
- case t.CUSTOM:
66
- return /* @__PURE__ */ e("span", { children: l == 0 ? E : "N/A" });
46
+ return u;
47
+ }, [i, s, d, t, c]);
48
+ if (g)
49
+ return /* @__PURE__ */ r("span", { className: "currency-conversion", children: m(i, e, p) });
50
+ if (d && t)
51
+ return /* @__PURE__ */ r("span", { className: "currency-conversion loading", children: i });
52
+ if (!n || !a || a < 0)
53
+ switch (v) {
54
+ case o.NA:
55
+ return /* @__PURE__ */ r("span", { children: "N/A" });
56
+ case o.HIDDEN:
57
+ return /* @__PURE__ */ r("span", { className: "hidden", children: "N/A" });
58
+ case o.DISPLAY_AS_ZERO:
59
+ return /* @__PURE__ */ r("span", { children: "0" });
60
+ case o.DISPLAY_AS_ZERO_WITH_CURRENCY:
61
+ return /* @__PURE__ */ r("span", { children: C(0, n ?? e) });
62
+ case o.DISPLAY_AS_ZERO_WITH_CURRENCY_NO_DECIMAL:
63
+ return /* @__PURE__ */ r("span", { children: R(0, n ?? e) });
64
+ case o.CUSTOM:
65
+ return /* @__PURE__ */ r("span", { children: a == 0 ? A : "N/A" });
67
66
  default:
68
- return /* @__PURE__ */ e("span", { children: "N/A" });
67
+ return /* @__PURE__ */ r("span", { children: "N/A" });
69
68
  }
70
- return /* @__PURE__ */ p("span", { className: "currency-conversion", children: [
71
- u(
72
- l,
69
+ return /* @__PURE__ */ l("span", { className: "currency-conversion", children: [
70
+ m(
71
+ a,
73
72
  n,
74
- m
73
+ p
75
74
  ),
76
- a && v && /* @__PURE__ */ e(
75
+ t && y && /* @__PURE__ */ r(
77
76
  M,
78
77
  {
79
- trigger: /* @__PURE__ */ e("sup", { children: /* @__PURE__ */ e(N, {}) }),
78
+ trigger: /* @__PURE__ */ r("sup", { children: /* @__PURE__ */ r(N, {}) }),
80
79
  position: f,
81
- children: /* @__PURE__ */ p("div", { className: "currency-conversion-container", children: [
82
- /* @__PURE__ */ p("p", { children: [
80
+ children: /* @__PURE__ */ l("div", { className: "currency-conversion-container", children: [
81
+ /* @__PURE__ */ l("p", { children: [
83
82
  "Converted from ",
84
- r,
83
+ e,
85
84
  " to ",
86
85
  n
87
86
  ] }),
88
- /* @__PURE__ */ p("div", { className: "currency-conversion-amounts", children: [
89
- /* @__PURE__ */ e("div", { children: /* @__PURE__ */ e("p", { children: u(i, r, m) }) }),
90
- /* @__PURE__ */ e("div", { children: /* @__PURE__ */ e("p", { children: u(
91
- l,
87
+ /* @__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,
92
91
  n,
93
- m
92
+ p
94
93
  ) }) }),
95
- /* @__PURE__ */ e("span", { className: "conversion-icon", children: /* @__PURE__ */ e(N, {}) })
94
+ /* @__PURE__ */ r("span", { className: "conversion-icon", children: /* @__PURE__ */ r(N, {}) })
96
95
  ] }),
97
- /* @__PURE__ */ e("div", { className: "currency-conversion-rate", children: /* @__PURE__ */ p("p", { children: [
96
+ /* @__PURE__ */ r("div", { className: "currency-conversion-rate", children: /* @__PURE__ */ l("p", { children: [
98
97
  "Current Rate:",
99
98
  " ",
100
99
  c ? (
101
100
  // only leaving 2 decimal places for the conversion rate is
102
101
  // not enough, can lead to confusion
103
102
  // use Number constructor to strip unnecessary trailing zeros
104
- `${Number((1 / c).toFixed(5))} ${r}`
103
+ `${Number((1 / c).toFixed(5))} ${e}`
105
104
  ) : "N/A",
106
105
  " ",
107
106
  "≈ ",
@@ -113,6 +112,6 @@ const O = 1e3 * 60 * 60, B = ({
113
112
  ] });
114
113
  };
115
114
  export {
116
- B as CashValue,
115
+ G as CashValue,
117
116
  O as CurrencyCallStaleTimeMs
118
117
  };
@@ -1,5 +1,5 @@
1
1
  import "../../arrayExtensions-DlcBOj5a.js";
2
- import { c as M } from "../../cashUtils-CrBZrS6N.js";
2
+ import { c as M } from "../../cashUtils-DB_r0g-F.js";
3
3
  import { e as P, A as l, E as N } from "../../noRetryInstance-DKhe8ju0.js";
4
4
  import { a as o } from "../../_styles.flight-booking-CaUgKcMC.js";
5
5
  import { useState as f, useCallback as I, useEffect as h } from "react";
@@ -0,0 +1,5 @@
1
+ const E = "USD", s = 0.03;
2
+ export {
3
+ E as D,
4
+ s as E
5
+ };
@@ -38,7 +38,10 @@ export interface ICashValueProps {
38
38
  * Defaults to true, but can be set to false to hide it.
39
39
  */
40
40
  showConversion?: boolean;
41
- addBuffer?: boolean;
41
+ /**
42
+ * Whether to show the original amount and currency
43
+ */
44
+ showOriginal?: boolean;
42
45
  }
43
46
  export declare const CurrencyCallStaleTimeMs: number;
44
47
  /**
@@ -48,4 +51,4 @@ export declare const CurrencyCallStaleTimeMs: number;
48
51
  * If the original currency differs from the user's currency, it shows a conversion
49
52
  * tooltip with details about the conversion rate and original amount.
50
53
  */
51
- export declare const CashValue: ({ amount, currency, position, zeroDisplayOption, customDisplay, decimalPlaces, showConversion, addBuffer }: ICashValueProps) => import("react/jsx-runtime").JSX.Element;
54
+ export declare const CashValue: ({ amount, currency, position, zeroDisplayOption, customDisplay, decimalPlaces, showConversion, showOriginal }: ICashValueProps) => import("react/jsx-runtime").JSX.Element;
@@ -2,7 +2,7 @@ import { StoryObj } from '@storybook/react';
2
2
  import { EInvalidAmountDisplayOption, EToolTipPosition } from './CashValueTypes';
3
3
  declare const meta: {
4
4
  title: string;
5
- component: ({ amount, currency, position, zeroDisplayOption, customDisplay, decimalPlaces, showConversion, addBuffer }: import('./CashValue').ICashValueProps) => import("react/jsx-runtime").JSX.Element;
5
+ component: ({ amount, currency, position, zeroDisplayOption, customDisplay, decimalPlaces, showConversion, showOriginal }: import('./CashValue').ICashValueProps) => import("react/jsx-runtime").JSX.Element;
6
6
  parameters: {
7
7
  layout: string;
8
8
  };
@@ -2,7 +2,8 @@ import '../../assets/_styles3.css';import '../../assets/_styles5.css';import '..
2
2
  var m = (t, r, e) => r in t ? y(t, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[r] = e;
3
3
  var n = (t, r, e) => m(t, typeof r != "symbol" ? r + "" : r, e);
4
4
  import "../../arrayExtensions-DlcBOj5a.js";
5
- import { A as C, E, c as s } from "../../noRetryInstance-DKhe8ju0.js";
5
+ import { E } from "../../index-BlYZu1Ej.js";
6
+ import { A as C, E as _, c as s } from "../../noRetryInstance-DKhe8ju0.js";
6
7
  import "react";
7
8
  import { ECurrencyEndpoints as i } from "../../configs/endpoints.js";
8
9
  import "react/jsx-runtime";
@@ -16,7 +17,7 @@ import "@tanstack/react-query";
16
17
  import "../../index-Cv-wvFlM.js";
17
18
  import "../../context/AwayzContext.js";
18
19
  /* empty css */
19
- import { awayzClient as _ } from "../../configs/awayzClient.js";
20
+ import { awayzClient as R } from "../../configs/awayzClient.js";
20
21
  class d {
21
22
  constructor() {
22
23
  n(this, "convertCurrency", async ({
@@ -24,20 +25,20 @@ class d {
24
25
  targetCurrency: e
25
26
  }) => {
26
27
  try {
27
- const { success: c, data: o } = await _.ensureQueryData({
28
- queryKey: [E.CHECK_USER],
28
+ const { success: o, data: c } = await R.ensureQueryData({
29
+ queryKey: [_.CHECK_USER],
29
30
  queryFn: C.checkUser
30
31
  });
31
- if (!c)
32
+ if (!o)
32
33
  throw new Error("Failed to fetch user data");
33
- const { userRegion: u, preferences: p } = o, { data: a } = await s.post(i.CURRENCY_CONVERSION, {
34
+ const { userRegion: u, preferences: p } = c, { data: a } = await s.post(i.CURRENCY_CONVERSION, {
34
35
  target_currency: e ?? p.currency ?? u.currency,
35
36
  base_currency: r
36
37
  });
37
- if (c && a.data)
38
- return a.data.conversion_rate;
39
- } catch (c) {
40
- console.error(c);
38
+ if (o && a.data)
39
+ return a.data.conversion_rate * (1 + E);
40
+ } catch (o) {
41
+ console.error(o);
41
42
  }
42
43
  return 0;
43
44
  });
@@ -52,18 +53,18 @@ class d {
52
53
  n(this, "convertToCurrency", async ({
53
54
  baseCurrency: r,
54
55
  targetCurrency: e,
55
- amount: c
56
+ amount: o
56
57
  }) => {
57
58
  try {
58
- const { data: o } = await s.post(i.CURRENCY_CONVERSION, {
59
+ const { data: c } = await s.post(i.CURRENCY_CONVERSION, {
59
60
  target_currency: e,
60
61
  base_currency: r,
61
- amount: c
62
+ amount: o
62
63
  });
63
- if (o.success)
64
- return o.data.conversion_result;
65
- } catch (o) {
66
- console.error(o);
64
+ if (c.success)
65
+ return c.data.conversion_result;
66
+ } catch (c) {
67
+ console.error(c);
67
68
  }
68
69
  return 0;
69
70
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@odynn/awayz-core",
3
- "version": "0.9.29",
3
+ "version": "0.9.31",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
@@ -1,34 +0,0 @@
1
- const o = "USD", a = 0.03, m = (r, t) => {
2
- var n = new Intl.NumberFormat("en-US", {
3
- style: "currency",
4
- currency: t ?? o
5
- });
6
- if (!r) return n.format(0);
7
- const e = parseFloat(r.toString());
8
- return n.format(e);
9
- }, i = (r, t) => {
10
- var n = new Intl.NumberFormat("en-US", {
11
- style: "currency",
12
- currency: t ?? o
13
- });
14
- return n.format(Math.round(r)).toString().split(".")[0];
15
- }, u = (r, t, n = 0) => {
16
- const e = parseFloat((r == null ? void 0 : r.toString()) || "0");
17
- return new Intl.NumberFormat("en-US", {
18
- style: "currency",
19
- currency: t ?? o,
20
- maximumFractionDigits: n
21
- }).format(isNaN(e) ? 0 : e);
22
- }, s = (r, t = "en") => 0 .toLocaleString(t, {
23
- style: "currency",
24
- currency: r,
25
- minimumFractionDigits: 0,
26
- maximumFractionDigits: 0
27
- }).replace(/\d/g, "").trim();
28
- export {
29
- a as E,
30
- m as a,
31
- u as b,
32
- s as c,
33
- i as g
34
- };