@blocklet/payment-react 1.22.24 → 1.22.26

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.
@@ -133,6 +133,9 @@ function PaymentInner({
133
133
  const amountStr = fromTokenToUnit(amount, currency.decimal).toString();
134
134
  setBenefitsState({ amount: amountStr });
135
135
  try {
136
+ if (!amountStr || Number(amountStr) === 0) {
137
+ return;
138
+ }
136
139
  const { data } = await api.put(`/api/checkout-sessions/${state.checkoutSession.id}/amount`, {
137
140
  priceId,
138
141
  amount: amountStr
@@ -11,7 +11,11 @@ import { useTabNavigation } from "../hooks/keyboard.js";
11
11
  const DONATION_PRESET_KEY_BASE = "payment-donation-preset";
12
12
  const DONATION_CUSTOM_AMOUNT_KEY_BASE = "payment-donation-custom-amount";
13
13
  const formatAmount = (amount) => {
14
- return String(amount);
14
+ const str = String(amount);
15
+ if (!str || str === "0") return str;
16
+ const num = parseFloat(str);
17
+ if (Number.isNaN(num)) return str;
18
+ return num.toString();
15
19
  };
16
20
  export default function ProductDonation({
17
21
  item,
@@ -29,7 +33,8 @@ export default function ProductDonation({
29
33
  };
30
34
  const getSavedCustomAmount = () => {
31
35
  try {
32
- return localStorage.getItem(getUserStorageKey(DONATION_CUSTOM_AMOUNT_KEY_BASE)) || "";
36
+ const saved = localStorage.getItem(getUserStorageKey(DONATION_CUSTOM_AMOUNT_KEY_BASE)) || "";
37
+ return saved ? formatAmount(saved) : "";
33
38
  } catch (e) {
34
39
  console.warn("Failed to access localStorage", e);
35
40
  return "";
@@ -146,6 +146,9 @@ function PaymentInner({
146
146
  amount: amountStr
147
147
  });
148
148
  try {
149
+ if (!amountStr || Number(amountStr) === 0) {
150
+ return;
151
+ }
149
152
  const {
150
153
  data
151
154
  } = await _api.default.put(`/api/checkout-sessions/${state.checkoutSession.id}/amount`, {
@@ -18,7 +18,11 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
18
18
  const DONATION_PRESET_KEY_BASE = "payment-donation-preset";
19
19
  const DONATION_CUSTOM_AMOUNT_KEY_BASE = "payment-donation-custom-amount";
20
20
  const formatAmount = amount => {
21
- return String(amount);
21
+ const str = String(amount);
22
+ if (!str || str === "0") return str;
23
+ const num = parseFloat(str);
24
+ if (Number.isNaN(num)) return str;
25
+ return num.toString();
22
26
  };
23
27
  function ProductDonation({
24
28
  item,
@@ -42,7 +46,8 @@ function ProductDonation({
42
46
  };
43
47
  const getSavedCustomAmount = () => {
44
48
  try {
45
- return localStorage.getItem(getUserStorageKey(DONATION_CUSTOM_AMOUNT_KEY_BASE)) || "";
49
+ const saved = localStorage.getItem(getUserStorageKey(DONATION_CUSTOM_AMOUNT_KEY_BASE)) || "";
50
+ return saved ? formatAmount(saved) : "";
46
51
  } catch (e) {
47
52
  console.warn("Failed to access localStorage", e);
48
53
  return "";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/payment-react",
3
- "version": "1.22.24",
3
+ "version": "1.22.26",
4
4
  "description": "Reusable react components for payment kit v2",
5
5
  "keywords": [
6
6
  "react",
@@ -54,13 +54,13 @@
54
54
  }
55
55
  },
56
56
  "dependencies": {
57
- "@arcblock/bridge": "^3.2.10",
58
- "@arcblock/did-connect-react": "^3.2.10",
59
- "@arcblock/react-hooks": "^3.2.10",
60
- "@arcblock/ux": "^3.2.10",
57
+ "@arcblock/bridge": "^3.2.11",
58
+ "@arcblock/did-connect-react": "^3.2.11",
59
+ "@arcblock/react-hooks": "^3.2.11",
60
+ "@arcblock/ux": "^3.2.11",
61
61
  "@arcblock/ws": "^1.27.12",
62
- "@blocklet/theme": "^3.2.10",
63
- "@blocklet/ui-react": "^3.2.10",
62
+ "@blocklet/theme": "^3.2.11",
63
+ "@blocklet/ui-react": "^3.2.11",
64
64
  "@mui/icons-material": "^7.1.2",
65
65
  "@mui/lab": "7.0.0-beta.14",
66
66
  "@mui/material": "^7.1.2",
@@ -96,7 +96,7 @@
96
96
  "@babel/core": "^7.27.4",
97
97
  "@babel/preset-env": "^7.27.2",
98
98
  "@babel/preset-react": "^7.27.1",
99
- "@blocklet/payment-types": "1.22.24",
99
+ "@blocklet/payment-types": "1.22.26",
100
100
  "@storybook/addon-essentials": "^7.6.20",
101
101
  "@storybook/addon-interactions": "^7.6.20",
102
102
  "@storybook/addon-links": "^7.6.20",
@@ -127,5 +127,5 @@
127
127
  "vite-plugin-babel": "^1.3.1",
128
128
  "vite-plugin-node-polyfills": "^0.23.0"
129
129
  },
130
- "gitHead": "d24ce471f0bdbf4a0ccaaa5317d4c68b4ddfd3bf"
130
+ "gitHead": "eb36a8deed14f45ff5917cc61bcc44cda36d1906"
131
131
  }
@@ -163,6 +163,9 @@ function PaymentInner({
163
163
  const amountStr = fromTokenToUnit(amount, currency.decimal).toString();
164
164
  setBenefitsState({ amount: amountStr });
165
165
  try {
166
+ if (!amountStr || Number(amountStr) === 0) {
167
+ return;
168
+ }
166
169
  const { data } = await api.put(`/api/checkout-sessions/${state.checkoutSession.id}/amount`, {
167
170
  priceId,
168
171
  amount: amountStr,
@@ -15,7 +15,11 @@ const DONATION_PRESET_KEY_BASE = 'payment-donation-preset';
15
15
  const DONATION_CUSTOM_AMOUNT_KEY_BASE = 'payment-donation-custom-amount';
16
16
 
17
17
  const formatAmount = (amount: string | number): string => {
18
- return String(amount);
18
+ const str = String(amount);
19
+ if (!str || str === '0') return str;
20
+ const num = parseFloat(str);
21
+ if (Number.isNaN(num)) return str;
22
+ return num.toString();
19
23
  };
20
24
 
21
25
  export default function ProductDonation({
@@ -41,7 +45,8 @@ export default function ProductDonation({
41
45
 
42
46
  const getSavedCustomAmount = () => {
43
47
  try {
44
- return localStorage.getItem(getUserStorageKey(DONATION_CUSTOM_AMOUNT_KEY_BASE)) || '';
48
+ const saved = localStorage.getItem(getUserStorageKey(DONATION_CUSTOM_AMOUNT_KEY_BASE)) || '';
49
+ return saved ? formatAmount(saved) : '';
45
50
  } catch (e) {
46
51
  console.warn('Failed to access localStorage', e);
47
52
  return '';