@tap-payments/os-micro-frontend-shared 0.0.99-amount-fix → 0.0.99-amount-fix-1
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,5 +1,6 @@
|
|
|
1
1
|
var _a;
|
|
2
|
-
|
|
2
|
+
const isSAOCI = import.meta.env.VITE_DEPLOYMENT_REGION === 'sa-oci';
|
|
3
|
+
export const BASE_URL = (_a = (isSAOCI ? 'https://mw-os.tap.com.sa' : import.meta.env.VITE_MW_BASE_URL)) !== null && _a !== void 0 ? _a : import.meta.env.VITE_BASE_URL;
|
|
3
4
|
export const API_URL = `${BASE_URL}/api`;
|
|
4
5
|
export const ENV = import.meta.env.VITE_ENV;
|
|
5
6
|
export const TEST_SECRET_KEY = import.meta.env.VITE_TEST_FIXED_SK;
|
|
@@ -10,14 +10,22 @@ export declare const isIntegerAmount: (charge: number) => boolean;
|
|
|
10
10
|
export declare const isDecimalWithOneDigit: (charge: number) => boolean;
|
|
11
11
|
export declare const hasOnlyOneDigitAfterDecimal: (charge: number) => boolean;
|
|
12
12
|
export declare const formatCurrencyWithInput: (charge: number, selectedCurrency: CurrencyCodes) => string;
|
|
13
|
-
export declare function formatAmount(amount: number,
|
|
13
|
+
export declare function formatAmount(amount: number, decimalPlaces?: number): {
|
|
14
14
|
integerAmount: string;
|
|
15
15
|
decimalAmount: string;
|
|
16
16
|
fullAmount: string;
|
|
17
|
+
raw: {
|
|
18
|
+
integer: number;
|
|
19
|
+
decimal: number;
|
|
20
|
+
};
|
|
17
21
|
};
|
|
18
22
|
export declare function formatAmountWithCurrency(amount?: number, currency?: string): {
|
|
19
23
|
integerAmount: string;
|
|
20
24
|
decimalAmount: string;
|
|
21
25
|
fullAmount: string;
|
|
26
|
+
raw: {
|
|
27
|
+
integer: number;
|
|
28
|
+
decimal: number;
|
|
29
|
+
};
|
|
22
30
|
};
|
|
23
31
|
export declare const getSupportedCurrencies: (currencies: Currency[]) => Currency[];
|
package/build/utils/currency.js
CHANGED
|
@@ -55,24 +55,33 @@ export const formatCurrencyWithInput = (charge, selectedCurrency) => {
|
|
|
55
55
|
}
|
|
56
56
|
return chargeString;
|
|
57
57
|
};
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const
|
|
58
|
+
function buildFormattedAmount(integer, decimal) {
|
|
59
|
+
return Number(decimal) > 0 ? `${integer}.${decimal}` : integer;
|
|
60
|
+
}
|
|
61
|
+
function getRawAmount(integer, decimalStr, isNegative) {
|
|
62
|
+
const sign = isNegative ? -1 : 1;
|
|
63
|
+
const decimal = Number(`0.${decimalStr}`) * sign;
|
|
64
|
+
return {
|
|
65
|
+
integer: integer * sign,
|
|
66
|
+
decimal,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
export function formatAmount(amount, decimalPlaces = 2) {
|
|
70
|
+
var _a;
|
|
71
|
+
const isNegative = amount < 0;
|
|
72
|
+
amount = Math.abs(amount);
|
|
73
|
+
const integerAmount = Math.floor(amount);
|
|
74
|
+
let decimalStr = (amount - integerAmount).toString().split('.')[1] || '0';
|
|
75
|
+
decimalStr = decimalStr.padEnd(decimalPlaces, '0').slice(0, decimalPlaces);
|
|
76
|
+
const formattedIntegerAmount = Intl.NumberFormat('en-US').format(integerAmount);
|
|
77
|
+
const decimalStrWithoutRounding = (_a = amount.toString().split('.')[1]) === null || _a === void 0 ? void 0 : _a.slice(0, decimalPlaces);
|
|
78
|
+
const fullAmount = buildFormattedAmount(formattedIntegerAmount, decimalStrWithoutRounding);
|
|
79
|
+
const raw = getRawAmount(integerAmount, decimalStr, isNegative);
|
|
72
80
|
return {
|
|
73
|
-
integerAmount:
|
|
74
|
-
decimalAmount:
|
|
75
|
-
fullAmount
|
|
81
|
+
integerAmount: formattedIntegerAmount,
|
|
82
|
+
decimalAmount: decimalStr,
|
|
83
|
+
fullAmount,
|
|
84
|
+
raw,
|
|
76
85
|
};
|
|
77
86
|
}
|
|
78
87
|
export function formatAmountWithCurrency(amount = 0, currency = '') {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tap-payments/os-micro-frontend-shared",
|
|
3
3
|
"description": "Shared components and utilities for Tap Payments micro frontends",
|
|
4
|
-
"version": "0.0.99-amount-fix",
|
|
4
|
+
"version": " 0.0.99-amount-fix-1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "build/index.js",
|
|
7
7
|
"module": "build/index.js",
|