@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.
- package/dist/cashUtils-DB_r0g-F.js +34 -0
- package/dist/components/CashValue/CashValue.js +66 -67
- package/dist/hooks/useAwayzAuth/useAwayzAuth.js +1 -1
- package/dist/index-BlYZu1Ej.js +5 -0
- package/dist/lib/components/CashValue/CashValue.d.ts +5 -2
- package/dist/lib/components/CashValue/CashValue.stories.d.ts +1 -1
- package/dist/services/currency/CurrencyService.js +18 -17
- package/package.json +1 -1
- package/dist/cashUtils-CrBZrS6N.js +0 -34
|
@@ -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
|
|
2
|
-
import { useQuery as
|
|
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 {
|
|
5
|
-
import { E as
|
|
6
|
-
import { useMemo as
|
|
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
|
|
13
|
-
import { useAwayzContext as
|
|
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
|
|
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,
|
|
19
|
+
const O = 1e3 * 60 * 60, G = ({
|
|
20
20
|
amount: i,
|
|
21
|
-
currency:
|
|
22
|
-
position: f =
|
|
23
|
-
zeroDisplayOption:
|
|
24
|
-
customDisplay:
|
|
25
|
-
decimalPlaces:
|
|
26
|
-
showConversion:
|
|
27
|
-
|
|
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 } =
|
|
31
|
-
queryKey: [
|
|
32
|
-
queryFn:
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
}),
|
|
38
|
+
}), a = S(() => {
|
|
42
39
|
if (!s)
|
|
43
40
|
return null;
|
|
44
|
-
let
|
|
45
|
-
if (
|
|
41
|
+
let u = typeof i == "string" ? parseFloat(i) : i;
|
|
42
|
+
if (t) {
|
|
46
43
|
if (d || !c) return null;
|
|
47
|
-
|
|
44
|
+
u = u * c;
|
|
48
45
|
}
|
|
49
|
-
return
|
|
50
|
-
}, [i, s, d,
|
|
51
|
-
if (
|
|
52
|
-
return /* @__PURE__ */
|
|
53
|
-
if (
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
case
|
|
58
|
-
return /* @__PURE__ */
|
|
59
|
-
case
|
|
60
|
-
return /* @__PURE__ */
|
|
61
|
-
case
|
|
62
|
-
return /* @__PURE__ */
|
|
63
|
-
case
|
|
64
|
-
return /* @__PURE__ */
|
|
65
|
-
case
|
|
66
|
-
return /* @__PURE__ */
|
|
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__ */
|
|
67
|
+
return /* @__PURE__ */ r("span", { children: "N/A" });
|
|
69
68
|
}
|
|
70
|
-
return /* @__PURE__ */
|
|
71
|
-
|
|
72
|
-
|
|
69
|
+
return /* @__PURE__ */ l("span", { className: "currency-conversion", children: [
|
|
70
|
+
m(
|
|
71
|
+
a,
|
|
73
72
|
n,
|
|
74
|
-
|
|
73
|
+
p
|
|
75
74
|
),
|
|
76
|
-
|
|
75
|
+
t && y && /* @__PURE__ */ r(
|
|
77
76
|
M,
|
|
78
77
|
{
|
|
79
|
-
trigger: /* @__PURE__ */
|
|
78
|
+
trigger: /* @__PURE__ */ r("sup", { children: /* @__PURE__ */ r(N, {}) }),
|
|
80
79
|
position: f,
|
|
81
|
-
children: /* @__PURE__ */
|
|
82
|
-
/* @__PURE__ */
|
|
80
|
+
children: /* @__PURE__ */ l("div", { className: "currency-conversion-container", children: [
|
|
81
|
+
/* @__PURE__ */ l("p", { children: [
|
|
83
82
|
"Converted from ",
|
|
84
|
-
|
|
83
|
+
e,
|
|
85
84
|
" to ",
|
|
86
85
|
n
|
|
87
86
|
] }),
|
|
88
|
-
/* @__PURE__ */
|
|
89
|
-
/* @__PURE__ */
|
|
90
|
-
/* @__PURE__ */
|
|
91
|
-
|
|
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
|
-
|
|
92
|
+
p
|
|
94
93
|
) }) }),
|
|
95
|
-
/* @__PURE__ */
|
|
94
|
+
/* @__PURE__ */ r("span", { className: "conversion-icon", children: /* @__PURE__ */ r(N, {}) })
|
|
96
95
|
] }),
|
|
97
|
-
/* @__PURE__ */
|
|
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))} ${
|
|
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
|
-
|
|
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-
|
|
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";
|
|
@@ -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
|
-
|
|
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,
|
|
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,
|
|
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 {
|
|
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
|
|
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:
|
|
28
|
-
queryKey: [
|
|
28
|
+
const { success: o, data: c } = await R.ensureQueryData({
|
|
29
|
+
queryKey: [_.CHECK_USER],
|
|
29
30
|
queryFn: C.checkUser
|
|
30
31
|
});
|
|
31
|
-
if (!
|
|
32
|
+
if (!o)
|
|
32
33
|
throw new Error("Failed to fetch user data");
|
|
33
|
-
const { userRegion: u, preferences: p } =
|
|
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 (
|
|
38
|
-
return a.data.conversion_rate;
|
|
39
|
-
} catch (
|
|
40
|
-
console.error(
|
|
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:
|
|
56
|
+
amount: o
|
|
56
57
|
}) => {
|
|
57
58
|
try {
|
|
58
|
-
const { data:
|
|
59
|
+
const { data: c } = await s.post(i.CURRENCY_CONVERSION, {
|
|
59
60
|
target_currency: e,
|
|
60
61
|
base_currency: r,
|
|
61
|
-
amount:
|
|
62
|
+
amount: o
|
|
62
63
|
});
|
|
63
|
-
if (
|
|
64
|
-
return
|
|
65
|
-
} catch (
|
|
66
|
-
console.error(
|
|
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,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
|
-
};
|