@blocklet/payment-react 1.19.2 → 1.19.4

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.
@@ -12,6 +12,7 @@ interface BenefitsProps {
12
12
  currency: {
13
13
  symbol: string;
14
14
  decimal: number;
15
+ maximum_precision?: number;
15
16
  };
16
17
  totalAmount?: string;
17
18
  }
@@ -1,7 +1,9 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { Avatar, Box, Stack, Typography } from "@mui/material";
3
- import { BN, fromUnitToToken } from "@ocap/util";
3
+ import { BN } from "@ocap/util";
4
4
  import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
5
+ import DID from "@arcblock/ux/lib/DID";
6
+ import { formatBNStr } from "../libs/util.js";
5
7
  export default function PaymentBeneficiaries({ data, currency, totalAmount = "0" }) {
6
8
  const { t } = useLocaleContext();
7
9
  return /* @__PURE__ */ jsxs(Stack, { spacing: 2, children: [
@@ -20,7 +22,7 @@ export default function PaymentBeneficiaries({ data, currency, totalAmount = "0"
20
22
  return /* @__PURE__ */ jsxs(
21
23
  Stack,
22
24
  {
23
- direction: { xs: "column", sm: "row" },
25
+ direction: "row",
24
26
  sx: {
25
27
  alignItems: "center",
26
28
  justifyContent: "space-between",
@@ -42,7 +44,15 @@ export default function PaymentBeneficiaries({ data, currency, totalAmount = "0"
42
44
  width: { xs: "100%", sm: "auto" }
43
45
  },
44
46
  children: [
45
- /* @__PURE__ */ jsx(Avatar, { src: item.avatar, alt: item.name, sx: { width: 32, height: 32 }, variant: "square" }),
47
+ /* @__PURE__ */ jsx(
48
+ Avatar,
49
+ {
50
+ src: item.avatar,
51
+ alt: item.name,
52
+ sx: { width: 32, height: 32 },
53
+ variant: item.type === "dapp" ? "square" : "circular"
54
+ }
55
+ ),
46
56
  /* @__PURE__ */ jsxs(Box, { children: [
47
57
  /* @__PURE__ */ jsx(
48
58
  Typography,
@@ -63,14 +73,13 @@ export default function PaymentBeneficiaries({ data, currency, totalAmount = "0"
63
73
  }
64
74
  ),
65
75
  /* @__PURE__ */ jsx(
66
- Typography,
76
+ DID,
67
77
  {
68
- variant: "caption",
69
- sx: {
70
- color: "text.secondary",
71
- cursor: "pointer"
72
- },
73
- children: item.address
78
+ did: item.address,
79
+ compact: true,
80
+ responsive: false,
81
+ sx: { whiteSpace: "nowrap", fontSize: "0.875rem !important" },
82
+ copyable: false
74
83
  }
75
84
  )
76
85
  ] })
@@ -87,7 +96,7 @@ export default function PaymentBeneficiaries({ data, currency, totalAmount = "0"
87
96
  },
88
97
  children: [
89
98
  /* @__PURE__ */ jsxs(Typography, { variant: "subtitle2", children: [
90
- fromUnitToToken(amount, currency.decimal),
99
+ formatBNStr(amount, currency.decimal, currency?.maximum_precision ?? 6),
91
100
  " ",
92
101
  currency.symbol
93
102
  ] }),
@@ -96,7 +105,8 @@ export default function PaymentBeneficiaries({ data, currency, totalAmount = "0"
96
105
  {
97
106
  variant: "caption",
98
107
  sx: {
99
- color: "text.secondary"
108
+ color: "text.secondary",
109
+ fontSize: "0.875rem"
100
110
  },
101
111
  children: [
102
112
  Number(item.percent),
@@ -215,6 +215,8 @@ export default function PaymentForm({
215
215
  }, [session?.user, checkoutSession.phone_number_collection?.enabled]);
216
216
  const paymentMethod = useWatch({ control, name: "payment_method" });
217
217
  const paymentCurrencyId = useWatch({ control, name: "payment_currency" });
218
+ const customerName = useWatch({ control, name: "customer_name" });
219
+ const customerEmail = useWatch({ control, name: "customer_email" });
218
220
  const afterUserLoggedIn = useMemoizedFn(() => {
219
221
  handleSubmit(onFormSubmit, onFormError)();
220
222
  });
@@ -234,7 +236,25 @@ export default function PaymentForm({
234
236
  const paymentCurrency = currencies.find((x) => x.id === paymentCurrencyId);
235
237
  const showStake = method.type === "arcblock" && !checkoutSession.subscription_data?.no_stake;
236
238
  const isDonationMode = checkoutSession?.submit_type === "donate" && isDonation;
237
- const showForm = !!session?.user;
239
+ const showForm = useMemo(() => {
240
+ if (!session?.user) {
241
+ return false;
242
+ }
243
+ if (method.type === "stripe") {
244
+ return true;
245
+ }
246
+ if (checkoutSession.phone_number_collection?.enabled) {
247
+ return true;
248
+ }
249
+ const mode = checkoutSession.billing_address_collection;
250
+ if (mode === "required") {
251
+ return true;
252
+ }
253
+ if (customerName && customerEmail) {
254
+ return false;
255
+ }
256
+ return true;
257
+ }, [session?.user, method, checkoutSession, customerName, customerEmail]);
238
258
  const handleConnected = async () => {
239
259
  setState({ paying: true });
240
260
  try {
@@ -427,6 +447,9 @@ export default function PaymentForm({
427
447
  setState({ submitting: false });
428
448
  };
429
449
  const onAction = () => {
450
+ if (state.submitting || state.paying) {
451
+ return;
452
+ }
430
453
  if (errorRef.current && !isEmpty(errors) && isMobile) {
431
454
  errorRef.current.scrollIntoView({ behavior: "smooth" });
432
455
  }
@@ -12,6 +12,7 @@ interface BenefitsProps {
12
12
  currency: {
13
13
  symbol: string;
14
14
  decimal: number;
15
+ maximum_precision?: number;
15
16
  };
16
17
  totalAmount?: string;
17
18
  }
@@ -8,6 +8,9 @@ var _jsxRuntime = require("react/jsx-runtime");
8
8
  var _material = require("@mui/material");
9
9
  var _util = require("@ocap/util");
10
10
  var _context = require("@arcblock/ux/lib/Locale/context");
11
+ var _DID = _interopRequireDefault(require("@arcblock/ux/lib/DID"));
12
+ var _util2 = require("../libs/util");
13
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
14
  function PaymentBeneficiaries({
12
15
  data,
13
16
  currency,
@@ -29,10 +32,7 @@ function PaymentBeneficiaries({
29
32
  }), data.map(item => {
30
33
  const amount = item.amount || (totalAmount ? new _util.BN(totalAmount).mul(new _util.BN(Number(item.percent))).div(new _util.BN(100)).toString() : "0");
31
34
  return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
32
- direction: {
33
- xs: "column",
34
- sm: "row"
35
- },
35
+ direction: "row",
36
36
  sx: {
37
37
  alignItems: "center",
38
38
  justifyContent: "space-between",
@@ -60,7 +60,7 @@ function PaymentBeneficiaries({
60
60
  width: 32,
61
61
  height: 32
62
62
  },
63
- variant: "square"
63
+ variant: item.type === "dapp" ? "square" : "circular"
64
64
  }), /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
65
65
  children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
66
66
  variant: "subtitle2",
@@ -76,13 +76,15 @@ function PaymentBeneficiaries({
76
76
  }
77
77
  },
78
78
  children: item.name
79
- }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
80
- variant: "caption",
79
+ }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_DID.default, {
80
+ did: item.address,
81
+ compact: true,
82
+ responsive: false,
81
83
  sx: {
82
- color: "text.secondary",
83
- cursor: "pointer"
84
+ whiteSpace: "nowrap",
85
+ fontSize: "0.875rem !important"
84
86
  },
85
- children: item.address
87
+ copyable: false
86
88
  })]
87
89
  })]
88
90
  }), /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
@@ -99,11 +101,12 @@ function PaymentBeneficiaries({
99
101
  },
100
102
  children: [/* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Typography, {
101
103
  variant: "subtitle2",
102
- children: [(0, _util.fromUnitToToken)(amount, currency.decimal), " ", currency.symbol]
104
+ children: [(0, _util2.formatBNStr)(amount, currency.decimal, currency?.maximum_precision ?? 6), " ", currency.symbol]
103
105
  }), /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Typography, {
104
106
  variant: "caption",
105
107
  sx: {
106
- color: "text.secondary"
108
+ color: "text.secondary",
109
+ fontSize: "0.875rem"
107
110
  },
108
111
  children: [Number(item.percent), "%"]
109
112
  })]
@@ -246,6 +246,14 @@ function PaymentForm({
246
246
  control,
247
247
  name: "payment_currency"
248
248
  });
249
+ const customerName = (0, _reactHookForm.useWatch)({
250
+ control,
251
+ name: "customer_name"
252
+ });
253
+ const customerEmail = (0, _reactHookForm.useWatch)({
254
+ control,
255
+ name: "customer_email"
256
+ });
249
257
  const afterUserLoggedIn = (0, _ahooks.useMemoizedFn)(() => {
250
258
  handleSubmit(onFormSubmit, onFormError)();
251
259
  });
@@ -267,7 +275,25 @@ function PaymentForm({
267
275
  const paymentCurrency = currencies.find(x => x.id === paymentCurrencyId);
268
276
  const showStake = method.type === "arcblock" && !checkoutSession.subscription_data?.no_stake;
269
277
  const isDonationMode = checkoutSession?.submit_type === "donate" && isDonation;
270
- const showForm = !!session?.user;
278
+ const showForm = (0, _react.useMemo)(() => {
279
+ if (!session?.user) {
280
+ return false;
281
+ }
282
+ if (method.type === "stripe") {
283
+ return true;
284
+ }
285
+ if (checkoutSession.phone_number_collection?.enabled) {
286
+ return true;
287
+ }
288
+ const mode = checkoutSession.billing_address_collection;
289
+ if (mode === "required") {
290
+ return true;
291
+ }
292
+ if (customerName && customerEmail) {
293
+ return false;
294
+ }
295
+ return true;
296
+ }, [session?.user, method, checkoutSession, customerName, customerEmail]);
271
297
  const handleConnected = async () => {
272
298
  setState({
273
299
  paying: true
@@ -500,6 +526,9 @@ function PaymentForm({
500
526
  });
501
527
  };
502
528
  const onAction = () => {
529
+ if (state.submitting || state.paying) {
530
+ return;
531
+ }
503
532
  if (errorRef.current && !(0, _isEmpty.default)(errors) && isMobile) {
504
533
  errorRef.current.scrollIntoView({
505
534
  behavior: "smooth"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/payment-react",
3
- "version": "1.19.2",
3
+ "version": "1.19.4",
4
4
  "description": "Reusable react components for payment kit v2",
5
5
  "keywords": [
6
6
  "react",
@@ -54,16 +54,16 @@
54
54
  }
55
55
  },
56
56
  "dependencies": {
57
- "@arcblock/did-connect": "^3.0.1",
58
- "@arcblock/ux": "^3.0.1",
59
- "@arcblock/ws": "^1.20.14",
60
- "@blocklet/theme": "^3.0.1",
61
- "@blocklet/ui-react": "^3.0.1",
57
+ "@arcblock/did-connect": "^3.0.24",
58
+ "@arcblock/ux": "^3.0.24",
59
+ "@arcblock/ws": "^1.20.15",
60
+ "@blocklet/theme": "^3.0.24",
61
+ "@blocklet/ui-react": "^3.0.24",
62
62
  "@mui/icons-material": "^7.1.2",
63
63
  "@mui/lab": "7.0.0-beta.14",
64
64
  "@mui/material": "^7.1.2",
65
65
  "@mui/system": "^7.1.1",
66
- "@ocap/util": "^1.20.14",
66
+ "@ocap/util": "^1.20.15",
67
67
  "@stripe/react-stripe-js": "^2.9.0",
68
68
  "@stripe/stripe-js": "^2.4.0",
69
69
  "@vitejs/plugin-legacy": "^7.0.0",
@@ -94,7 +94,7 @@
94
94
  "@babel/core": "^7.27.4",
95
95
  "@babel/preset-env": "^7.27.2",
96
96
  "@babel/preset-react": "^7.27.1",
97
- "@blocklet/payment-types": "1.19.2",
97
+ "@blocklet/payment-types": "1.19.4",
98
98
  "@storybook/addon-essentials": "^7.6.20",
99
99
  "@storybook/addon-interactions": "^7.6.20",
100
100
  "@storybook/addon-links": "^7.6.20",
@@ -125,5 +125,5 @@
125
125
  "vite-plugin-babel": "^1.3.1",
126
126
  "vite-plugin-node-polyfills": "^0.23.0"
127
127
  },
128
- "gitHead": "741c897204afc412721a942201516932bff59235"
128
+ "gitHead": "ced79cc9e205a344b6fdce2f43ac8d27bb37f5f4"
129
129
  }
@@ -1,7 +1,9 @@
1
1
  /* eslint-disable @typescript-eslint/indent */
2
2
  import { Avatar, Box, Stack, Typography } from '@mui/material';
3
- import { BN, fromUnitToToken } from '@ocap/util';
3
+ import { BN } from '@ocap/util';
4
4
  import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
5
+ import DID from '@arcblock/ux/lib/DID';
6
+ import { formatBNStr } from '../libs/util';
5
7
 
6
8
  export interface TBeneficiary {
7
9
  name: string;
@@ -18,6 +20,7 @@ interface BenefitsProps {
18
20
  currency: {
19
21
  symbol: string;
20
22
  decimal: number;
23
+ maximum_precision?: number;
21
24
  };
22
25
  totalAmount?: string;
23
26
  }
@@ -45,7 +48,7 @@ export default function PaymentBeneficiaries({ data, currency, totalAmount = '0'
45
48
  return (
46
49
  <Stack
47
50
  key={item.address}
48
- direction={{ xs: 'column', sm: 'row' }}
51
+ direction="row"
49
52
  sx={{
50
53
  alignItems: 'center',
51
54
  justifyContent: 'space-between',
@@ -64,7 +67,12 @@ export default function PaymentBeneficiaries({ data, currency, totalAmount = '0'
64
67
  alignItems: 'center',
65
68
  width: { xs: '100%', sm: 'auto' },
66
69
  }}>
67
- <Avatar src={item.avatar} alt={item.name} sx={{ width: 32, height: 32 }} variant="square" />
70
+ <Avatar
71
+ src={item.avatar}
72
+ alt={item.name}
73
+ sx={{ width: 32, height: 32 }}
74
+ variant={item.type === 'dapp' ? 'square' : 'circular'}
75
+ />
68
76
  <Box>
69
77
  <Typography
70
78
  variant="subtitle2"
@@ -81,14 +89,13 @@ export default function PaymentBeneficiaries({ data, currency, totalAmount = '0'
81
89
  }}>
82
90
  {item.name}
83
91
  </Typography>
84
- <Typography
85
- variant="caption"
86
- sx={{
87
- color: 'text.secondary',
88
- cursor: 'pointer',
89
- }}>
90
- {item.address}
91
- </Typography>
92
+ <DID
93
+ did={item.address}
94
+ compact
95
+ responsive={false}
96
+ sx={{ whiteSpace: 'nowrap', fontSize: '0.875rem !important' }}
97
+ copyable={false}
98
+ />
92
99
  </Box>
93
100
  </Stack>
94
101
  <Stack
@@ -98,12 +105,13 @@ export default function PaymentBeneficiaries({ data, currency, totalAmount = '0'
98
105
  mt: { xs: 1, sm: 0 },
99
106
  }}>
100
107
  <Typography variant="subtitle2">
101
- {fromUnitToToken(amount, currency.decimal)} {currency.symbol}
108
+ {formatBNStr(amount, currency.decimal, currency?.maximum_precision ?? 6)} {currency.symbol}
102
109
  </Typography>
103
110
  <Typography
104
111
  variant="caption"
105
112
  sx={{
106
113
  color: 'text.secondary',
114
+ fontSize: '0.875rem',
107
115
  }}>
108
116
  {Number(item.percent)}%
109
117
  </Typography>
@@ -315,6 +315,8 @@ export default function PaymentForm({
315
315
 
316
316
  const paymentMethod = useWatch({ control, name: 'payment_method' });
317
317
  const paymentCurrencyId = useWatch({ control, name: 'payment_currency' });
318
+ const customerName = useWatch({ control, name: 'customer_name' });
319
+ const customerEmail = useWatch({ control, name: 'customer_email' });
318
320
 
319
321
  // const domSize = useSize(document.body);
320
322
 
@@ -349,7 +351,25 @@ export default function PaymentForm({
349
351
  const showStake = method.type === 'arcblock' && !checkoutSession.subscription_data?.no_stake;
350
352
 
351
353
  const isDonationMode = checkoutSession?.submit_type === 'donate' && isDonation;
352
- const showForm = !!session?.user;
354
+ const showForm = useMemo(() => {
355
+ if (!session?.user) {
356
+ return false;
357
+ }
358
+ if (method.type === 'stripe') {
359
+ return true;
360
+ }
361
+ if (checkoutSession.phone_number_collection?.enabled) {
362
+ return true;
363
+ }
364
+ const mode = checkoutSession.billing_address_collection;
365
+ if (mode === 'required') {
366
+ return true;
367
+ }
368
+ if (customerName && customerEmail) {
369
+ return false;
370
+ }
371
+ return true;
372
+ }, [session?.user, method, checkoutSession, customerName, customerEmail]);
353
373
 
354
374
  const handleConnected = async () => {
355
375
  setState({ paying: true });
@@ -563,6 +583,9 @@ export default function PaymentForm({
563
583
  };
564
584
 
565
585
  const onAction = () => {
586
+ if (state.submitting || state.paying) {
587
+ return;
588
+ }
566
589
  if (errorRef.current && !isEmpty(errors) && isMobile) {
567
590
  errorRef.current.scrollIntoView({ behavior: 'smooth' });
568
591
  }