@blocklet/payment-react 1.13.284 → 1.13.286

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.
@@ -46,15 +46,23 @@ export default function PricingTable({ table, alignItems, interval, mode, onSele
46
46
  const {
47
47
  settings: { paymentMethods = [] }
48
48
  } = usePaymentContext();
49
- const [currency, setCurrency] = useState(table.currency);
49
+ const [currency, setCurrency] = useState(table.currency || {});
50
50
  const { recurring, grouped } = groupItemsByRecurring(table.items);
51
51
  const [state, setState] = useSetState({ interval });
52
52
  const currencyMap = useMemo(() => {
53
- const { payment_currencies: paymentCurrencies = [] } = paymentMethods[0];
54
- return paymentCurrencies.reduce((acc, x) => {
55
- acc[x.id] = x;
56
- return acc;
57
- }, {});
53
+ if (!paymentMethods || paymentMethods.length === 0) {
54
+ return {};
55
+ }
56
+ const ans = {};
57
+ paymentMethods.forEach((paymentMethod) => {
58
+ const { payment_currencies: paymentCurrencies = [] } = paymentMethod;
59
+ if (paymentCurrencies && paymentCurrencies.length > 0) {
60
+ paymentCurrencies.forEach((x) => {
61
+ ans[x.id] = x;
62
+ });
63
+ }
64
+ });
65
+ return ans;
58
66
  }, [paymentMethods]);
59
67
  const currencyList = useMemo(() => {
60
68
  const visited = {};
@@ -66,7 +74,7 @@ export default function PricingTable({ table, alignItems, interval, mode, onSele
66
74
  visited[c?.currency_id] = true;
67
75
  });
68
76
  });
69
- return Object.keys(visited).map((x) => currencyMap[x]);
77
+ return Object.keys(visited).map((x) => currencyMap[x]).filter((v) => v);
70
78
  }, [currencyMap, grouped, state.interval]);
71
79
  useEffect(() => {
72
80
  if (table) {
@@ -164,11 +172,11 @@ export default function PricingTable({ table, alignItems, interval, mode, onSele
164
172
  currencyList.length > 1 && /* @__PURE__ */ jsx(
165
173
  Select,
166
174
  {
167
- value: currency.id,
168
- onChange: (e) => setCurrency(currencyList.find((v) => v.id === e.target.value)),
175
+ value: currency?.id,
176
+ onChange: (e) => setCurrency(currencyList.find((v) => v?.id === e.target.value)),
169
177
  size: "small",
170
178
  sx: { m: 1, width: 120 },
171
- children: currencyList.map((x) => /* @__PURE__ */ jsx(MenuItem, { value: x.id, children: /* @__PURE__ */ jsx(Typography, { color: x.id === currency.id ? "text.primary" : "text.secondary", children: x.symbol }) }, x.id))
179
+ children: currencyList.map((x) => /* @__PURE__ */ jsx(MenuItem, { value: x?.id, children: /* @__PURE__ */ jsx(Typography, { color: x?.id === currency?.id ? "text.primary" : "text.secondary", children: x?.symbol }) }, x?.id))
172
180
  }
173
181
  )
174
182
  ] }),
@@ -314,7 +322,7 @@ export default function PricingTable({ table, alignItems, interval, mode, onSele
314
322
  )
315
323
  ] }, f.name))
316
324
  ] }) }),
317
- /* @__PURE__ */ jsx(Subscribe, { x, action, onSelect, currencyId: currency.id })
325
+ /* @__PURE__ */ jsx(Subscribe, { x, action, onSelect, currencyId: currency?.id })
318
326
  ]
319
327
  },
320
328
  x?.price_id
@@ -0,0 +1,4 @@
1
+ export declare const RefundType: {
2
+ refund: string;
3
+ stakeReturn: string;
4
+ };
@@ -0,0 +1,4 @@
1
+ export const RefundType = {
2
+ refund: "refund",
3
+ stakeReturn: "stake_return"
4
+ };
package/es/locales/en.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import flat from "flat";
2
+ import { RefundType } from "../libs/constant.js";
2
3
  export default flat({
3
4
  common: {
4
5
  id: "ID",
@@ -79,7 +80,8 @@ export default flat({
79
80
  days: "days",
80
81
  weeks: "weeks",
81
82
  months: "months",
82
- years: "years"
83
+ years: "years",
84
+ type: "type"
83
85
  },
84
86
  payment: {
85
87
  checkout: {
@@ -283,5 +285,11 @@ export default flat({
283
285
  upcoming: "Upcoming invoice"
284
286
  }
285
287
  }
288
+ },
289
+ refund: {
290
+ type: {
291
+ [RefundType.refund]: "Refund",
292
+ [RefundType.stakeReturn]: "Stake Return"
293
+ }
286
294
  }
287
295
  });
package/es/locales/zh.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import flat from "flat";
2
+ import { RefundType } from "../libs/constant.js";
2
3
  export default flat({
3
4
  common: {
4
5
  id: "ID",
@@ -79,7 +80,8 @@ export default flat({
79
80
  days: "\u5929",
80
81
  weeks: "\u5468",
81
82
  months: "\u6708",
82
- years: "\u5E74"
83
+ years: "\u5E74",
84
+ type: "\u7C7B\u578B"
83
85
  },
84
86
  payment: {
85
87
  checkout: {
@@ -283,5 +285,11 @@ export default flat({
283
285
  upcoming: "\u672A\u6765\u8D26\u5355"
284
286
  }
285
287
  }
288
+ },
289
+ refund: {
290
+ type: {
291
+ [RefundType.refund]: "\u9000\u6B3E",
292
+ [RefundType.stakeReturn]: "\u9000\u62BC\u91D1"
293
+ }
286
294
  }
287
295
  });
@@ -326,7 +326,9 @@ export const Root = styled(Box)`
326
326
  position: absolute;
327
327
  right: 0;
328
328
  top: 0;
329
- transition: background-color 0.15s ease, box-shadow 0.15s ease-out;
329
+ transition:
330
+ background-color 0.15s ease,
331
+ box-shadow 0.15s ease-out;
330
332
  }
331
333
  .cko-product {
332
334
  margin-top: ${(props) => props.mode === "standalone" ? "64px" : "0"};
@@ -54,7 +54,7 @@ function PricingTable({
54
54
  paymentMethods = []
55
55
  }
56
56
  } = (0, _payment.usePaymentContext)();
57
- const [currency, setCurrency] = (0, _react.useState)(table.currency);
57
+ const [currency, setCurrency] = (0, _react.useState)(table.currency || {});
58
58
  const {
59
59
  recurring,
60
60
  grouped
@@ -63,13 +63,21 @@ function PricingTable({
63
63
  interval
64
64
  });
65
65
  const currencyMap = (0, _react.useMemo)(() => {
66
- const {
67
- payment_currencies: paymentCurrencies = []
68
- } = paymentMethods[0];
69
- return paymentCurrencies.reduce((acc, x) => {
70
- acc[x.id] = x;
71
- return acc;
72
- }, {});
66
+ if (!paymentMethods || paymentMethods.length === 0) {
67
+ return {};
68
+ }
69
+ const ans = {};
70
+ paymentMethods.forEach(paymentMethod => {
71
+ const {
72
+ payment_currencies: paymentCurrencies = []
73
+ } = paymentMethod;
74
+ if (paymentCurrencies && paymentCurrencies.length > 0) {
75
+ paymentCurrencies.forEach(x => {
76
+ ans[x.id] = x;
77
+ });
78
+ }
79
+ });
80
+ return ans;
73
81
  }, [paymentMethods]);
74
82
  const currencyList = (0, _react.useMemo)(() => {
75
83
  const visited = {};
@@ -81,7 +89,7 @@ function PricingTable({
81
89
  visited[c?.currency_id] = true;
82
90
  });
83
91
  });
84
- return Object.keys(visited).map(x => currencyMap[x]);
92
+ return Object.keys(visited).map(x => currencyMap[x]).filter(v => v);
85
93
  }, [currencyMap, grouped, state.interval]);
86
94
  (0, _react.useEffect)(() => {
87
95
  if (table) {
@@ -176,20 +184,20 @@ function PricingTable({
176
184
  children: (0, _util.formatRecurring)(recurring[x], true, "", locale)
177
185
  }, x))
178
186
  }), currencyList.length > 1 && /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Select, {
179
- value: currency.id,
180
- onChange: e => setCurrency(currencyList.find(v => v.id === e.target.value)),
187
+ value: currency?.id,
188
+ onChange: e => setCurrency(currencyList.find(v => v?.id === e.target.value)),
181
189
  size: "small",
182
190
  sx: {
183
191
  m: 1,
184
192
  width: 120
185
193
  },
186
194
  children: currencyList.map(x => /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.MenuItem, {
187
- value: x.id,
195
+ value: x?.id,
188
196
  children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
189
- color: x.id === currency.id ? "text.primary" : "text.secondary",
190
- children: x.symbol
197
+ color: x?.id === currency?.id ? "text.primary" : "text.secondary",
198
+ children: x?.symbol
191
199
  })
192
- }, x.id))
200
+ }, x?.id))
193
201
  })]
194
202
  }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Stack, {
195
203
  flexWrap: "wrap",
@@ -337,7 +345,7 @@ function PricingTable({
337
345
  x,
338
346
  action,
339
347
  onSelect,
340
- currencyId: currency.id
348
+ currencyId: currency?.id
341
349
  })]
342
350
  }, x?.price_id);
343
351
  })
@@ -0,0 +1,4 @@
1
+ export declare const RefundType: {
2
+ refund: string;
3
+ stakeReturn: string;
4
+ };
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.RefundType = void 0;
7
+ const RefundType = exports.RefundType = {
8
+ refund: "refund",
9
+ stakeReturn: "stake_return"
10
+ };
package/lib/locales/en.js CHANGED
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
 
7
7
  var _flat = _interopRequireDefault(require("flat"));
8
+ var _constant = require("../libs/constant");
8
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
10
  module.exports = (0, _flat.default)({
10
11
  common: {
@@ -86,7 +87,8 @@ module.exports = (0, _flat.default)({
86
87
  days: "days",
87
88
  weeks: "weeks",
88
89
  months: "months",
89
- years: "years"
90
+ years: "years",
91
+ type: "type"
90
92
  },
91
93
  payment: {
92
94
  checkout: {
@@ -290,5 +292,11 @@ module.exports = (0, _flat.default)({
290
292
  upcoming: "Upcoming invoice"
291
293
  }
292
294
  }
295
+ },
296
+ refund: {
297
+ type: {
298
+ [_constant.RefundType.refund]: "Refund",
299
+ [_constant.RefundType.stakeReturn]: "Stake Return"
300
+ }
293
301
  }
294
302
  });
package/lib/locales/zh.js CHANGED
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
 
7
7
  var _flat = _interopRequireDefault(require("flat"));
8
+ var _constant = require("../libs/constant");
8
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
10
  module.exports = (0, _flat.default)({
10
11
  common: {
@@ -86,7 +87,8 @@ module.exports = (0, _flat.default)({
86
87
  days: "\u5929",
87
88
  weeks: "\u5468",
88
89
  months: "\u6708",
89
- years: "\u5E74"
90
+ years: "\u5E74",
91
+ type: "\u7C7B\u578B"
90
92
  },
91
93
  payment: {
92
94
  checkout: {
@@ -290,5 +292,11 @@ module.exports = (0, _flat.default)({
290
292
  upcoming: "\u672A\u6765\u8D26\u5355"
291
293
  }
292
294
  }
295
+ },
296
+ refund: {
297
+ type: {
298
+ [_constant.RefundType.refund]: "\u9000\u6B3E",
299
+ [_constant.RefundType.stakeReturn]: "\u9000\u62BC\u91D1"
300
+ }
293
301
  }
294
302
  });
@@ -401,7 +401,9 @@ const Root = exports.Root = (0, _system.styled)(_material.Box)`
401
401
  position: absolute;
402
402
  right: 0;
403
403
  top: 0;
404
- transition: background-color 0.15s ease, box-shadow 0.15s ease-out;
404
+ transition:
405
+ background-color 0.15s ease,
406
+ box-shadow 0.15s ease-out;
405
407
  }
406
408
  .cko-product {
407
409
  margin-top: ${props => props.mode === "standalone" ? "64px" : "0"};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/payment-react",
3
- "version": "1.13.284",
3
+ "version": "1.13.286",
4
4
  "description": "Reusable react components for payment kit v2",
5
5
  "keywords": [
6
6
  "react",
@@ -86,12 +86,12 @@
86
86
  "access": "public"
87
87
  },
88
88
  "devDependencies": {
89
- "@arcblock/eslint-config-ts": "^0.3.0",
89
+ "@arcblock/eslint-config-ts": "^0.3.2",
90
90
  "@babel/cli": "^7.24.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.13.284",
94
+ "@blocklet/payment-types": "1.13.286",
95
95
  "@storybook/addon-essentials": "^7.6.19",
96
96
  "@storybook/addon-interactions": "^7.6.19",
97
97
  "@storybook/addon-links": "^7.6.19",
@@ -107,7 +107,7 @@
107
107
  "glob": "^10.4.1",
108
108
  "import-sort-style-module": "^6.0.0",
109
109
  "jest": "^29.7.0",
110
- "prettier": "^2.8.8",
110
+ "prettier": "^3.3.2",
111
111
  "prettier-plugin-import-sort": "^0.0.7",
112
112
  "react": "^18.3.1",
113
113
  "react-dom": "^18.3.1",
@@ -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": "c844c5590104d35d4bffedddec6f909684bacc4b"
123
+ "gitHead": "fa41b3d6a308d9405f56717beee2f030a91ddec3"
124
124
  }
@@ -64,15 +64,23 @@ export default function PricingTable({ table, alignItems, interval, mode, onSele
64
64
  const {
65
65
  settings: { paymentMethods = [] },
66
66
  } = usePaymentContext();
67
- const [currency, setCurrency] = useState(table.currency);
67
+ const [currency, setCurrency] = useState(table.currency || {});
68
68
  const { recurring, grouped } = groupItemsByRecurring(table.items);
69
69
  const [state, setState] = useSetState({ interval });
70
70
  const currencyMap = useMemo(() => {
71
- const { payment_currencies: paymentCurrencies = [] } = paymentMethods[0];
72
- return paymentCurrencies.reduce((acc: any, x: { id: string; symbol: string }) => {
73
- acc[x.id] = x;
74
- return acc;
75
- }, {});
71
+ if (!paymentMethods || paymentMethods.length === 0) {
72
+ return {};
73
+ }
74
+ const ans: { [key: string]: any } = {};
75
+ paymentMethods.forEach((paymentMethod) => {
76
+ const { payment_currencies: paymentCurrencies = [] } = paymentMethod;
77
+ if (paymentCurrencies && paymentCurrencies.length > 0) {
78
+ paymentCurrencies.forEach((x: { id: string; symbol: string }) => {
79
+ ans[x.id] = x;
80
+ });
81
+ }
82
+ });
83
+ return ans;
76
84
  }, [paymentMethods]);
77
85
 
78
86
  const currencyList = useMemo(() => {
@@ -85,7 +93,9 @@ export default function PricingTable({ table, alignItems, interval, mode, onSele
85
93
  visited[c?.currency_id] = true;
86
94
  });
87
95
  });
88
- return Object.keys(visited).map((x) => currencyMap[x]);
96
+ return Object.keys(visited)
97
+ .map((x) => currencyMap[x])
98
+ .filter((v) => v);
89
99
  }, [currencyMap, grouped, state.interval]);
90
100
 
91
101
  useEffect(() => {
@@ -182,13 +192,15 @@ export default function PricingTable({ table, alignItems, interval, mode, onSele
182
192
  )}
183
193
  {currencyList.length > 1 && (
184
194
  <Select
185
- value={currency.id}
186
- onChange={(e) => setCurrency(currencyList.find((v) => v.id === e.target.value))}
195
+ value={currency?.id}
196
+ onChange={(e) => setCurrency(currencyList.find((v) => v?.id === e.target.value))}
187
197
  size="small"
188
198
  sx={{ m: 1, width: 120 }}>
189
199
  {currencyList.map((x) => (
190
- <MenuItem key={x.id} value={x.id}>
191
- <Typography color={x.id === currency.id ? 'text.primary' : 'text.secondary'}>{x.symbol}</Typography>
200
+ <MenuItem key={x?.id} value={x?.id}>
201
+ <Typography color={x?.id === currency?.id ? 'text.primary' : 'text.secondary'}>
202
+ {x?.symbol}
203
+ </Typography>
192
204
  </MenuItem>
193
205
  ))}
194
206
  </Select>
@@ -324,7 +336,7 @@ export default function PricingTable({ table, alignItems, interval, mode, onSele
324
336
  </List>
325
337
  </Box>
326
338
  )}
327
- <Subscribe x={x} action={action} onSelect={onSelect} currencyId={currency.id} />
339
+ <Subscribe x={x} action={action} onSelect={onSelect} currencyId={currency?.id} />
328
340
  </Stack>
329
341
  );
330
342
  }
@@ -0,0 +1,4 @@
1
+ export const RefundType = {
2
+ refund: 'refund',
3
+ stakeReturn: 'stake_return',
4
+ };
@@ -1,5 +1,7 @@
1
1
  import flat from 'flat';
2
2
 
3
+ import { RefundType } from '../libs/constant';
4
+
3
5
  export default flat({
4
6
  common: {
5
7
  id: 'ID',
@@ -81,6 +83,7 @@ export default flat({
81
83
  weeks: 'weeks',
82
84
  months: 'months',
83
85
  years: 'years',
86
+ type: 'type',
84
87
  },
85
88
  payment: {
86
89
  checkout: {
@@ -295,4 +298,10 @@ export default flat({
295
298
  },
296
299
  },
297
300
  },
301
+ refund: {
302
+ type: {
303
+ [RefundType.refund]: 'Refund',
304
+ [RefundType.stakeReturn]: 'Stake Return',
305
+ },
306
+ },
298
307
  });
@@ -1,5 +1,7 @@
1
1
  import flat from 'flat';
2
2
 
3
+ import { RefundType } from '../libs/constant';
4
+
3
5
  export default flat({
4
6
  common: {
5
7
  id: 'ID',
@@ -81,6 +83,7 @@ export default flat({
81
83
  weeks: '周',
82
84
  months: '月',
83
85
  years: '年',
86
+ type: '类型',
84
87
  },
85
88
  payment: {
86
89
  checkout: {
@@ -287,4 +290,10 @@ export default flat({
287
290
  },
288
291
  },
289
292
  },
293
+ refund: {
294
+ type: {
295
+ [RefundType.refund]: '退款',
296
+ [RefundType.stakeReturn]: '退押金',
297
+ },
298
+ },
290
299
  });
@@ -381,7 +381,9 @@ export const Root = styled(Box)<{ mode: LiteralUnion<'standalone' | 'inline' | '
381
381
  position: absolute;
382
382
  right: 0;
383
383
  top: 0;
384
- transition: background-color 0.15s ease, box-shadow 0.15s ease-out;
384
+ transition:
385
+ background-color 0.15s ease,
386
+ box-shadow 0.15s ease-out;
385
387
  }
386
388
  .cko-product {
387
389
  margin-top: ${(props) => (props.mode === 'standalone' ? '64px' : '0')};