payment-kit 1.16.19 → 1.17.0
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/blocklet.yml
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "payment-kit",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.17.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "blocklet dev --open",
|
|
6
6
|
"eject": "vite eject",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"@arcblock/validator": "^1.18.165",
|
|
54
54
|
"@blocklet/js-sdk": "^1.16.36",
|
|
55
55
|
"@blocklet/logger": "^1.16.36",
|
|
56
|
-
"@blocklet/payment-react": "1.
|
|
56
|
+
"@blocklet/payment-react": "1.17.0",
|
|
57
57
|
"@blocklet/sdk": "^1.16.36",
|
|
58
58
|
"@blocklet/ui-react": "^2.11.15",
|
|
59
59
|
"@blocklet/uploader": "^0.1.60",
|
|
@@ -120,7 +120,7 @@
|
|
|
120
120
|
"devDependencies": {
|
|
121
121
|
"@abtnode/types": "^1.16.36",
|
|
122
122
|
"@arcblock/eslint-config-ts": "^0.3.3",
|
|
123
|
-
"@blocklet/payment-types": "1.
|
|
123
|
+
"@blocklet/payment-types": "1.17.0",
|
|
124
124
|
"@types/cookie-parser": "^1.4.7",
|
|
125
125
|
"@types/cors": "^2.8.17",
|
|
126
126
|
"@types/debug": "^4.1.12",
|
|
@@ -166,5 +166,5 @@
|
|
|
166
166
|
"parser": "typescript"
|
|
167
167
|
}
|
|
168
168
|
},
|
|
169
|
-
"gitHead": "
|
|
169
|
+
"gitHead": "b25f7f7c1990a01db3c43dff90eecb65f37bd5d7"
|
|
170
170
|
}
|
|
@@ -19,9 +19,9 @@ import {
|
|
|
19
19
|
} from '@mui/material';
|
|
20
20
|
import Dialog from '@arcblock/ux/lib/Dialog';
|
|
21
21
|
import { EventHandler, useState } from 'react';
|
|
22
|
-
import { api, Switch, useMobile } from '@blocklet/payment-react';
|
|
22
|
+
import { api, formatAmountPrecisionLimit, Switch, useMobile } from '@blocklet/payment-react';
|
|
23
23
|
import { useRequest } from 'ahooks';
|
|
24
|
-
import { BN, fromUnitToToken } from '@ocap/util';
|
|
24
|
+
import { BN, fromTokenToUnit, fromUnitToToken } from '@ocap/util';
|
|
25
25
|
import type { TPaymentCurrency, TSubscriptionExpanded } from '@blocklet/payment-types';
|
|
26
26
|
import Currency from '../currency';
|
|
27
27
|
|
|
@@ -32,6 +32,21 @@ const fetchCycleAmount = (
|
|
|
32
32
|
return api.get(`/api/subscriptions/${subscriptionId}/cycle-amount`, { params }).then((res) => res.data);
|
|
33
33
|
};
|
|
34
34
|
|
|
35
|
+
function safeAdd(currency: { decimal: number }, ...numbers: string[]) {
|
|
36
|
+
if (!numbers.length) return '0';
|
|
37
|
+
if (!numbers.every((n) => /^-?\d*\.?\d*$/.test(n))) {
|
|
38
|
+
throw new Error('Invalid number format');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const decimal = currency?.decimal || 18;
|
|
42
|
+
const sum = numbers.reduce((total, num) => {
|
|
43
|
+
const unitAmount = fromTokenToUnit(num, decimal);
|
|
44
|
+
return new BN(total).add(new BN(unitAmount));
|
|
45
|
+
}, new BN(0));
|
|
46
|
+
|
|
47
|
+
return fromUnitToToken(sum.toString(), decimal);
|
|
48
|
+
}
|
|
49
|
+
|
|
35
50
|
type OverdraftProtectionDialogProps = {
|
|
36
51
|
value: {
|
|
37
52
|
enabled: boolean;
|
|
@@ -48,6 +63,7 @@ type OverdraftProtectionDialogProps = {
|
|
|
48
63
|
symbol: string;
|
|
49
64
|
logo: string;
|
|
50
65
|
decimal: number;
|
|
66
|
+
maximum_precision?: number;
|
|
51
67
|
};
|
|
52
68
|
subscription: TSubscriptionExpanded;
|
|
53
69
|
};
|
|
@@ -66,7 +82,7 @@ export default function OverdraftProtectionDialog({
|
|
|
66
82
|
currency,
|
|
67
83
|
subscription,
|
|
68
84
|
}: OverdraftProtectionDialogProps) {
|
|
69
|
-
const { t } = useLocaleContext();
|
|
85
|
+
const { t, locale } = useLocaleContext();
|
|
70
86
|
const { isMobile } = useMobile();
|
|
71
87
|
const [customAmount, setCustomAmount] = useState(false);
|
|
72
88
|
const [presetAmounts, setPresetAmounts] = useState<{ amount: string; cycles: number }[]>([]);
|
|
@@ -298,6 +314,14 @@ export default function OverdraftProtectionDialog({
|
|
|
298
314
|
symbol: currency.symbol,
|
|
299
315
|
});
|
|
300
316
|
}
|
|
317
|
+
const validPrecision = formatAmountPrecisionLimit(
|
|
318
|
+
val.toString(),
|
|
319
|
+
locale,
|
|
320
|
+
currency?.maximum_precision || 6
|
|
321
|
+
);
|
|
322
|
+
if (validPrecision) {
|
|
323
|
+
return validPrecision;
|
|
324
|
+
}
|
|
301
325
|
return true;
|
|
302
326
|
},
|
|
303
327
|
})}
|
|
@@ -325,11 +349,11 @@ export default function OverdraftProtectionDialog({
|
|
|
325
349
|
{amount && Number(amount) > 0 && !methods.formState.errors.amount && (
|
|
326
350
|
<Typography variant="body2" sx={{ color: 'text.lighter', mt: '8px !important' }} fontSize={12}>
|
|
327
351
|
{t('customer.overdraftProtection.total', {
|
|
328
|
-
total:
|
|
352
|
+
total: safeAdd(currency, amount, availableAmount),
|
|
329
353
|
symbol: currency.symbol,
|
|
330
354
|
})}
|
|
331
355
|
{formatEstimatedDuration(
|
|
332
|
-
Math.floor(
|
|
356
|
+
Math.floor(Number(safeAdd(currency, amount, availableAmount)) / Number(estimateAmount))
|
|
333
357
|
)}
|
|
334
358
|
</Typography>
|
|
335
359
|
)}
|