@odynn/awayz-core 0.9.29 → 0.9.30

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
+ c as a,
31
+ u as b,
32
+ y as c,
33
+ i as g
34
+ };
@@ -1,100 +1,96 @@
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 e, jsxs as l } from "react/jsx-runtime";
2
+ import { useQuery as g } 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 E, a as C, b as u } from "../../cashUtils-DJFSvWw5.js";
5
+ import { E as R } from "../../noRetryInstance-DKhe8ju0.js";
6
+ import { useMemo as _ } 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 S } from "./CashValueTypes.js";
13
+ import { useAwayzContext as T } 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";
18
- import { Tooltip as M } from "../Tooltip/Tooltip.js";
19
- const O = 1e3 * 60 * 60, B = ({
17
+ import { CurrencyService as D } from "../../services/currency/CurrencyService.js";
18
+ import { Tooltip as I } from "../Tooltip/Tooltip.js";
19
+ const M = 1e3 * 60 * 60, z = ({
20
20
  amount: i,
21
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
22
+ position: f = S.RIGHT,
23
+ zeroDisplayOption: A = o.NA,
24
+ customDisplay: v,
25
+ decimalPlaces: p = 2,
26
+ showConversion: y = !1
28
27
  }) => {
29
28
  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,
40
- staleTime: O
41
- }), l = T(() => {
42
- if (!s)
29
+ const { user: t } = T(), n = ((h = t == null ? void 0 : t.preferences) == null ? void 0 : h.currency) ?? r, s = n !== r, { data: c, isPending: m } = g({
30
+ queryKey: [R.CONVERT_CURRENCY, r, n],
31
+ queryFn: () => D.convertCurrency({
32
+ baseCurrency: r,
33
+ targetCurrency: n
34
+ }),
35
+ enabled: s && !!r && !!i,
36
+ staleTime: M
37
+ }), a = _(() => {
38
+ if (!t)
43
39
  return null;
44
- let o = typeof i == "string" ? parseFloat(i) : i;
45
- if (a) {
46
- if (d || !c) return null;
47
- o = o * c;
40
+ let d = typeof i == "string" ? parseFloat(i) : i;
41
+ if (s) {
42
+ if (m || !c) return null;
43
+ d = d * c;
48
44
  }
49
- return o;
50
- }, [i, s, d, a, c]);
51
- if (d && a)
45
+ return d;
46
+ }, [i, t, m, s, c]);
47
+ if (m && s)
52
48
  return /* @__PURE__ */ e("span", { className: "currency-conversion loading", children: i });
53
- if (!n || !l || l < 0)
49
+ if (!n || !a || a < 0)
54
50
  switch (A) {
55
- case t.NA:
51
+ case o.NA:
56
52
  return /* @__PURE__ */ e("span", { children: "N/A" });
57
- case t.HIDDEN:
53
+ case o.HIDDEN:
58
54
  return /* @__PURE__ */ e("span", { className: "hidden", children: "N/A" });
59
- case t.DISPLAY_AS_ZERO:
55
+ case o.DISPLAY_AS_ZERO:
60
56
  return /* @__PURE__ */ e("span", { children: "0" });
61
- case t.DISPLAY_AS_ZERO_WITH_CURRENCY:
57
+ case o.DISPLAY_AS_ZERO_WITH_CURRENCY:
62
58
  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" });
59
+ case o.DISPLAY_AS_ZERO_WITH_CURRENCY_NO_DECIMAL:
60
+ return /* @__PURE__ */ e("span", { children: E(0, n ?? r) });
61
+ case o.CUSTOM:
62
+ return /* @__PURE__ */ e("span", { children: a == 0 ? v : "N/A" });
67
63
  default:
68
64
  return /* @__PURE__ */ e("span", { children: "N/A" });
69
65
  }
70
- return /* @__PURE__ */ p("span", { className: "currency-conversion", children: [
66
+ return /* @__PURE__ */ l("span", { className: "currency-conversion", children: [
71
67
  u(
72
- l,
68
+ a,
73
69
  n,
74
- m
70
+ p
75
71
  ),
76
- a && v && /* @__PURE__ */ e(
77
- M,
72
+ s && y && /* @__PURE__ */ e(
73
+ I,
78
74
  {
79
75
  trigger: /* @__PURE__ */ e("sup", { children: /* @__PURE__ */ e(N, {}) }),
80
76
  position: f,
81
- children: /* @__PURE__ */ p("div", { className: "currency-conversion-container", children: [
82
- /* @__PURE__ */ p("p", { children: [
77
+ children: /* @__PURE__ */ l("div", { className: "currency-conversion-container", children: [
78
+ /* @__PURE__ */ l("p", { children: [
83
79
  "Converted from ",
84
80
  r,
85
81
  " to ",
86
82
  n
87
83
  ] }),
88
- /* @__PURE__ */ p("div", { className: "currency-conversion-amounts", children: [
89
- /* @__PURE__ */ e("div", { children: /* @__PURE__ */ e("p", { children: u(i, r, m) }) }),
84
+ /* @__PURE__ */ l("div", { className: "currency-conversion-amounts", children: [
85
+ /* @__PURE__ */ e("div", { children: /* @__PURE__ */ e("p", { children: u(i, r, p) }) }),
90
86
  /* @__PURE__ */ e("div", { children: /* @__PURE__ */ e("p", { children: u(
91
- l,
87
+ a,
92
88
  n,
93
- m
89
+ p
94
90
  ) }) }),
95
91
  /* @__PURE__ */ e("span", { className: "conversion-icon", children: /* @__PURE__ */ e(N, {}) })
96
92
  ] }),
97
- /* @__PURE__ */ e("div", { className: "currency-conversion-rate", children: /* @__PURE__ */ p("p", { children: [
93
+ /* @__PURE__ */ e("div", { className: "currency-conversion-rate", children: /* @__PURE__ */ l("p", { children: [
98
94
  "Current Rate:",
99
95
  " ",
100
96
  c ? (
@@ -113,6 +109,6 @@ const O = 1e3 * 60 * 60, B = ({
113
109
  ] });
114
110
  };
115
111
  export {
116
- B as CashValue,
117
- O as CurrencyCallStaleTimeMs
112
+ z as CashValue,
113
+ M as CurrencyCallStaleTimeMs
118
114
  };
@@ -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-DJFSvWw5.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,6 @@ 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;
42
41
  }
43
42
  export declare const CurrencyCallStaleTimeMs: number;
44
43
  /**
@@ -48,4 +47,4 @@ export declare const CurrencyCallStaleTimeMs: number;
48
47
  * If the original currency differs from the user's currency, it shows a conversion
49
48
  * tooltip with details about the conversion rate and original amount.
50
49
  */
51
- export declare const CashValue: ({ amount, currency, position, zeroDisplayOption, customDisplay, decimalPlaces, showConversion, addBuffer }: ICashValueProps) => import("react/jsx-runtime").JSX.Element;
50
+ export declare const CashValue: ({ amount, currency, position, zeroDisplayOption, customDisplay, decimalPlaces, showConversion }: 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 }: 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.30",
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
- };