@blocklet/payment-react 1.14.5 → 1.14.6
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/es/libs/util.d.ts +1 -0
- package/es/libs/util.js +7 -0
- package/es/locales/en.js +2 -1
- package/es/locales/zh.js +2 -1
- package/es/payment/index.js +17 -2
- package/es/payment/product-donation.d.ts +3 -2
- package/es/payment/product-donation.js +9 -2
- package/es/payment/summary.js +2 -1
- package/lib/libs/util.d.ts +1 -0
- package/lib/libs/util.js +10 -0
- package/lib/locales/en.js +2 -1
- package/lib/locales/zh.js +2 -1
- package/lib/payment/index.js +13 -2
- package/lib/payment/product-donation.d.ts +3 -2
- package/lib/payment/product-donation.js +13 -2
- package/lib/payment/summary.js +2 -1
- package/package.json +3 -3
- package/src/libs/util.ts +8 -0
- package/src/locales/en.tsx +1 -0
- package/src/locales/zh.tsx +1 -0
- package/src/payment/index.tsx +21 -2
- package/src/payment/product-donation.tsx +11 -2
- package/src/payment/summary.tsx +1 -0
package/es/libs/util.d.ts
CHANGED
|
@@ -77,3 +77,4 @@ export declare function formatTotalPrice({ product, quantity, priceId, locale, }
|
|
|
77
77
|
locale: string;
|
|
78
78
|
}): PricingRenderProps;
|
|
79
79
|
export declare function formatQuantityInventory(price: TPrice, quantity: string | number, locale?: string): string;
|
|
80
|
+
export declare function formatAmountPrecisionLimit(amount: string, locale?: string, precision?: number): string;
|
package/es/libs/util.js
CHANGED
|
@@ -687,3 +687,10 @@ export function formatQuantityInventory(price, quantity, locale = "en") {
|
|
|
687
687
|
}
|
|
688
688
|
return "";
|
|
689
689
|
}
|
|
690
|
+
export function formatAmountPrecisionLimit(amount, locale = "en", precision = 6) {
|
|
691
|
+
const [, decimal] = amount.split(".");
|
|
692
|
+
if (decimal && decimal.length > precision) {
|
|
693
|
+
return t("common.amountPrecisionLimit", locale, { precision });
|
|
694
|
+
}
|
|
695
|
+
return "";
|
|
696
|
+
}
|
package/es/locales/en.js
CHANGED
|
@@ -84,7 +84,8 @@ export default flat({
|
|
|
84
84
|
type: "type",
|
|
85
85
|
donation: "Donation",
|
|
86
86
|
quantityLimitPerCheckout: "Exceed purchase limit",
|
|
87
|
-
quantityNotEnough: "Exceed inventory"
|
|
87
|
+
quantityNotEnough: "Exceed inventory",
|
|
88
|
+
amountPrecisionLimit: "Amount decimal places must be less than or equal to {precision}"
|
|
88
89
|
},
|
|
89
90
|
payment: {
|
|
90
91
|
checkout: {
|
package/es/locales/zh.js
CHANGED
|
@@ -84,7 +84,8 @@ export default flat({
|
|
|
84
84
|
type: "\u7C7B\u578B",
|
|
85
85
|
donation: "\u6253\u8D4F",
|
|
86
86
|
quantityLimitPerCheckout: "\u8D85\u51FA\u8D2D\u4E70\u9650\u5236",
|
|
87
|
-
quantityNotEnough: "\u5E93\u5B58\u4E0D\u8DB3"
|
|
87
|
+
quantityNotEnough: "\u5E93\u5B58\u4E0D\u8DB3",
|
|
88
|
+
amountPrecisionLimit: "\u91D1\u989D\u5C0F\u6570\u4F4D\u6570\u5FC5\u987B\u5728 {precision} \u4F4D\u4EE5\u5185"
|
|
88
89
|
},
|
|
89
90
|
payment: {
|
|
90
91
|
checkout: {
|
package/es/payment/index.js
CHANGED
|
@@ -10,7 +10,13 @@ import { useEffect, useState } from "react";
|
|
|
10
10
|
import { FormProvider, useForm, useWatch } from "react-hook-form";
|
|
11
11
|
import { usePaymentContext } from "../contexts/payment.js";
|
|
12
12
|
import api from "../libs/api.js";
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
findCurrency,
|
|
15
|
+
formatAmountPrecisionLimit,
|
|
16
|
+
formatError,
|
|
17
|
+
getStatementDescriptor,
|
|
18
|
+
isValidCountry
|
|
19
|
+
} from "../libs/util.js";
|
|
14
20
|
import PaymentError from "./error.js";
|
|
15
21
|
import CheckoutFooter from "./footer.js";
|
|
16
22
|
import PaymentForm from "./form/index.js";
|
|
@@ -131,7 +137,7 @@ export function PaymentInner({
|
|
|
131
137
|
goBack,
|
|
132
138
|
action
|
|
133
139
|
}) {
|
|
134
|
-
const { t } = useLocaleContext();
|
|
140
|
+
const { t, locale } = useLocaleContext();
|
|
135
141
|
const { settings, session } = usePaymentContext();
|
|
136
142
|
const [state, setState] = useSetState({ checkoutSession });
|
|
137
143
|
const defaultCurrencyId = state.checkoutSession.currency_id || state.checkoutSession.line_items[0]?.price.currency_id;
|
|
@@ -201,7 +207,15 @@ export function PaymentInner({
|
|
|
201
207
|
Toast.error(formatError(err));
|
|
202
208
|
}
|
|
203
209
|
};
|
|
210
|
+
const min = parseFloat(paymentLink?.donation_settings?.amount.minimum || "0");
|
|
211
|
+
const max = paymentLink?.donation_settings?.amount.maximum ? parseFloat(paymentLink?.donation_settings?.amount.maximum) : Infinity;
|
|
204
212
|
const onChangeAmount = async ({ priceId, amount }) => {
|
|
213
|
+
if (Number(amount) < min || Number(amount) > max) {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
if (formatAmountPrecisionLimit(amount, locale)) {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
205
219
|
try {
|
|
206
220
|
const { data } = await api.put(`/api/checkout-sessions/${state.checkoutSession.id}/amount`, {
|
|
207
221
|
priceId,
|
|
@@ -236,6 +250,7 @@ export function PaymentInner({
|
|
|
236
250
|
trialInDays: state.checkoutSession.subscription_data?.trial_period_days || 0,
|
|
237
251
|
billingThreshold: Math.max(
|
|
238
252
|
state.checkoutSession.subscription_data?.billing_threshold_amount || 0,
|
|
253
|
+
// @ts-ignore
|
|
239
254
|
state.checkoutSession.subscription_data?.min_stake_amount || 0
|
|
240
255
|
),
|
|
241
256
|
showStaking: method.type === "arcblock",
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import type { DonationSettings, TLineItemExpanded } from '@blocklet/payment-types';
|
|
3
|
-
export default function ProductDonation({ item, settings, onChange, }: {
|
|
2
|
+
import type { DonationSettings, TLineItemExpanded, TPaymentCurrency } from '@blocklet/payment-types';
|
|
3
|
+
export default function ProductDonation({ item, settings, onChange, currency, }: {
|
|
4
4
|
item: TLineItemExpanded;
|
|
5
5
|
settings: DonationSettings;
|
|
6
6
|
onChange: Function;
|
|
7
|
+
currency: TPaymentCurrency;
|
|
7
8
|
}): import("react").JSX.Element;
|
|
@@ -4,12 +4,14 @@ import { Box, Card, CardActionArea, FormControlLabel, Stack, TextField, Typograp
|
|
|
4
4
|
import { useSetState } from "ahooks";
|
|
5
5
|
import { useEffect } from "react";
|
|
6
6
|
import Switch from "../components/switch-button.js";
|
|
7
|
+
import { formatAmountPrecisionLimit } from "../libs/util.js";
|
|
7
8
|
export default function ProductDonation({
|
|
8
9
|
item,
|
|
9
10
|
settings,
|
|
10
|
-
onChange
|
|
11
|
+
onChange,
|
|
12
|
+
currency
|
|
11
13
|
}) {
|
|
12
|
-
const { t } = useLocaleContext();
|
|
14
|
+
const { t, locale } = useLocaleContext();
|
|
13
15
|
const preset = settings.amount.preset || settings.amount.presets?.[0] || "0";
|
|
14
16
|
const [state, setState] = useSetState({
|
|
15
17
|
selected: preset,
|
|
@@ -34,6 +36,11 @@ export default function ProductDonation({
|
|
|
34
36
|
const { value } = event.target;
|
|
35
37
|
const min = parseFloat(settings.amount.minimum || "0");
|
|
36
38
|
const max = settings.amount.maximum ? parseFloat(settings.amount.maximum) : Infinity;
|
|
39
|
+
const precision = currency?.maximum_precision || 6;
|
|
40
|
+
if (formatAmountPrecisionLimit(value, locale)) {
|
|
41
|
+
setState({ input: value, error: formatAmountPrecisionLimit(value, locale, precision) });
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
37
44
|
if (value < min || value > max) {
|
|
38
45
|
setState({ input: value, error: t("payment.checkout.donation.between", { min, max }) });
|
|
39
46
|
return;
|
package/es/payment/summary.js
CHANGED
package/lib/libs/util.d.ts
CHANGED
|
@@ -77,3 +77,4 @@ export declare function formatTotalPrice({ product, quantity, priceId, locale, }
|
|
|
77
77
|
locale: string;
|
|
78
78
|
}): PricingRenderProps;
|
|
79
79
|
export declare function formatQuantityInventory(price: TPrice, quantity: string | number, locale?: string): string;
|
|
80
|
+
export declare function formatAmountPrecisionLimit(amount: string, locale?: string, precision?: number): string;
|
package/lib/libs/util.js
CHANGED
|
@@ -7,6 +7,7 @@ exports.PAYMENT_KIT_DID = void 0;
|
|
|
7
7
|
exports.findCurrency = findCurrency;
|
|
8
8
|
exports.flattenPaymentMethods = void 0;
|
|
9
9
|
exports.formatAmount = formatAmount;
|
|
10
|
+
exports.formatAmountPrecisionLimit = formatAmountPrecisionLimit;
|
|
10
11
|
exports.formatBNStr = formatBNStr;
|
|
11
12
|
exports.formatCheckoutHeadlines = formatCheckoutHeadlines;
|
|
12
13
|
exports.formatDateTime = formatDateTime;
|
|
@@ -821,4 +822,13 @@ function formatQuantityInventory(price, quantity, locale = "en") {
|
|
|
821
822
|
return (0, _locales.t)("common.quantityLimitPerCheckout", locale);
|
|
822
823
|
}
|
|
823
824
|
return "";
|
|
825
|
+
}
|
|
826
|
+
function formatAmountPrecisionLimit(amount, locale = "en", precision = 6) {
|
|
827
|
+
const [, decimal] = amount.split(".");
|
|
828
|
+
if (decimal && decimal.length > precision) {
|
|
829
|
+
return (0, _locales.t)("common.amountPrecisionLimit", locale, {
|
|
830
|
+
precision
|
|
831
|
+
});
|
|
832
|
+
}
|
|
833
|
+
return "";
|
|
824
834
|
}
|
package/lib/locales/en.js
CHANGED
|
@@ -91,7 +91,8 @@ module.exports = (0, _flat.default)({
|
|
|
91
91
|
type: "type",
|
|
92
92
|
donation: "Donation",
|
|
93
93
|
quantityLimitPerCheckout: "Exceed purchase limit",
|
|
94
|
-
quantityNotEnough: "Exceed inventory"
|
|
94
|
+
quantityNotEnough: "Exceed inventory",
|
|
95
|
+
amountPrecisionLimit: "Amount decimal places must be less than or equal to {precision}"
|
|
95
96
|
},
|
|
96
97
|
payment: {
|
|
97
98
|
checkout: {
|
package/lib/locales/zh.js
CHANGED
|
@@ -91,7 +91,8 @@ module.exports = (0, _flat.default)({
|
|
|
91
91
|
type: "\u7C7B\u578B",
|
|
92
92
|
donation: "\u6253\u8D4F",
|
|
93
93
|
quantityLimitPerCheckout: "\u8D85\u51FA\u8D2D\u4E70\u9650\u5236",
|
|
94
|
-
quantityNotEnough: "\u5E93\u5B58\u4E0D\u8DB3"
|
|
94
|
+
quantityNotEnough: "\u5E93\u5B58\u4E0D\u8DB3",
|
|
95
|
+
amountPrecisionLimit: "\u91D1\u989D\u5C0F\u6570\u4F4D\u6570\u5FC5\u987B\u5728 {precision} \u4F4D\u4EE5\u5185"
|
|
95
96
|
},
|
|
96
97
|
payment: {
|
|
97
98
|
checkout: {
|
package/lib/payment/index.js
CHANGED
|
@@ -154,7 +154,8 @@ function PaymentInner({
|
|
|
154
154
|
action
|
|
155
155
|
}) {
|
|
156
156
|
const {
|
|
157
|
-
t
|
|
157
|
+
t,
|
|
158
|
+
locale
|
|
158
159
|
} = (0, _context.useLocaleContext)();
|
|
159
160
|
const {
|
|
160
161
|
settings,
|
|
@@ -255,10 +256,18 @@ function PaymentInner({
|
|
|
255
256
|
_Toast.default.error((0, _util2.formatError)(err));
|
|
256
257
|
}
|
|
257
258
|
};
|
|
259
|
+
const min = parseFloat(paymentLink?.donation_settings?.amount.minimum || "0");
|
|
260
|
+
const max = paymentLink?.donation_settings?.amount.maximum ? parseFloat(paymentLink?.donation_settings?.amount.maximum) : Infinity;
|
|
258
261
|
const onChangeAmount = async ({
|
|
259
262
|
priceId,
|
|
260
263
|
amount
|
|
261
264
|
}) => {
|
|
265
|
+
if (Number(amount) < min || Number(amount) > max) {
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
if ((0, _util2.formatAmountPrecisionLimit)(amount, locale)) {
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
262
271
|
try {
|
|
263
272
|
const {
|
|
264
273
|
data
|
|
@@ -311,7 +320,9 @@ function PaymentInner({
|
|
|
311
320
|
}) : null, /* @__PURE__ */(0, _jsxRuntime.jsx)(_summary.default, {
|
|
312
321
|
items: state.checkoutSession.line_items,
|
|
313
322
|
trialInDays: state.checkoutSession.subscription_data?.trial_period_days || 0,
|
|
314
|
-
billingThreshold: Math.max(state.checkoutSession.subscription_data?.billing_threshold_amount || 0,
|
|
323
|
+
billingThreshold: Math.max(state.checkoutSession.subscription_data?.billing_threshold_amount || 0,
|
|
324
|
+
// @ts-ignore
|
|
325
|
+
state.checkoutSession.subscription_data?.min_stake_amount || 0),
|
|
315
326
|
showStaking: method.type === "arcblock",
|
|
316
327
|
currency,
|
|
317
328
|
onUpsell,
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import type { DonationSettings, TLineItemExpanded } from '@blocklet/payment-types';
|
|
3
|
-
export default function ProductDonation({ item, settings, onChange, }: {
|
|
2
|
+
import type { DonationSettings, TLineItemExpanded, TPaymentCurrency } from '@blocklet/payment-types';
|
|
3
|
+
export default function ProductDonation({ item, settings, onChange, currency, }: {
|
|
4
4
|
item: TLineItemExpanded;
|
|
5
5
|
settings: DonationSettings;
|
|
6
6
|
onChange: Function;
|
|
7
|
+
currency: TPaymentCurrency;
|
|
7
8
|
}): import("react").JSX.Element;
|
|
@@ -10,14 +10,17 @@ var _material = require("@mui/material");
|
|
|
10
10
|
var _ahooks = require("ahooks");
|
|
11
11
|
var _react = require("react");
|
|
12
12
|
var _switchButton = _interopRequireDefault(require("../components/switch-button"));
|
|
13
|
+
var _util = require("../libs/util");
|
|
13
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
15
|
function ProductDonation({
|
|
15
16
|
item,
|
|
16
17
|
settings,
|
|
17
|
-
onChange
|
|
18
|
+
onChange,
|
|
19
|
+
currency
|
|
18
20
|
}) {
|
|
19
21
|
const {
|
|
20
|
-
t
|
|
22
|
+
t,
|
|
23
|
+
locale
|
|
21
24
|
} = (0, _context.useLocaleContext)();
|
|
22
25
|
const preset = settings.amount.preset || settings.amount.presets?.[0] || "0";
|
|
23
26
|
const [state, setState] = (0, _ahooks.useSetState)({
|
|
@@ -64,6 +67,14 @@ function ProductDonation({
|
|
|
64
67
|
} = event.target;
|
|
65
68
|
const min = parseFloat(settings.amount.minimum || "0");
|
|
66
69
|
const max = settings.amount.maximum ? parseFloat(settings.amount.maximum) : Infinity;
|
|
70
|
+
const precision = currency?.maximum_precision || 6;
|
|
71
|
+
if ((0, _util.formatAmountPrecisionLimit)(value, locale)) {
|
|
72
|
+
setState({
|
|
73
|
+
input: value,
|
|
74
|
+
error: (0, _util.formatAmountPrecisionLimit)(value, locale, precision)
|
|
75
|
+
});
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
67
78
|
if (value < min || value > max) {
|
|
68
79
|
setState({
|
|
69
80
|
input: value,
|
package/lib/payment/summary.js
CHANGED
|
@@ -209,7 +209,8 @@ function PaymentSummary({
|
|
|
209
209
|
children: items.map(x => x.price.custom_unit_amount && onChangeAmount && donationSettings ? /* @__PURE__ */(0, _jsxRuntime.jsx)(_productDonation.default, {
|
|
210
210
|
item: x,
|
|
211
211
|
settings: donationSettings,
|
|
212
|
-
onChange: onChangeAmount
|
|
212
|
+
onChange: onChangeAmount,
|
|
213
|
+
currency
|
|
213
214
|
}, `${x.price_id}-${currency.id}`) : /* @__PURE__ */(0, _jsxRuntime.jsx)(_productItem.default, {
|
|
214
215
|
item: x,
|
|
215
216
|
items,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/payment-react",
|
|
3
|
-
"version": "1.14.
|
|
3
|
+
"version": "1.14.6",
|
|
4
4
|
"description": "Reusable react components for payment kit v2",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
"@babel/core": "^7.24.7",
|
|
92
92
|
"@babel/preset-env": "^7.24.7",
|
|
93
93
|
"@babel/preset-react": "^7.24.7",
|
|
94
|
-
"@blocklet/payment-types": "1.14.
|
|
94
|
+
"@blocklet/payment-types": "1.14.6",
|
|
95
95
|
"@storybook/addon-essentials": "^7.6.19",
|
|
96
96
|
"@storybook/addon-interactions": "^7.6.19",
|
|
97
97
|
"@storybook/addon-links": "^7.6.19",
|
|
@@ -120,5 +120,5 @@
|
|
|
120
120
|
"vite-plugin-babel": "^1.2.0",
|
|
121
121
|
"vite-plugin-node-polyfills": "^0.21.0"
|
|
122
122
|
},
|
|
123
|
-
"gitHead": "
|
|
123
|
+
"gitHead": "6c2ea2db76a8bb8413d0b802f35b50b650c7f6d2"
|
|
124
124
|
}
|
package/src/libs/util.ts
CHANGED
|
@@ -888,3 +888,11 @@ export function formatQuantityInventory(price: TPrice, quantity: string | number
|
|
|
888
888
|
}
|
|
889
889
|
return '';
|
|
890
890
|
}
|
|
891
|
+
|
|
892
|
+
export function formatAmountPrecisionLimit(amount: string, locale = 'en', precision: number = 6) {
|
|
893
|
+
const [, decimal] = amount.split('.');
|
|
894
|
+
if (decimal && decimal.length > precision) {
|
|
895
|
+
return t('common.amountPrecisionLimit', locale, { precision });
|
|
896
|
+
}
|
|
897
|
+
return '';
|
|
898
|
+
}
|
package/src/locales/en.tsx
CHANGED
|
@@ -87,6 +87,7 @@ export default flat({
|
|
|
87
87
|
donation: 'Donation',
|
|
88
88
|
quantityLimitPerCheckout: 'Exceed purchase limit',
|
|
89
89
|
quantityNotEnough: 'Exceed inventory',
|
|
90
|
+
amountPrecisionLimit: 'Amount decimal places must be less than or equal to {precision}',
|
|
90
91
|
},
|
|
91
92
|
payment: {
|
|
92
93
|
checkout: {
|
package/src/locales/zh.tsx
CHANGED
package/src/payment/index.tsx
CHANGED
|
@@ -19,7 +19,13 @@ import type { LiteralUnion } from 'type-fest';
|
|
|
19
19
|
|
|
20
20
|
import { usePaymentContext } from '../contexts/payment';
|
|
21
21
|
import api from '../libs/api';
|
|
22
|
-
import {
|
|
22
|
+
import {
|
|
23
|
+
findCurrency,
|
|
24
|
+
formatAmountPrecisionLimit,
|
|
25
|
+
formatError,
|
|
26
|
+
getStatementDescriptor,
|
|
27
|
+
isValidCountry,
|
|
28
|
+
} from '../libs/util';
|
|
23
29
|
import { CheckoutCallbacks, CheckoutContext, CheckoutFormData } from '../types';
|
|
24
30
|
import PaymentError from './error';
|
|
25
31
|
import CheckoutFooter from './footer';
|
|
@@ -164,7 +170,7 @@ export function PaymentInner({
|
|
|
164
170
|
goBack,
|
|
165
171
|
action,
|
|
166
172
|
}: MainProps) {
|
|
167
|
-
const { t } = useLocaleContext();
|
|
173
|
+
const { t, locale } = useLocaleContext();
|
|
168
174
|
const { settings, session } = usePaymentContext();
|
|
169
175
|
const [state, setState] = useSetState<{ checkoutSession: TCheckoutSessionExpanded }>({ checkoutSession });
|
|
170
176
|
|
|
@@ -245,7 +251,19 @@ export function PaymentInner({
|
|
|
245
251
|
}
|
|
246
252
|
};
|
|
247
253
|
|
|
254
|
+
const min = parseFloat(paymentLink?.donation_settings?.amount.minimum || '0');
|
|
255
|
+
const max = paymentLink?.donation_settings?.amount.maximum
|
|
256
|
+
? parseFloat(paymentLink?.donation_settings?.amount.maximum)
|
|
257
|
+
: Infinity;
|
|
258
|
+
|
|
248
259
|
const onChangeAmount = async ({ priceId, amount }: { priceId: string; amount: string }) => {
|
|
260
|
+
if (Number(amount) < min || Number(amount) > max) {
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if (formatAmountPrecisionLimit(amount, locale)) {
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
249
267
|
try {
|
|
250
268
|
const { data } = await api.put(`/api/checkout-sessions/${state.checkoutSession.id}/amount`, {
|
|
251
269
|
priceId,
|
|
@@ -282,6 +300,7 @@ export function PaymentInner({
|
|
|
282
300
|
trialInDays={state.checkoutSession.subscription_data?.trial_period_days || 0}
|
|
283
301
|
billingThreshold={Math.max(
|
|
284
302
|
state.checkoutSession.subscription_data?.billing_threshold_amount || 0,
|
|
303
|
+
// @ts-ignore
|
|
285
304
|
state.checkoutSession.subscription_data?.min_stake_amount || 0
|
|
286
305
|
)}
|
|
287
306
|
showStaking={method.type === 'arcblock'}
|
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
2
|
-
import type { DonationSettings, TLineItemExpanded } from '@blocklet/payment-types';
|
|
2
|
+
import type { DonationSettings, TLineItemExpanded, TPaymentCurrency } from '@blocklet/payment-types';
|
|
3
3
|
import { Box, Card, CardActionArea, FormControlLabel, Stack, TextField, Typography } from '@mui/material';
|
|
4
4
|
import { useSetState } from 'ahooks';
|
|
5
5
|
import { useEffect } from 'react';
|
|
6
6
|
|
|
7
7
|
import Switch from '../components/switch-button';
|
|
8
|
+
import { formatAmountPrecisionLimit } from '../libs/util';
|
|
8
9
|
|
|
9
10
|
export default function ProductDonation({
|
|
10
11
|
item,
|
|
11
12
|
settings,
|
|
12
13
|
onChange,
|
|
14
|
+
currency,
|
|
13
15
|
}: {
|
|
14
16
|
item: TLineItemExpanded;
|
|
15
17
|
settings: DonationSettings;
|
|
16
18
|
onChange: Function;
|
|
19
|
+
currency: TPaymentCurrency;
|
|
17
20
|
}) {
|
|
18
|
-
const { t } = useLocaleContext();
|
|
21
|
+
const { t, locale } = useLocaleContext();
|
|
19
22
|
const preset = settings.amount.preset || settings.amount.presets?.[0] || '0';
|
|
20
23
|
const [state, setState] = useSetState({
|
|
21
24
|
selected: preset,
|
|
@@ -44,6 +47,12 @@ export default function ProductDonation({
|
|
|
44
47
|
const { value } = event.target;
|
|
45
48
|
const min = parseFloat(settings.amount.minimum || '0');
|
|
46
49
|
const max = settings.amount.maximum ? parseFloat(settings.amount.maximum) : Infinity;
|
|
50
|
+
const precision = currency?.maximum_precision || 6;
|
|
51
|
+
|
|
52
|
+
if (formatAmountPrecisionLimit(value, locale)) {
|
|
53
|
+
setState({ input: value, error: formatAmountPrecisionLimit(value, locale, precision) });
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
47
56
|
|
|
48
57
|
if (value < min || value > max) {
|
|
49
58
|
setState({ input: value, error: t('payment.checkout.donation.between', { min, max }) });
|