@odynn/awayz-core 0.9.30 → 0.9.32
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-DJFSvWw5.js → cashUtils-DB_r0g-F.js} +3 -3
- package/dist/components/CashValue/CashValue.js +63 -60
- package/dist/hooks/useAwayzAuth/useAwayzAuth.js +23 -23
- package/dist/lib/components/CashValue/CashValue.d.ts +5 -1
- package/dist/lib/components/CashValue/CashValue.stories.d.ts +1 -1
- package/dist/lib/services/account/AccountServices.types.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,107 +1,110 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useQuery as
|
|
1
|
+
import { jsx as r, jsxs as l } from "react/jsx-runtime";
|
|
2
|
+
import { useQuery as R } from "@tanstack/react-query";
|
|
3
3
|
import "../../arrayExtensions-DlcBOj5a.js";
|
|
4
|
-
import { g as
|
|
5
|
-
import { E as
|
|
6
|
-
import { useMemo as
|
|
7
|
-
import { a as
|
|
4
|
+
import { g as m, a as _, b as N } from "../../cashUtils-DB_r0g-F.js";
|
|
5
|
+
import { E as S } from "../../noRetryInstance-DKhe8ju0.js";
|
|
6
|
+
import { useMemo as T } from "react";
|
|
7
|
+
import { a as f } 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 s, EToolTipPosition as D } from "./CashValueTypes.js";
|
|
13
|
+
import { useAwayzContext as I } from "../../hooks/useAwayzContext.js";
|
|
14
14
|
import "../../configs/awayzClient.js";
|
|
15
15
|
/* empty css */
|
|
16
16
|
import "../../context/AwayzContext.js";
|
|
17
|
-
import { CurrencyService as
|
|
18
|
-
import { Tooltip as
|
|
19
|
-
const
|
|
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 = ({
|
|
20
20
|
amount: i,
|
|
21
|
-
currency:
|
|
22
|
-
position:
|
|
23
|
-
zeroDisplayOption: A =
|
|
24
|
-
customDisplay:
|
|
21
|
+
currency: e,
|
|
22
|
+
position: v = D.RIGHT,
|
|
23
|
+
zeroDisplayOption: A = s.NA,
|
|
24
|
+
customDisplay: y,
|
|
25
25
|
decimalPlaces: p = 2,
|
|
26
|
-
showConversion:
|
|
26
|
+
showConversion: g = !1,
|
|
27
|
+
showOriginal: E = !1
|
|
27
28
|
}) => {
|
|
28
|
-
var h;
|
|
29
|
-
const { user:
|
|
30
|
-
queryKey: [
|
|
31
|
-
queryFn: () =>
|
|
32
|
-
baseCurrency:
|
|
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), t = n !== e, { data: c, isPending: d } = R({
|
|
31
|
+
queryKey: [S.CONVERT_CURRENCY, e, n],
|
|
32
|
+
queryFn: () => M.convertCurrency({
|
|
33
|
+
baseCurrency: e,
|
|
33
34
|
targetCurrency: n
|
|
34
35
|
}),
|
|
35
|
-
enabled:
|
|
36
|
-
staleTime:
|
|
37
|
-
}), a =
|
|
38
|
-
if (!
|
|
36
|
+
enabled: t && !!e && !!i,
|
|
37
|
+
staleTime: x
|
|
38
|
+
}), a = T(() => {
|
|
39
|
+
if (!o)
|
|
39
40
|
return null;
|
|
40
|
-
let
|
|
41
|
-
if (
|
|
42
|
-
if (
|
|
43
|
-
|
|
41
|
+
let u = typeof i == "string" ? parseFloat(i) : i;
|
|
42
|
+
if (t) {
|
|
43
|
+
if (d || !c) return null;
|
|
44
|
+
u = u * c;
|
|
44
45
|
}
|
|
45
|
-
return
|
|
46
|
-
}, [i,
|
|
47
|
-
if (
|
|
48
|
-
return /* @__PURE__ */
|
|
46
|
+
return u;
|
|
47
|
+
}, [i, o, d, t, c]);
|
|
48
|
+
if (E)
|
|
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 });
|
|
49
52
|
if (!n || !a || a < 0)
|
|
50
53
|
switch (A) {
|
|
51
|
-
case
|
|
52
|
-
return /* @__PURE__ */
|
|
53
|
-
case
|
|
54
|
-
return /* @__PURE__ */
|
|
55
|
-
case
|
|
56
|
-
return /* @__PURE__ */
|
|
57
|
-
case
|
|
58
|
-
return /* @__PURE__ */
|
|
59
|
-
case
|
|
60
|
-
return /* @__PURE__ */
|
|
61
|
-
case
|
|
62
|
-
return /* @__PURE__ */
|
|
54
|
+
case s.NA:
|
|
55
|
+
return /* @__PURE__ */ r("span", { children: "N/A" });
|
|
56
|
+
case s.HIDDEN:
|
|
57
|
+
return /* @__PURE__ */ r("span", { className: "hidden", children: "N/A" });
|
|
58
|
+
case s.DISPLAY_AS_ZERO:
|
|
59
|
+
return /* @__PURE__ */ r("span", { children: "0" });
|
|
60
|
+
case s.DISPLAY_AS_ZERO_WITH_CURRENCY:
|
|
61
|
+
return /* @__PURE__ */ r("span", { children: N(0, n ?? e) });
|
|
62
|
+
case s.DISPLAY_AS_ZERO_WITH_CURRENCY_NO_DECIMAL:
|
|
63
|
+
return /* @__PURE__ */ r("span", { children: _(0, n ?? e) });
|
|
64
|
+
case s.CUSTOM:
|
|
65
|
+
return /* @__PURE__ */ r("span", { children: a == 0 ? y : "N/A" });
|
|
63
66
|
default:
|
|
64
|
-
return /* @__PURE__ */
|
|
67
|
+
return /* @__PURE__ */ r("span", { children: "N/A" });
|
|
65
68
|
}
|
|
66
69
|
return /* @__PURE__ */ l("span", { className: "currency-conversion", children: [
|
|
67
|
-
|
|
70
|
+
m(
|
|
68
71
|
a,
|
|
69
72
|
n,
|
|
70
73
|
p
|
|
71
74
|
),
|
|
72
|
-
|
|
73
|
-
|
|
75
|
+
t && g && /* @__PURE__ */ r(
|
|
76
|
+
O,
|
|
74
77
|
{
|
|
75
|
-
trigger: /* @__PURE__ */
|
|
76
|
-
position:
|
|
78
|
+
trigger: /* @__PURE__ */ r("sup", { children: /* @__PURE__ */ r(f, {}) }),
|
|
79
|
+
position: v,
|
|
77
80
|
children: /* @__PURE__ */ l("div", { className: "currency-conversion-container", children: [
|
|
78
81
|
/* @__PURE__ */ l("p", { children: [
|
|
79
82
|
"Converted from ",
|
|
80
|
-
|
|
83
|
+
e,
|
|
81
84
|
" to ",
|
|
82
85
|
n
|
|
83
86
|
] }),
|
|
84
87
|
/* @__PURE__ */ l("div", { className: "currency-conversion-amounts", children: [
|
|
85
|
-
/* @__PURE__ */
|
|
86
|
-
/* @__PURE__ */
|
|
88
|
+
/* @__PURE__ */ r("div", { children: /* @__PURE__ */ r("p", { children: m(i, e, p) }) }),
|
|
89
|
+
/* @__PURE__ */ r("div", { children: /* @__PURE__ */ r("p", { children: m(
|
|
87
90
|
a,
|
|
88
91
|
n,
|
|
89
92
|
p
|
|
90
93
|
) }) }),
|
|
91
|
-
/* @__PURE__ */
|
|
94
|
+
/* @__PURE__ */ r("span", { className: "conversion-icon", children: /* @__PURE__ */ r(f, {}) })
|
|
92
95
|
] }),
|
|
93
|
-
/* @__PURE__ */
|
|
96
|
+
/* @__PURE__ */ r("div", { className: "currency-conversion-rate", children: /* @__PURE__ */ l("p", { children: [
|
|
94
97
|
"Current Rate:",
|
|
95
98
|
" ",
|
|
96
99
|
c ? (
|
|
97
100
|
// only leaving 2 decimal places for the conversion rate is
|
|
98
101
|
// not enough, can lead to confusion
|
|
99
102
|
// use Number constructor to strip unnecessary trailing zeros
|
|
100
|
-
`${Number((1 / c).toFixed(5))} ${
|
|
103
|
+
`${Number((1 / c).toFixed(5))} ${e}`
|
|
101
104
|
) : "N/A",
|
|
102
105
|
" ",
|
|
103
106
|
"≈ ",
|
|
104
|
-
|
|
107
|
+
N(1, n)
|
|
105
108
|
] }) })
|
|
106
109
|
] })
|
|
107
110
|
}
|
|
@@ -109,6 +112,6 @@ const M = 1e3 * 60 * 60, z = ({
|
|
|
109
112
|
] });
|
|
110
113
|
};
|
|
111
114
|
export {
|
|
112
|
-
|
|
113
|
-
|
|
115
|
+
k as CashValue,
|
|
116
|
+
x as CurrencyCallStaleTimeMs
|
|
114
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";
|
|
@@ -17,22 +17,22 @@ import "../../context/AwayzContext.js";
|
|
|
17
17
|
/* empty css */
|
|
18
18
|
import { EAuthFlow as T } from "../../types/EAuthFlow.js";
|
|
19
19
|
const x = (s, c) => {
|
|
20
|
-
var m,
|
|
21
|
-
let i = "",
|
|
22
|
-
typeof c == "string" ? i = c : c instanceof P ? (i = c.message,
|
|
20
|
+
var m, S;
|
|
21
|
+
let i = "", y = c;
|
|
22
|
+
typeof c == "string" ? i = c : c instanceof P ? (i = c.message, y = {
|
|
23
23
|
message: c.message,
|
|
24
24
|
cause: c.cause,
|
|
25
25
|
status: c.status,
|
|
26
26
|
data: (m = c == null ? void 0 : c.response) == null ? void 0 : m.data
|
|
27
|
-
}) : i = c.message, (
|
|
27
|
+
}) : i = c.message, (S = window.parent) == null || S.postMessage(
|
|
28
28
|
{
|
|
29
29
|
type: "auth_error",
|
|
30
|
-
details: { message: i, action: s, info:
|
|
30
|
+
details: { message: i, action: s, info: y }
|
|
31
31
|
},
|
|
32
32
|
"*"
|
|
33
33
|
);
|
|
34
34
|
}, le = (s) => {
|
|
35
|
-
const [c, i] = f(!0), [
|
|
35
|
+
const [c, i] = f(!0), [y, m] = f(!1), [S, A] = f(), [g, k] = f(), [C, _] = f([]), [p, F] = f([]), E = I(
|
|
36
36
|
async (t) => {
|
|
37
37
|
s != null && s.onSuccess && (s == null || s.onSuccess(t)), s != null && s.onSuccessAsync && await (s == null ? void 0 : s.onSuccessAsync(t)), i(!1), m(!0), A(t.token), k(t.user), O.invalidateQueries();
|
|
38
38
|
},
|
|
@@ -59,13 +59,13 @@ const x = (s, c) => {
|
|
|
59
59
|
u("no awayz token returned after exchanging id token");
|
|
60
60
|
return;
|
|
61
61
|
}
|
|
62
|
-
localStorage.setItem(o.TOKEN, n.token), await
|
|
63
|
-
const { data:
|
|
62
|
+
localStorage.setItem(o.TOKEN, n.token), await E(n);
|
|
63
|
+
const { data: d, ...K } = await l.getRequestLimit();
|
|
64
64
|
if (!K.success) {
|
|
65
65
|
console.error({ reqLimitError: K });
|
|
66
66
|
return;
|
|
67
67
|
}
|
|
68
|
-
|
|
68
|
+
d == null || d.forEach(
|
|
69
69
|
(H) => window.parent.postMessage(
|
|
70
70
|
{
|
|
71
71
|
type: "request_limit",
|
|
@@ -89,7 +89,7 @@ const x = (s, c) => {
|
|
|
89
89
|
u(e);
|
|
90
90
|
return;
|
|
91
91
|
}
|
|
92
|
-
await
|
|
92
|
+
await E({
|
|
93
93
|
user: e,
|
|
94
94
|
token: localStorage.getItem(o.TOKEN)
|
|
95
95
|
});
|
|
@@ -126,11 +126,11 @@ const x = (s, c) => {
|
|
|
126
126
|
if (e.data.type !== "auth") return;
|
|
127
127
|
const r = (w = e.data) == null ? void 0 : w.idToken, a = e.data.refreshToken, n = s.isTestMode ? e.data.overrideTokenExchangeEndpoint : void 0;
|
|
128
128
|
if (!r) {
|
|
129
|
-
const
|
|
129
|
+
const d = `received message ${JSON.stringify(
|
|
130
130
|
e.data
|
|
131
131
|
)}
|
|
132
132
|
no idToken in body`;
|
|
133
|
-
u(
|
|
133
|
+
u(d);
|
|
134
134
|
return;
|
|
135
135
|
}
|
|
136
136
|
localStorage.setItem(o.REFRESH_TOKEN, a), await R(r, a, n);
|
|
@@ -146,9 +146,9 @@ const x = (s, c) => {
|
|
|
146
146
|
};
|
|
147
147
|
}, []), {
|
|
148
148
|
isAuthenticating: c,
|
|
149
|
-
isAuthenticated:
|
|
150
|
-
token:
|
|
151
|
-
user:
|
|
149
|
+
isAuthenticated: y,
|
|
150
|
+
token: S,
|
|
151
|
+
user: g,
|
|
152
152
|
supportedRegions: C,
|
|
153
153
|
supportedCurrencies: p,
|
|
154
154
|
signIn: async (t) => {
|
|
@@ -158,7 +158,7 @@ const x = (s, c) => {
|
|
|
158
158
|
u(e.message);
|
|
159
159
|
else {
|
|
160
160
|
const a = (r = e.data) == null ? void 0 : r.refreshToken;
|
|
161
|
-
localStorage.setItem(o.REFRESH_TOKEN, a), await
|
|
161
|
+
localStorage.setItem(o.REFRESH_TOKEN, a), await E(e.data);
|
|
162
162
|
}
|
|
163
163
|
return e;
|
|
164
164
|
},
|
|
@@ -169,7 +169,7 @@ const x = (s, c) => {
|
|
|
169
169
|
u(e.message);
|
|
170
170
|
else {
|
|
171
171
|
const a = (r = e.data) == null ? void 0 : r.refreshToken;
|
|
172
|
-
localStorage.setItem(o.REFRESH_TOKEN, a), await
|
|
172
|
+
localStorage.setItem(o.REFRESH_TOKEN, a), await E(e.data);
|
|
173
173
|
}
|
|
174
174
|
return e;
|
|
175
175
|
},
|
|
@@ -186,7 +186,7 @@ const x = (s, c) => {
|
|
|
186
186
|
u(r.message);
|
|
187
187
|
else {
|
|
188
188
|
const n = (a = r.data) == null ? void 0 : a.refreshToken;
|
|
189
|
-
localStorage.setItem(o.REFRESH_TOKEN, n), await
|
|
189
|
+
localStorage.setItem(o.REFRESH_TOKEN, n), await E(r.data);
|
|
190
190
|
}
|
|
191
191
|
return r;
|
|
192
192
|
},
|
|
@@ -198,12 +198,12 @@ const x = (s, c) => {
|
|
|
198
198
|
const e = await q.setCurrency(t);
|
|
199
199
|
if (!e.success || !e.data)
|
|
200
200
|
return console.error("Failed to set preferred currency:", e), !1;
|
|
201
|
-
if (
|
|
201
|
+
if (g) {
|
|
202
202
|
const r = {
|
|
203
|
-
...
|
|
203
|
+
...g,
|
|
204
204
|
preferences: {
|
|
205
|
-
...
|
|
206
|
-
currency: e.data.currency
|
|
205
|
+
...g.preferences,
|
|
206
|
+
currency: e.data.currency || g.preferences.currency
|
|
207
207
|
}
|
|
208
208
|
};
|
|
209
209
|
k(r), O.invalidateQueries({
|
|
@@ -38,6 +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
|
+
/**
|
|
42
|
+
* Whether to show the original amount and currency
|
|
43
|
+
*/
|
|
44
|
+
showOriginal?: boolean;
|
|
41
45
|
}
|
|
42
46
|
export declare const CurrencyCallStaleTimeMs: number;
|
|
43
47
|
/**
|
|
@@ -47,4 +51,4 @@ export declare const CurrencyCallStaleTimeMs: number;
|
|
|
47
51
|
* If the original currency differs from the user's currency, it shows a conversion
|
|
48
52
|
* tooltip with details about the conversion rate and original amount.
|
|
49
53
|
*/
|
|
50
|
-
export declare const CashValue: ({ amount, currency, position, zeroDisplayOption, customDisplay, decimalPlaces, showConversion }: 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 }: 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
|
};
|