@blocklet/payment-react 1.26.0 → 1.26.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.
- package/es/checkout-v2/components/left/product-item-card.js +4 -4
- package/es/checkout-v2/panels/left/credit-topup-panel.js +1 -5
- package/es/checkout-v2/utils/format.js +2 -2
- package/lib/checkout-v2/components/left/product-item-card.js +4 -4
- package/lib/checkout-v2/panels/left/credit-topup-panel.js +1 -5
- package/lib/checkout-v2/utils/format.js +2 -2
- package/package.json +4 -4
- package/src/checkout-v2/components/left/product-item-card.tsx +12 -4
- package/src/checkout-v2/panels/left/credit-topup-panel.tsx +1 -5
- package/src/checkout-v2/utils/format.ts +3 -2
|
@@ -73,7 +73,7 @@ export default function ProductItemCard({
|
|
|
73
73
|
const tokenAmount = baseUsd * quantity / rate;
|
|
74
74
|
const abs = Math.abs(tokenAmount);
|
|
75
75
|
const precision = abs > 0 && abs < 0.01 ? 6 : 2;
|
|
76
|
-
return tokenAmount.toLocaleString("en-US", { minimumFractionDigits: 0, maximumFractionDigits: precision }).replace(
|
|
76
|
+
return tokenAmount.toLocaleString("en-US", { minimumFractionDigits: 0, maximumFractionDigits: precision }).replace(/(\.\d*?)0+$/, "$1").replace(/\.$/, "") || "0";
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
}
|
|
@@ -104,7 +104,7 @@ export default function ProductItemCard({
|
|
|
104
104
|
const discAmount = numericTotal * couponDetails.percent_off / 100;
|
|
105
105
|
const abs = Math.abs(discAmount);
|
|
106
106
|
const precision = abs > 0 && abs < 0.01 ? 6 : 2;
|
|
107
|
-
return `${discAmount.toLocaleString("en-US", { minimumFractionDigits: 0, maximumFractionDigits: precision }).replace(
|
|
107
|
+
return `${discAmount.toLocaleString("en-US", { minimumFractionDigits: 0, maximumFractionDigits: precision }).replace(/(\.\d*?)0+$/, "$1").replace(/\.$/, "") || "0"} ${currency?.symbol || ""}`;
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
if (item.discount_amounts?.length > 0 && currency) {
|
|
@@ -153,7 +153,7 @@ export default function ProductItemCard({
|
|
|
153
153
|
const tokenAmount = baseUsd / rate;
|
|
154
154
|
const abs = Math.abs(tokenAmount);
|
|
155
155
|
const precision = abs > 0 && abs < 0.01 ? 6 : 2;
|
|
156
|
-
const formatted = tokenAmount.toLocaleString("en-US", { minimumFractionDigits: 0, maximumFractionDigits: precision }).replace(
|
|
156
|
+
const formatted = tokenAmount.toLocaleString("en-US", { minimumFractionDigits: 0, maximumFractionDigits: precision }).replace(/(\.\d*?)0+$/, "$1").replace(/\.$/, "") || "0";
|
|
157
157
|
return `${formatted} ${currency?.symbol || ""} ${slashText}`;
|
|
158
158
|
}
|
|
159
159
|
}
|
|
@@ -179,7 +179,7 @@ export default function ProductItemCard({
|
|
|
179
179
|
const tokenAmount = baseUsd / rate;
|
|
180
180
|
const abs = Math.abs(tokenAmount);
|
|
181
181
|
const precision = abs > 0 && abs < 0.01 ? 6 : 2;
|
|
182
|
-
const formatted = tokenAmount.toLocaleString("en-US", { minimumFractionDigits: 0, maximumFractionDigits: precision }).replace(
|
|
182
|
+
const formatted = tokenAmount.toLocaleString("en-US", { minimumFractionDigits: 0, maximumFractionDigits: precision }).replace(/(\.\d*?)0+$/, "$1").replace(/\.$/, "") || "0";
|
|
183
183
|
return `${formatted} ${currency?.symbol || ""} ${originalSlash}`;
|
|
184
184
|
}
|
|
185
185
|
}
|
|
@@ -116,12 +116,8 @@ export default function CreditTopupPanel() {
|
|
|
116
116
|
const intervalDisplay = intervalValue === 1 ? t(`common.${intervalUnit}`) : `${intervalValue} ${t(`common.${intervalUnit}s`)}`;
|
|
117
117
|
return scheduleConfig.expire_with_next_grant ? t("payment.checkout.credit.schedule.withRefresh", { amount: formattedAmount, interval: intervalDisplay }) : t("payment.checkout.credit.schedule.periodic", { amount: formattedAmount, interval: intervalDisplay });
|
|
118
118
|
}
|
|
119
|
-
const productDesc = product?.description || "";
|
|
120
|
-
if (productDesc && productDesc.length > 10 && productDesc !== creditName) {
|
|
121
|
-
return productDesc;
|
|
122
|
-
}
|
|
123
119
|
return "";
|
|
124
|
-
}, [creditAmount, currencySymbol, hasSchedule, scheduleConfig,
|
|
120
|
+
}, [creditAmount, currencySymbol, hasSchedule, scheduleConfig, t]);
|
|
125
121
|
const validityText = useMemo(() => {
|
|
126
122
|
if (!hasExpiry) return "";
|
|
127
123
|
return t("payment.checkout.creditTopup.validFor", {
|
|
@@ -20,7 +20,7 @@ export function formatTokenAmount(unitAmount, currency) {
|
|
|
20
20
|
const abs = Math.abs(num);
|
|
21
21
|
const precision = abs > 0 && abs < 0.01 ? 6 : 2;
|
|
22
22
|
const formatted = num.toLocaleString("en-US", { minimumFractionDigits: 0, maximumFractionDigits: precision });
|
|
23
|
-
return formatted.replace(
|
|
23
|
+
return formatted.replace(/(\.\d*?)0+$/, "$1").replace(/\.$/, "") || "0";
|
|
24
24
|
} catch {
|
|
25
25
|
return "0";
|
|
26
26
|
}
|
|
@@ -51,7 +51,7 @@ export function formatDynamicUnitPrice(price, currency, exchangeRate) {
|
|
|
51
51
|
const tokenAmount = baseUsd / rate;
|
|
52
52
|
const abs = Math.abs(tokenAmount);
|
|
53
53
|
const precision = abs > 0 && abs < 0.01 ? 6 : 2;
|
|
54
|
-
return tokenAmount.toLocaleString("en-US", { minimumFractionDigits: 0, maximumFractionDigits: precision }).replace(
|
|
54
|
+
return tokenAmount.toLocaleString("en-US", { minimumFractionDigits: 0, maximumFractionDigits: precision }).replace(/(\.\d*?)0+$/, "$1").replace(/\.$/, "") || "0";
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
}
|
|
@@ -70,7 +70,7 @@ function ProductItemCard({
|
|
|
70
70
|
return tokenAmount.toLocaleString("en-US", {
|
|
71
71
|
minimumFractionDigits: 0,
|
|
72
72
|
maximumFractionDigits: precision
|
|
73
|
-
}).replace(
|
|
73
|
+
}).replace(/(\.\d*?)0+$/, "$1").replace(/\.$/, "") || "0";
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
}
|
|
@@ -107,7 +107,7 @@ function ProductItemCard({
|
|
|
107
107
|
return `${discAmount.toLocaleString("en-US", {
|
|
108
108
|
minimumFractionDigits: 0,
|
|
109
109
|
maximumFractionDigits: precision
|
|
110
|
-
}).replace(
|
|
110
|
+
}).replace(/(\.\d*?)0+$/, "$1").replace(/\.$/, "") || "0"} ${currency?.symbol || ""}`;
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
if (item.discount_amounts?.length > 0 && currency) {
|
|
@@ -166,7 +166,7 @@ function ProductItemCard({
|
|
|
166
166
|
const formatted = tokenAmount.toLocaleString("en-US", {
|
|
167
167
|
minimumFractionDigits: 0,
|
|
168
168
|
maximumFractionDigits: precision
|
|
169
|
-
}).replace(
|
|
169
|
+
}).replace(/(\.\d*?)0+$/, "$1").replace(/\.$/, "") || "0";
|
|
170
170
|
return `${formatted} ${currency?.symbol || ""} ${slashText}`;
|
|
171
171
|
}
|
|
172
172
|
}
|
|
@@ -200,7 +200,7 @@ function ProductItemCard({
|
|
|
200
200
|
const formatted = tokenAmount.toLocaleString("en-US", {
|
|
201
201
|
minimumFractionDigits: 0,
|
|
202
202
|
maximumFractionDigits: precision
|
|
203
|
-
}).replace(
|
|
203
|
+
}).replace(/(\.\d*?)0+$/, "$1").replace(/\.$/, "") || "0";
|
|
204
204
|
return `${formatted} ${currency?.symbol || ""} ${originalSlash}`;
|
|
205
205
|
}
|
|
206
206
|
}
|
|
@@ -144,12 +144,8 @@ function CreditTopupPanel() {
|
|
|
144
144
|
interval: intervalDisplay
|
|
145
145
|
});
|
|
146
146
|
}
|
|
147
|
-
const productDesc = product?.description || "";
|
|
148
|
-
if (productDesc && productDesc.length > 10 && productDesc !== creditName) {
|
|
149
|
-
return productDesc;
|
|
150
|
-
}
|
|
151
147
|
return "";
|
|
152
|
-
}, [creditAmount, currencySymbol, hasSchedule, scheduleConfig,
|
|
148
|
+
}, [creditAmount, currencySymbol, hasSchedule, scheduleConfig, t]);
|
|
153
149
|
const validityText = (0, _react.useMemo)(() => {
|
|
154
150
|
if (!hasExpiry) return "";
|
|
155
151
|
return t("payment.checkout.creditTopup.validFor", {
|
|
@@ -35,7 +35,7 @@ function formatTokenAmount(unitAmount, currency) {
|
|
|
35
35
|
minimumFractionDigits: 0,
|
|
36
36
|
maximumFractionDigits: precision
|
|
37
37
|
});
|
|
38
|
-
return formatted.replace(
|
|
38
|
+
return formatted.replace(/(\.\d*?)0+$/, "$1").replace(/\.$/, "") || "0";
|
|
39
39
|
} catch {
|
|
40
40
|
return "0";
|
|
41
41
|
}
|
|
@@ -69,7 +69,7 @@ function formatDynamicUnitPrice(price, currency, exchangeRate) {
|
|
|
69
69
|
return tokenAmount.toLocaleString("en-US", {
|
|
70
70
|
minimumFractionDigits: 0,
|
|
71
71
|
maximumFractionDigits: precision
|
|
72
|
-
}).replace(
|
|
72
|
+
}).replace(/(\.\d*?)0+$/, "$1").replace(/\.$/, "") || "0";
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/payment-react",
|
|
3
|
-
"version": "1.26.
|
|
3
|
+
"version": "1.26.1",
|
|
4
4
|
"description": "Reusable react components for payment kit v2",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"@arcblock/react-hooks": "^3.5.1",
|
|
60
60
|
"@arcblock/ux": "^3.5.1",
|
|
61
61
|
"@arcblock/ws": "^1.28.5",
|
|
62
|
-
"@blocklet/payment-react-headless": "1.26.
|
|
62
|
+
"@blocklet/payment-react-headless": "1.26.1",
|
|
63
63
|
"@blocklet/theme": "^3.5.1",
|
|
64
64
|
"@blocklet/ui-react": "^3.5.1",
|
|
65
65
|
"@mui/icons-material": "^7.1.2",
|
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
"@babel/core": "^7.27.4",
|
|
98
98
|
"@babel/preset-env": "^7.27.2",
|
|
99
99
|
"@babel/preset-react": "^7.27.1",
|
|
100
|
-
"@blocklet/payment-types": "1.26.
|
|
100
|
+
"@blocklet/payment-types": "1.26.1",
|
|
101
101
|
"@storybook/addon-essentials": "^7.6.20",
|
|
102
102
|
"@storybook/addon-interactions": "^7.6.20",
|
|
103
103
|
"@storybook/addon-links": "^7.6.20",
|
|
@@ -128,5 +128,5 @@
|
|
|
128
128
|
"vite-plugin-babel": "^1.3.1",
|
|
129
129
|
"vite-plugin-node-polyfills": "^0.23.0"
|
|
130
130
|
},
|
|
131
|
-
"gitHead": "
|
|
131
|
+
"gitHead": "1ba42f376f040b1214d992420cda37053fc14288"
|
|
132
132
|
}
|
|
@@ -109,7 +109,8 @@ export default function ProductItemCard({
|
|
|
109
109
|
return (
|
|
110
110
|
tokenAmount
|
|
111
111
|
.toLocaleString('en-US', { minimumFractionDigits: 0, maximumFractionDigits: precision })
|
|
112
|
-
.replace(
|
|
112
|
+
.replace(/(\.\d*?)0+$/, '$1')
|
|
113
|
+
.replace(/\.$/, '') || '0'
|
|
113
114
|
);
|
|
114
115
|
}
|
|
115
116
|
}
|
|
@@ -147,7 +148,12 @@ export default function ProductItemCard({
|
|
|
147
148
|
const discAmount = (numericTotal * couponDetails.percent_off) / 100;
|
|
148
149
|
const abs = Math.abs(discAmount);
|
|
149
150
|
const precision = abs > 0 && abs < 0.01 ? 6 : 2;
|
|
150
|
-
return `${
|
|
151
|
+
return `${
|
|
152
|
+
discAmount
|
|
153
|
+
.toLocaleString('en-US', { minimumFractionDigits: 0, maximumFractionDigits: precision })
|
|
154
|
+
.replace(/(\.\d*?)0+$/, '$1')
|
|
155
|
+
.replace(/\.$/, '') || '0'
|
|
156
|
+
} ${currency?.symbol || ''}`;
|
|
151
157
|
}
|
|
152
158
|
}
|
|
153
159
|
if ((item as any).discount_amounts?.length > 0 && currency) {
|
|
@@ -207,7 +213,8 @@ export default function ProductItemCard({
|
|
|
207
213
|
const formatted =
|
|
208
214
|
tokenAmount
|
|
209
215
|
.toLocaleString('en-US', { minimumFractionDigits: 0, maximumFractionDigits: precision })
|
|
210
|
-
.replace(
|
|
216
|
+
.replace(/(\.\d*?)0+$/, '$1')
|
|
217
|
+
.replace(/\.$/, '') || '0';
|
|
211
218
|
return `${formatted} ${currency?.symbol || ''} ${slashText}`;
|
|
212
219
|
}
|
|
213
220
|
}
|
|
@@ -238,7 +245,8 @@ export default function ProductItemCard({
|
|
|
238
245
|
const formatted =
|
|
239
246
|
tokenAmount
|
|
240
247
|
.toLocaleString('en-US', { minimumFractionDigits: 0, maximumFractionDigits: precision })
|
|
241
|
-
.replace(
|
|
248
|
+
.replace(/(\.\d*?)0+$/, '$1')
|
|
249
|
+
.replace(/\.$/, '') || '0';
|
|
242
250
|
return `${formatted} ${currency?.symbol || ''} ${originalSlash}`;
|
|
243
251
|
}
|
|
244
252
|
}
|
|
@@ -154,12 +154,8 @@ export default function CreditTopupPanel() {
|
|
|
154
154
|
? t('payment.checkout.credit.schedule.withRefresh', { amount: formattedAmount, interval: intervalDisplay })
|
|
155
155
|
: t('payment.checkout.credit.schedule.periodic', { amount: formattedAmount, interval: intervalDisplay });
|
|
156
156
|
}
|
|
157
|
-
const productDesc = product?.description || '';
|
|
158
|
-
if (productDesc && productDesc.length > 10 && productDesc !== creditName) {
|
|
159
|
-
return productDesc;
|
|
160
|
-
}
|
|
161
157
|
return '';
|
|
162
|
-
}, [creditAmount, currencySymbol, hasSchedule, scheduleConfig,
|
|
158
|
+
}, [creditAmount, currencySymbol, hasSchedule, scheduleConfig, t]);
|
|
163
159
|
|
|
164
160
|
// Validity text: "Credits are valid for X days after purchase."
|
|
165
161
|
const validityText = useMemo(() => {
|
|
@@ -29,7 +29,7 @@ export function formatTokenAmount(unitAmount: string | number | bigint, currency
|
|
|
29
29
|
const abs = Math.abs(num);
|
|
30
30
|
const precision = abs > 0 && abs < 0.01 ? 6 : 2;
|
|
31
31
|
const formatted = num.toLocaleString('en-US', { minimumFractionDigits: 0, maximumFractionDigits: precision });
|
|
32
|
-
return formatted.replace(
|
|
32
|
+
return formatted.replace(/(\.\d*?)0+$/, '$1').replace(/\.$/, '') || '0';
|
|
33
33
|
} catch {
|
|
34
34
|
return '0';
|
|
35
35
|
}
|
|
@@ -90,7 +90,8 @@ export function formatDynamicUnitPrice(
|
|
|
90
90
|
return (
|
|
91
91
|
tokenAmount
|
|
92
92
|
.toLocaleString('en-US', { minimumFractionDigits: 0, maximumFractionDigits: precision })
|
|
93
|
-
.replace(
|
|
93
|
+
.replace(/(\.\d*?)0+$/, '$1')
|
|
94
|
+
.replace(/\.$/, '') || '0'
|
|
94
95
|
);
|
|
95
96
|
}
|
|
96
97
|
}
|