@blocklet/payment-react 1.19.1 → 1.19.3
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/components/label.js +2 -1
- package/es/components/payment-beneficiaries.d.ts +1 -0
- package/es/components/payment-beneficiaries.js +22 -12
- package/es/history/credit/transactions-list.js +0 -1
- package/es/payment/form/address.js +2 -1
- package/es/payment/form/index.js +26 -2
- package/lib/components/label.js +3 -1
- package/lib/components/payment-beneficiaries.d.ts +1 -0
- package/lib/components/payment-beneficiaries.js +15 -12
- package/lib/history/credit/transactions-list.js +0 -1
- package/lib/payment/form/address.js +6 -5
- package/lib/payment/form/index.js +34 -4
- package/package.json +9 -9
- package/src/components/label.tsx +2 -1
- package/src/components/payment-beneficiaries.tsx +20 -12
- package/src/history/credit/transactions-list.tsx +0 -1
- package/src/payment/form/address.tsx +2 -1
- package/src/payment/form/index.tsx +26 -2
package/es/components/label.js
CHANGED
|
@@ -17,6 +17,7 @@ export default function CustomFormLabel({
|
|
|
17
17
|
display: "flex",
|
|
18
18
|
alignItems: "center",
|
|
19
19
|
gap: 0.5,
|
|
20
|
+
fontSize: "0.875rem",
|
|
20
21
|
fontWeight: 500,
|
|
21
22
|
color: "text.primary",
|
|
22
23
|
"&.MuiFormLabel-root": {
|
|
@@ -31,7 +32,7 @@ export default function CustomFormLabel({
|
|
|
31
32
|
children: [
|
|
32
33
|
children,
|
|
33
34
|
required && /* @__PURE__ */ jsx(Typography, { component: "span", color: "error", children: "*" }),
|
|
34
|
-
tooltip && (typeof tooltip === "string" ? /* @__PURE__ */ jsx(Tooltip, { title: tooltip, children: /* @__PURE__ */ jsx(InfoOutlined, { fontSize: "small", sx: { opacity: 0.7 } }) }) : tooltip)
|
|
35
|
+
tooltip && (typeof tooltip === "string" ? /* @__PURE__ */ jsx(Tooltip, { title: tooltip, children: /* @__PURE__ */ jsx(InfoOutlined, { fontSize: "small", sx: { opacity: 0.7, fontSize: "1rem" } }) }) : tooltip)
|
|
35
36
|
]
|
|
36
37
|
}
|
|
37
38
|
),
|
|
@@ -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
|
|
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:
|
|
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(
|
|
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
|
-
|
|
76
|
+
DID,
|
|
67
77
|
{
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
|
|
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),
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
|
|
3
|
-
import { Fade,
|
|
3
|
+
import { Fade, InputAdornment, Stack } from "@mui/material";
|
|
4
4
|
import { Controller, useFormContext, useWatch } from "react-hook-form";
|
|
5
5
|
import FormInput from "../../components/input.js";
|
|
6
|
+
import FormLabel from "../../components/label.js";
|
|
6
7
|
import CountrySelect from "../../components/country-select.js";
|
|
7
8
|
import { getFieldValidation, validatePostalCode } from "../../libs/validator.js";
|
|
8
9
|
export default function AddressForm({ mode, stripe, sx = {}, fieldValidation = {}, errorPosition = "right" }) {
|
package/es/payment/form/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import "react-international-phone/style.css";
|
|
3
3
|
import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
|
|
4
4
|
import Toast from "@arcblock/ux/lib/Toast";
|
|
5
|
-
import { Box, Button, CircularProgress, Divider, Fade,
|
|
5
|
+
import { Box, Button, CircularProgress, Divider, Fade, Stack, Tooltip, Typography } from "@mui/material";
|
|
6
6
|
import { useMemoizedFn, useSetState } from "ahooks";
|
|
7
7
|
import pWaitFor from "p-wait-for";
|
|
8
8
|
import { useEffect, useMemo, useRef } from "react";
|
|
@@ -15,6 +15,7 @@ import DID from "@arcblock/ux/lib/DID";
|
|
|
15
15
|
import isEmpty from "lodash/isEmpty";
|
|
16
16
|
import { HelpOutline, OpenInNew } from "@mui/icons-material";
|
|
17
17
|
import FormInput from "../../components/input.js";
|
|
18
|
+
import FormLabel from "../../components/label.js";
|
|
18
19
|
import { usePaymentContext } from "../../contexts/payment.js";
|
|
19
20
|
import { useSubscription } from "../../hooks/subscription.js";
|
|
20
21
|
import api from "../../libs/api.js";
|
|
@@ -214,6 +215,8 @@ export default function PaymentForm({
|
|
|
214
215
|
}, [session?.user, checkoutSession.phone_number_collection?.enabled]);
|
|
215
216
|
const paymentMethod = useWatch({ control, name: "payment_method" });
|
|
216
217
|
const paymentCurrencyId = useWatch({ control, name: "payment_currency" });
|
|
218
|
+
const customerName = useWatch({ control, name: "customer_name" });
|
|
219
|
+
const customerEmail = useWatch({ control, name: "customer_email" });
|
|
217
220
|
const afterUserLoggedIn = useMemoizedFn(() => {
|
|
218
221
|
handleSubmit(onFormSubmit, onFormError)();
|
|
219
222
|
});
|
|
@@ -233,7 +236,25 @@ export default function PaymentForm({
|
|
|
233
236
|
const paymentCurrency = currencies.find((x) => x.id === paymentCurrencyId);
|
|
234
237
|
const showStake = method.type === "arcblock" && !checkoutSession.subscription_data?.no_stake;
|
|
235
238
|
const isDonationMode = checkoutSession?.submit_type === "donate" && isDonation;
|
|
236
|
-
const showForm =
|
|
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]);
|
|
237
258
|
const handleConnected = async () => {
|
|
238
259
|
setState({ paying: true });
|
|
239
260
|
try {
|
|
@@ -426,6 +447,9 @@ export default function PaymentForm({
|
|
|
426
447
|
setState({ submitting: false });
|
|
427
448
|
};
|
|
428
449
|
const onAction = () => {
|
|
450
|
+
if (state.submitting || state.paying) {
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
429
453
|
if (errorRef.current && !isEmpty(errors) && isMobile) {
|
|
430
454
|
errorRef.current.scrollIntoView({ behavior: "smooth" });
|
|
431
455
|
}
|
package/lib/components/label.js
CHANGED
|
@@ -25,6 +25,7 @@ function CustomFormLabel({
|
|
|
25
25
|
display: "flex",
|
|
26
26
|
alignItems: "center",
|
|
27
27
|
gap: 0.5,
|
|
28
|
+
fontSize: "0.875rem",
|
|
28
29
|
fontWeight: 500,
|
|
29
30
|
color: "text.primary",
|
|
30
31
|
"&.MuiFormLabel-root": {
|
|
@@ -45,7 +46,8 @@ function CustomFormLabel({
|
|
|
45
46
|
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_iconsMaterial.InfoOutlined, {
|
|
46
47
|
fontSize: "small",
|
|
47
48
|
sx: {
|
|
48
|
-
opacity: 0.7
|
|
49
|
+
opacity: 0.7,
|
|
50
|
+
fontSize: "1rem"
|
|
49
51
|
}
|
|
50
52
|
})
|
|
51
53
|
}) : tooltip)]
|
|
@@ -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)(
|
|
80
|
-
|
|
79
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_DID.default, {
|
|
80
|
+
did: item.address,
|
|
81
|
+
compact: true,
|
|
82
|
+
responsive: false,
|
|
81
83
|
sx: {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
+
whiteSpace: "nowrap",
|
|
85
|
+
fontSize: "0.875rem !important"
|
|
84
86
|
},
|
|
85
|
-
|
|
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,
|
|
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
|
})]
|
|
@@ -111,7 +111,6 @@ const TransactionsTable = _react.default.memo(props => {
|
|
|
111
111
|
label: t("common.creditAmount"),
|
|
112
112
|
name: "credit_amount",
|
|
113
113
|
align: "right",
|
|
114
|
-
width: 120,
|
|
115
114
|
options: {
|
|
116
115
|
customBodyRenderLite: (_, index) => {
|
|
117
116
|
const transaction = data?.list[index];
|
|
@@ -9,6 +9,7 @@ var _context = require("@arcblock/ux/lib/Locale/context");
|
|
|
9
9
|
var _material = require("@mui/material");
|
|
10
10
|
var _reactHookForm = require("react-hook-form");
|
|
11
11
|
var _input = _interopRequireDefault(require("../../components/input"));
|
|
12
|
+
var _label = _interopRequireDefault(require("../../components/label"));
|
|
12
13
|
var _countrySelect = _interopRequireDefault(require("../../components/country-select"));
|
|
13
14
|
var _validator = require("../../libs/validator");
|
|
14
15
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -40,7 +41,7 @@ function AddressForm({
|
|
|
40
41
|
direction: "column",
|
|
41
42
|
className: "cko-payment-form",
|
|
42
43
|
spacing: 0,
|
|
43
|
-
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(
|
|
44
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_label.default, {
|
|
44
45
|
className: "base-label",
|
|
45
46
|
children: t("payment.checkout.billing.line1")
|
|
46
47
|
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_input.default, {
|
|
@@ -52,7 +53,7 @@ function AddressForm({
|
|
|
52
53
|
errorPosition,
|
|
53
54
|
variant: "outlined",
|
|
54
55
|
placeholder: t("payment.checkout.billing.line1")
|
|
55
|
-
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(
|
|
56
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_label.default, {
|
|
56
57
|
className: "base-label",
|
|
57
58
|
children: t("payment.checkout.billing.city")
|
|
58
59
|
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_input.default, {
|
|
@@ -64,7 +65,7 @@ function AddressForm({
|
|
|
64
65
|
errorPosition,
|
|
65
66
|
variant: "outlined",
|
|
66
67
|
placeholder: t("payment.checkout.billing.city")
|
|
67
|
-
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(
|
|
68
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_label.default, {
|
|
68
69
|
className: "base-label",
|
|
69
70
|
children: t("payment.checkout.billing.state")
|
|
70
71
|
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_input.default, {
|
|
@@ -76,7 +77,7 @@ function AddressForm({
|
|
|
76
77
|
errorPosition,
|
|
77
78
|
variant: "outlined",
|
|
78
79
|
placeholder: t("payment.checkout.billing.state")
|
|
79
|
-
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(
|
|
80
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_label.default, {
|
|
80
81
|
className: "base-label",
|
|
81
82
|
children: t("payment.checkout.billing.postal_code")
|
|
82
83
|
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_input.default, {
|
|
@@ -131,7 +132,7 @@ function AddressForm({
|
|
|
131
132
|
direction: "column",
|
|
132
133
|
className: "cko-payment-form",
|
|
133
134
|
spacing: 0,
|
|
134
|
-
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(
|
|
135
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_label.default, {
|
|
135
136
|
className: "base-label",
|
|
136
137
|
children: t("payment.checkout.billing.postal_code")
|
|
137
138
|
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Stack, {
|
|
@@ -22,6 +22,7 @@ var _DID = _interopRequireDefault(require("@arcblock/ux/lib/DID"));
|
|
|
22
22
|
var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
|
|
23
23
|
var _iconsMaterial = require("@mui/icons-material");
|
|
24
24
|
var _input = _interopRequireDefault(require("../../components/input"));
|
|
25
|
+
var _label = _interopRequireDefault(require("../../components/label"));
|
|
25
26
|
var _payment = require("../../contexts/payment");
|
|
26
27
|
var _subscription = require("../../hooks/subscription");
|
|
27
28
|
var _api = _interopRequireDefault(require("../../libs/api"));
|
|
@@ -245,6 +246,14 @@ function PaymentForm({
|
|
|
245
246
|
control,
|
|
246
247
|
name: "payment_currency"
|
|
247
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
|
+
});
|
|
248
257
|
const afterUserLoggedIn = (0, _ahooks.useMemoizedFn)(() => {
|
|
249
258
|
handleSubmit(onFormSubmit, onFormError)();
|
|
250
259
|
});
|
|
@@ -266,7 +275,25 @@ function PaymentForm({
|
|
|
266
275
|
const paymentCurrency = currencies.find(x => x.id === paymentCurrencyId);
|
|
267
276
|
const showStake = method.type === "arcblock" && !checkoutSession.subscription_data?.no_stake;
|
|
268
277
|
const isDonationMode = checkoutSession?.submit_type === "donate" && isDonation;
|
|
269
|
-
const showForm =
|
|
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]);
|
|
270
297
|
const handleConnected = async () => {
|
|
271
298
|
setState({
|
|
272
299
|
paying: true
|
|
@@ -499,6 +526,9 @@ function PaymentForm({
|
|
|
499
526
|
});
|
|
500
527
|
};
|
|
501
528
|
const onAction = () => {
|
|
529
|
+
if (state.submitting || state.paying) {
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
502
532
|
if (errorRef.current && !(0, _isEmpty.default)(errors) && isMobile) {
|
|
503
533
|
errorRef.current.scrollIntoView({
|
|
504
534
|
behavior: "smooth"
|
|
@@ -756,7 +786,7 @@ function PaymentForm({
|
|
|
756
786
|
overflow: "auto",
|
|
757
787
|
py: 1
|
|
758
788
|
},
|
|
759
|
-
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(
|
|
789
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_label.default, {
|
|
760
790
|
className: "base-label",
|
|
761
791
|
children: t("payment.checkout.customer.name")
|
|
762
792
|
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_input.default, {
|
|
@@ -767,7 +797,7 @@ function PaymentForm({
|
|
|
767
797
|
required: t("payment.checkout.required"),
|
|
768
798
|
...(0, _validator.getFieldValidation)("customer_name", checkoutSession.metadata?.page_info?.field_validation, locale)
|
|
769
799
|
}
|
|
770
|
-
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(
|
|
800
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_label.default, {
|
|
771
801
|
className: "base-label",
|
|
772
802
|
children: t("payment.checkout.customer.email")
|
|
773
803
|
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_input.default, {
|
|
@@ -780,7 +810,7 @@ function PaymentForm({
|
|
|
780
810
|
...(0, _validator.getFieldValidation)("customer_email", checkoutSession.metadata?.page_info?.field_validation, locale)
|
|
781
811
|
}
|
|
782
812
|
}), checkoutSession.phone_number_collection?.enabled && /* @__PURE__ */(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
783
|
-
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(
|
|
813
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_label.default, {
|
|
784
814
|
className: "base-label",
|
|
785
815
|
children: t("payment.checkout.customer.phone")
|
|
786
816
|
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_phone.default, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/payment-react",
|
|
3
|
-
"version": "1.19.
|
|
3
|
+
"version": "1.19.3",
|
|
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.
|
|
58
|
-
"@arcblock/ux": "^3.0.
|
|
59
|
-
"@arcblock/ws": "^1.20.
|
|
60
|
-
"@blocklet/theme": "^3.0.
|
|
61
|
-
"@blocklet/ui-react": "^3.0.
|
|
57
|
+
"@arcblock/did-connect": "^3.0.22",
|
|
58
|
+
"@arcblock/ux": "^3.0.22",
|
|
59
|
+
"@arcblock/ws": "^1.20.15",
|
|
60
|
+
"@blocklet/theme": "^3.0.22",
|
|
61
|
+
"@blocklet/ui-react": "^3.0.22",
|
|
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.
|
|
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.
|
|
97
|
+
"@blocklet/payment-types": "1.19.3",
|
|
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": "
|
|
128
|
+
"gitHead": "f274edb338c8f5a23ae46d9f7fea8458a6001cf7"
|
|
129
129
|
}
|
package/src/components/label.tsx
CHANGED
|
@@ -18,6 +18,7 @@ export default function CustomFormLabel({
|
|
|
18
18
|
display: 'flex',
|
|
19
19
|
alignItems: 'center',
|
|
20
20
|
gap: 0.5,
|
|
21
|
+
fontSize: '0.875rem',
|
|
21
22
|
fontWeight: 500,
|
|
22
23
|
color: 'text.primary',
|
|
23
24
|
'&.MuiFormLabel-root': {
|
|
@@ -38,7 +39,7 @@ export default function CustomFormLabel({
|
|
|
38
39
|
{tooltip &&
|
|
39
40
|
(typeof tooltip === 'string' ? (
|
|
40
41
|
<Tooltip title={tooltip}>
|
|
41
|
-
<InfoOutlined fontSize="small" sx={{ opacity: 0.7 }} />
|
|
42
|
+
<InfoOutlined fontSize="small" sx={{ opacity: 0.7, fontSize: '1rem' }} />
|
|
42
43
|
</Tooltip>
|
|
43
44
|
) : (
|
|
44
45
|
tooltip
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/indent */
|
|
2
2
|
import { Avatar, Box, Stack, Typography } from '@mui/material';
|
|
3
|
-
import { BN
|
|
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=
|
|
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
|
|
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
|
-
<
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
|
|
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
|
-
{
|
|
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>
|
|
@@ -141,7 +141,6 @@ const TransactionsTable = React.memo((props: Props) => {
|
|
|
141
141
|
label: t('common.creditAmount'),
|
|
142
142
|
name: 'credit_amount',
|
|
143
143
|
align: 'right',
|
|
144
|
-
width: 120,
|
|
145
144
|
options: {
|
|
146
145
|
customBodyRenderLite: (_: string, index: number) => {
|
|
147
146
|
const transaction = data?.list[index] as TCreditTransactionExpanded;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
2
|
-
import { Fade,
|
|
2
|
+
import { Fade, InputAdornment, Stack } from '@mui/material';
|
|
3
3
|
import type { SxProps } from '@mui/material';
|
|
4
4
|
import { Controller, useFormContext, useWatch } from 'react-hook-form';
|
|
5
5
|
import FormInput from '../../components/input';
|
|
6
|
+
import FormLabel from '../../components/label';
|
|
6
7
|
import CountrySelect from '../../components/country-select';
|
|
7
8
|
import { getFieldValidation, validatePostalCode } from '../../libs/validator';
|
|
8
9
|
|
|
@@ -5,7 +5,7 @@ import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
|
5
5
|
// import { useTheme } from '@arcblock/ux/lib/Theme';
|
|
6
6
|
import Toast from '@arcblock/ux/lib/Toast';
|
|
7
7
|
import type { TCheckoutSession, TCustomer, TPaymentIntent, TPaymentMethodExpanded } from '@blocklet/payment-types';
|
|
8
|
-
import { Box, Button, CircularProgress, Divider, Fade,
|
|
8
|
+
import { Box, Button, CircularProgress, Divider, Fade, Stack, Tooltip, Typography } from '@mui/material';
|
|
9
9
|
import { useMemoizedFn, useSetState } from 'ahooks';
|
|
10
10
|
import pWaitFor from 'p-wait-for';
|
|
11
11
|
import { useEffect, useMemo, useRef } from 'react';
|
|
@@ -19,6 +19,7 @@ import DID from '@arcblock/ux/lib/DID';
|
|
|
19
19
|
import isEmpty from 'lodash/isEmpty';
|
|
20
20
|
import { HelpOutline, OpenInNew } from '@mui/icons-material';
|
|
21
21
|
import FormInput from '../../components/input';
|
|
22
|
+
import FormLabel from '../../components/label';
|
|
22
23
|
import { usePaymentContext } from '../../contexts/payment';
|
|
23
24
|
import { useSubscription } from '../../hooks/subscription';
|
|
24
25
|
import api from '../../libs/api';
|
|
@@ -314,6 +315,8 @@ export default function PaymentForm({
|
|
|
314
315
|
|
|
315
316
|
const paymentMethod = useWatch({ control, name: 'payment_method' });
|
|
316
317
|
const paymentCurrencyId = useWatch({ control, name: 'payment_currency' });
|
|
318
|
+
const customerName = useWatch({ control, name: 'customer_name' });
|
|
319
|
+
const customerEmail = useWatch({ control, name: 'customer_email' });
|
|
317
320
|
|
|
318
321
|
// const domSize = useSize(document.body);
|
|
319
322
|
|
|
@@ -348,7 +351,25 @@ export default function PaymentForm({
|
|
|
348
351
|
const showStake = method.type === 'arcblock' && !checkoutSession.subscription_data?.no_stake;
|
|
349
352
|
|
|
350
353
|
const isDonationMode = checkoutSession?.submit_type === 'donate' && isDonation;
|
|
351
|
-
const showForm =
|
|
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]);
|
|
352
373
|
|
|
353
374
|
const handleConnected = async () => {
|
|
354
375
|
setState({ paying: true });
|
|
@@ -562,6 +583,9 @@ export default function PaymentForm({
|
|
|
562
583
|
};
|
|
563
584
|
|
|
564
585
|
const onAction = () => {
|
|
586
|
+
if (state.submitting || state.paying) {
|
|
587
|
+
return;
|
|
588
|
+
}
|
|
565
589
|
if (errorRef.current && !isEmpty(errors) && isMobile) {
|
|
566
590
|
errorRef.current.scrollIntoView({ behavior: 'smooth' });
|
|
567
591
|
}
|