@odynn/awayz-core 0.2.17 → 0.2.18
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.
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import { IConvertCurrencyArgs } from './CurrencyService.types';
|
|
2
2
|
declare class _CurrencyService {
|
|
3
3
|
convertCurrency: ({ baseCurrency }: IConvertCurrencyArgs) => Promise<number>;
|
|
4
|
+
/**
|
|
5
|
+
* Convert from base currency to target currency for the amount provided
|
|
6
|
+
* @param param0 IConvertCurrencyArgs
|
|
7
|
+
* @param baseCurrency the base currency to convert from
|
|
8
|
+
* @param targetCurrency the target currency to convert to
|
|
9
|
+
* @parm amount the amount to be converted from the base to the target currency
|
|
10
|
+
* @returns the converted amount
|
|
11
|
+
*/
|
|
12
|
+
convertToCurrency: ({ baseCurrency, targetCurrency, amount }: IConvertCurrencyArgs) => Promise<number>;
|
|
4
13
|
}
|
|
5
14
|
export declare const CurrencyService: _CurrencyService;
|
|
6
15
|
export {};
|
|
@@ -1,40 +1,66 @@
|
|
|
1
|
-
import '../../assets/_styles.css';var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { a as
|
|
1
|
+
import '../../assets/_styles.css';var i = Object.defineProperty;
|
|
2
|
+
var y = (t, r, e) => r in t ? i(t, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[r] = e;
|
|
3
|
+
var o = (t, r, e) => y(t, typeof r != "symbol" ? r + "" : r, e);
|
|
4
|
+
import { a as p, b as C, c as a } from "../../AccountService--d4c37gO.js";
|
|
5
5
|
import "react";
|
|
6
|
-
import { ECurrencyEndpoints as
|
|
6
|
+
import { ECurrencyEndpoints as s } from "../../configs/endpoints.js";
|
|
7
7
|
import "react/jsx-runtime";
|
|
8
8
|
import "../../context/AwayzContext.js";
|
|
9
|
-
import { awayzClient as
|
|
9
|
+
import { awayzClient as m } from "../../configs/awayzClient.js";
|
|
10
10
|
import "@tanstack/react-query";
|
|
11
11
|
/* empty css */
|
|
12
12
|
class E {
|
|
13
13
|
constructor() {
|
|
14
|
-
|
|
14
|
+
o(this, "convertCurrency", async ({
|
|
15
15
|
baseCurrency: r
|
|
16
16
|
}) => {
|
|
17
17
|
try {
|
|
18
|
-
const { success: e, data: n } = await
|
|
19
|
-
queryKey: [
|
|
20
|
-
queryFn:
|
|
18
|
+
const { success: e, data: n } = await m.ensureQueryData({
|
|
19
|
+
queryKey: [C.CHECK_USER],
|
|
20
|
+
queryFn: p.checkUser
|
|
21
21
|
});
|
|
22
22
|
if (!e)
|
|
23
23
|
throw new Error("Failed to fetch user data");
|
|
24
|
-
const { userRegion:
|
|
25
|
-
target_currency:
|
|
24
|
+
const { userRegion: c } = n, { data: u } = await a.post(s.CURRENCY_CONVERSION, {
|
|
25
|
+
target_currency: c.currency,
|
|
26
26
|
base_currency: r
|
|
27
27
|
});
|
|
28
28
|
if (e)
|
|
29
|
-
return
|
|
29
|
+
return u.data.conversion_rate;
|
|
30
30
|
} catch (e) {
|
|
31
31
|
console.error(e);
|
|
32
32
|
}
|
|
33
33
|
return 0;
|
|
34
34
|
});
|
|
35
|
+
/**
|
|
36
|
+
* Convert from base currency to target currency for the amount provided
|
|
37
|
+
* @param param0 IConvertCurrencyArgs
|
|
38
|
+
* @param baseCurrency the base currency to convert from
|
|
39
|
+
* @param targetCurrency the target currency to convert to
|
|
40
|
+
* @parm amount the amount to be converted from the base to the target currency
|
|
41
|
+
* @returns the converted amount
|
|
42
|
+
*/
|
|
43
|
+
o(this, "convertToCurrency", async ({
|
|
44
|
+
baseCurrency: r,
|
|
45
|
+
targetCurrency: e,
|
|
46
|
+
amount: n
|
|
47
|
+
}) => {
|
|
48
|
+
try {
|
|
49
|
+
const { data: c } = await a.post(s.CURRENCY_CONVERSION, {
|
|
50
|
+
target_currency: e,
|
|
51
|
+
base_currency: r,
|
|
52
|
+
amount: n
|
|
53
|
+
});
|
|
54
|
+
if (c.success)
|
|
55
|
+
return c.data.conversion_result;
|
|
56
|
+
} catch (c) {
|
|
57
|
+
console.error(c);
|
|
58
|
+
}
|
|
59
|
+
return 0;
|
|
60
|
+
});
|
|
35
61
|
}
|
|
36
62
|
}
|
|
37
|
-
const
|
|
63
|
+
const h = new E();
|
|
38
64
|
export {
|
|
39
|
-
|
|
65
|
+
h as CurrencyService
|
|
40
66
|
};
|