@blocklet/payment-react 1.18.6 → 1.18.7
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/README.md +394 -341
- package/es/checkout/donate.d.ts +28 -4
- package/es/checkout/donate.js +5 -6
- package/es/components/loading-button.d.ts +10 -0
- package/es/components/loading-button.js +75 -0
- package/es/components/pricing-table.js +2 -3
- package/es/index.d.ts +2 -1
- package/es/index.js +3 -1
- package/es/payment/form/index.js +13 -11
- package/es/payment/form/stripe/form.js +19 -4
- package/es/payment/index.js +0 -1
- package/es/payment/summary.js +1 -1
- package/es/theme/index.js +2 -1
- package/lib/checkout/donate.d.ts +28 -4
- package/lib/checkout/donate.js +4 -7
- package/lib/components/loading-button.d.ts +10 -0
- package/lib/components/loading-button.js +86 -0
- package/lib/components/pricing-table.js +3 -4
- package/lib/index.d.ts +2 -1
- package/lib/index.js +8 -0
- package/lib/payment/form/index.js +12 -13
- package/lib/payment/form/stripe/form.js +24 -5
- package/lib/payment/index.js +0 -1
- package/lib/payment/summary.js +3 -3
- package/lib/theme/index.js +2 -1
- package/package.json +6 -6
- package/src/checkout/donate.tsx +33 -16
- package/src/components/loading-button.tsx +100 -0
- package/src/components/pricing-table.tsx +3 -3
- package/src/index.ts +2 -0
- package/src/payment/form/index.tsx +64 -59
- package/src/payment/form/stripe/form.tsx +20 -5
- package/src/payment/index.tsx +0 -1
- package/src/payment/summary.tsx +1 -1
- package/src/theme/index.tsx +1 -0
package/es/checkout/donate.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DonationSettings, TCheckoutSessionExpanded, TPaymentCurrency, TPaymentMethod } from '@blocklet/payment-types';
|
|
1
|
+
import type { DonationSettings, PaymentBeneficiary, TCheckoutSessionExpanded, TPaymentCurrency, TPaymentMethod } from '@blocklet/payment-types';
|
|
2
2
|
import { type ButtonProps as MUIButtonProps } from '@mui/material';
|
|
3
3
|
import type { CheckoutProps, PaymentThemeOptions } from '../types';
|
|
4
4
|
export type DonateHistory = {
|
|
@@ -7,14 +7,38 @@ export type DonateHistory = {
|
|
|
7
7
|
method: TPaymentMethod;
|
|
8
8
|
totalAmount: string;
|
|
9
9
|
};
|
|
10
|
-
export type
|
|
11
|
-
|
|
10
|
+
export type CheckoutDonateSettings = {
|
|
11
|
+
target: string;
|
|
12
|
+
title: string;
|
|
13
|
+
description: string;
|
|
14
|
+
reference: string;
|
|
15
|
+
beneficiaries: PaymentBeneficiary[];
|
|
16
|
+
amount?: {
|
|
17
|
+
presets?: string[];
|
|
18
|
+
preset?: string;
|
|
19
|
+
minimum?: string;
|
|
20
|
+
maximum?: string;
|
|
21
|
+
custom?: boolean;
|
|
22
|
+
};
|
|
23
|
+
appearance?: {
|
|
24
|
+
button?: {
|
|
25
|
+
text?: any;
|
|
26
|
+
icon?: any;
|
|
27
|
+
size?: string;
|
|
28
|
+
color?: string;
|
|
29
|
+
variant?: string;
|
|
30
|
+
};
|
|
31
|
+
history?: {
|
|
32
|
+
variant?: string;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
};
|
|
12
36
|
export interface ButtonType extends Omit<MUIButtonProps, 'text' | 'icon'> {
|
|
13
37
|
text?: string | React.ReactNode;
|
|
14
38
|
icon: React.ReactNode;
|
|
15
39
|
}
|
|
16
40
|
export type DonateProps = Pick<CheckoutProps, 'onPaid' | 'onError'> & {
|
|
17
|
-
settings:
|
|
41
|
+
settings: CheckoutDonateSettings;
|
|
18
42
|
livemode?: boolean;
|
|
19
43
|
timeout?: number;
|
|
20
44
|
mode?: 'inline' | 'default' | 'custom';
|
package/es/checkout/donate.js
CHANGED
|
@@ -2,7 +2,6 @@ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import Dialog from "@arcblock/ux/lib/Dialog";
|
|
3
3
|
import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
|
|
4
4
|
import {
|
|
5
|
-
Alert,
|
|
6
5
|
Avatar,
|
|
7
6
|
AvatarGroup,
|
|
8
7
|
Box,
|
|
@@ -30,7 +29,6 @@ import {
|
|
|
30
29
|
formatAmount,
|
|
31
30
|
formatBNStr,
|
|
32
31
|
formatDateTime,
|
|
33
|
-
formatError,
|
|
34
32
|
getCustomerAvatar,
|
|
35
33
|
lazyLoad,
|
|
36
34
|
openDonationSettings
|
|
@@ -309,7 +307,7 @@ function CheckoutDonateInner({
|
|
|
309
307
|
}, timeout);
|
|
310
308
|
};
|
|
311
309
|
if (donation.error) {
|
|
312
|
-
return
|
|
310
|
+
return null;
|
|
313
311
|
}
|
|
314
312
|
const handlePopoverOpen = (event) => {
|
|
315
313
|
donation.run();
|
|
@@ -430,13 +428,14 @@ function CheckoutDonateInner({
|
|
|
430
428
|
`${formatAmount(
|
|
431
429
|
supporters.data?.totalAmount || "0",
|
|
432
430
|
supporters.data?.currency?.decimal
|
|
433
|
-
)} ${supporters.data?.currency?.symbol}`,
|
|
431
|
+
)} ${supporters.data?.currency?.symbol || ""}`,
|
|
434
432
|
supporters.data || {},
|
|
435
433
|
!!supporters.loading,
|
|
436
434
|
donateSettings
|
|
437
435
|
) }) : /* @__PURE__ */ jsxs(Typography, { children: [
|
|
438
|
-
"Please provide a valid render function
|
|
439
|
-
|
|
436
|
+
"Please provide a valid render function",
|
|
437
|
+
" ",
|
|
438
|
+
/* @__PURE__ */ jsx("pre", { children: "(openDonate, donateTotalAmount, supporters, loading, donateSettings) => ReactNode" })
|
|
440
439
|
] });
|
|
441
440
|
}
|
|
442
441
|
return defaultRender;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type ButtonProps, type CircularProgressProps } from '@mui/material';
|
|
2
|
+
export interface LoadingButtonProps extends ButtonProps {
|
|
3
|
+
loading?: boolean;
|
|
4
|
+
loadingIndicator?: React.ReactNode;
|
|
5
|
+
loadingPosition?: 'start' | 'center' | 'end';
|
|
6
|
+
loadingProps?: Partial<CircularProgressProps>;
|
|
7
|
+
loadingOnly?: boolean;
|
|
8
|
+
}
|
|
9
|
+
declare const LoadingButton: import("react").ForwardRefExoticComponent<Omit<LoadingButtonProps, "ref"> & import("react").RefAttributes<HTMLButtonElement>>;
|
|
10
|
+
export default LoadingButton;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import {
|
|
3
|
+
Button,
|
|
4
|
+
CircularProgress,
|
|
5
|
+
Typography
|
|
6
|
+
} from "@mui/material";
|
|
7
|
+
import { forwardRef } from "react";
|
|
8
|
+
const LoadingButton = forwardRef(
|
|
9
|
+
({
|
|
10
|
+
children,
|
|
11
|
+
loading,
|
|
12
|
+
loadingPosition = "start",
|
|
13
|
+
loadingIndicator,
|
|
14
|
+
loadingProps = {},
|
|
15
|
+
onClick,
|
|
16
|
+
sx,
|
|
17
|
+
loadingOnly = false,
|
|
18
|
+
...props
|
|
19
|
+
}, ref) => {
|
|
20
|
+
const handleClick = (e) => {
|
|
21
|
+
if (loading) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
onClick?.(e);
|
|
25
|
+
};
|
|
26
|
+
const getPositionStyles = (position) => {
|
|
27
|
+
return {
|
|
28
|
+
color: "inherit",
|
|
29
|
+
...position === "start" && { mr: 1 },
|
|
30
|
+
...position === "end" && { ml: 1 },
|
|
31
|
+
...position === "center" && {
|
|
32
|
+
position: "absolute",
|
|
33
|
+
left: "50%",
|
|
34
|
+
transform: "translateY(-50%) translateX(-50%)",
|
|
35
|
+
top: "50%"
|
|
36
|
+
},
|
|
37
|
+
display: "inline-flex",
|
|
38
|
+
alignItems: "center"
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
const defaultIndicator = /* @__PURE__ */ jsx(CircularProgress, { size: 16, ...loadingProps, sx: { color: "inherit", ...loadingProps?.sx || {} } });
|
|
42
|
+
const indicator = /* @__PURE__ */ jsx(Typography, { sx: getPositionStyles(loadingPosition), children: loadingIndicator || defaultIndicator });
|
|
43
|
+
return /* @__PURE__ */ jsxs(
|
|
44
|
+
Button,
|
|
45
|
+
{
|
|
46
|
+
ref,
|
|
47
|
+
disabled: props.disabled,
|
|
48
|
+
onClick: handleClick,
|
|
49
|
+
sx: {
|
|
50
|
+
position: "relative",
|
|
51
|
+
display: "inline-flex",
|
|
52
|
+
alignItems: "center",
|
|
53
|
+
justifyContent: "center",
|
|
54
|
+
...sx
|
|
55
|
+
},
|
|
56
|
+
...props,
|
|
57
|
+
children: [
|
|
58
|
+
loading && loadingPosition === "start" && indicator,
|
|
59
|
+
/* @__PURE__ */ jsx(Typography, { sx: { visibility: loading && loadingOnly ? "hidden" : "visible" }, children }),
|
|
60
|
+
loading && loadingPosition === "center" && indicator,
|
|
61
|
+
loading && loadingPosition === "end" && indicator
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
);
|
|
67
|
+
LoadingButton.displayName = "LoadingButton";
|
|
68
|
+
LoadingButton.defaultProps = {
|
|
69
|
+
loading: false,
|
|
70
|
+
loadingIndicator: void 0,
|
|
71
|
+
loadingPosition: "start",
|
|
72
|
+
loadingProps: {},
|
|
73
|
+
loadingOnly: false
|
|
74
|
+
};
|
|
75
|
+
export default LoadingButton;
|
|
@@ -2,7 +2,6 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
|
|
3
3
|
import Toast from "@arcblock/ux/lib/Toast";
|
|
4
4
|
import { CheckOutlined } from "@mui/icons-material";
|
|
5
|
-
import { LoadingButton } from "@mui/lab";
|
|
6
5
|
import {
|
|
7
6
|
Avatar,
|
|
8
7
|
Box,
|
|
@@ -34,6 +33,7 @@ import {
|
|
|
34
33
|
} from "../libs/util.js";
|
|
35
34
|
import { useMobile } from "../hooks/mobile.js";
|
|
36
35
|
import TruncatedText from "./truncated-text.js";
|
|
36
|
+
import LoadingButton from "./loading-button.js";
|
|
37
37
|
const sortOrder = {
|
|
38
38
|
year: 1,
|
|
39
39
|
month: 2,
|
|
@@ -290,7 +290,6 @@ export default function PricingTable({ table, alignItems, interval, mode, onSele
|
|
|
290
290
|
justifyContent: alignItems === "center" ? "center" : "flex-start",
|
|
291
291
|
sx: {
|
|
292
292
|
flex: "0 1 auto",
|
|
293
|
-
overflow: "auto",
|
|
294
293
|
pb: 2.5
|
|
295
294
|
},
|
|
296
295
|
className: "price-table-wrap",
|
|
@@ -319,7 +318,7 @@ export default function PricingTable({ table, alignItems, interval, mode, onSele
|
|
|
319
318
|
boxShadow: "0px 0px 0px 1px rgba(3, 7, 18, 0.08), 0px 1px 2px -1px rgba(3, 7, 18, 0.08), 0px 2px 4px rgba(3, 7, 18, 0.04)",
|
|
320
319
|
"&:hover": {
|
|
321
320
|
borderColor: mode === "select" && x.is_selected ? "primary.main" : "#ddd",
|
|
322
|
-
boxShadow: "
|
|
321
|
+
boxShadow: "0px 0px 0px 1px var(--shadows-card-hover-1, rgba(2, 7, 19, 0.08)),0px 1px 2px -1px var(--shadows-card-hover-2, rgba(2, 7, 19, 0.08)),0px 2px 8px 0px var(--shadows-card-hover-3, rgba(2, 7, 19, 0.10))"
|
|
323
322
|
},
|
|
324
323
|
width: {
|
|
325
324
|
xs: "100%",
|
package/es/index.d.ts
CHANGED
|
@@ -30,6 +30,7 @@ import Link from './components/link';
|
|
|
30
30
|
import { createLazyComponent } from './components/lazy-loader';
|
|
31
31
|
import OverdueInvoicePayment from './components/over-due-invoice-payment';
|
|
32
32
|
import PaymentBeneficiaries from './components/payment-beneficiaries';
|
|
33
|
+
import LoadingButton from './components/loading-button';
|
|
33
34
|
export { PaymentThemeProvider } from './theme';
|
|
34
35
|
export * from './libs/util';
|
|
35
36
|
export * from './libs/connect';
|
|
@@ -42,4 +43,4 @@ export * from './hooks/mobile';
|
|
|
42
43
|
export * from './hooks/table';
|
|
43
44
|
export * from './hooks/scroll';
|
|
44
45
|
export { translations, createTranslator } from './locales';
|
|
45
|
-
export { createLazyComponent, api, dayjs, FormInput, PhoneInput, AddressForm, StripeForm, Status, Livemode, Switch, ConfirmDialog, CheckoutForm, CheckoutTable, CheckoutDonate, CurrencySelector, Payment, PaymentSummary, PricingTable, ProductSkeleton, Amount, CustomerInvoiceList, CustomerPaymentList, TxLink, TxGas, SafeGuard, PricingItem, CountrySelect, Table, TruncatedText, Link, OverdueInvoicePayment, PaymentBeneficiaries, };
|
|
46
|
+
export { createLazyComponent, api, dayjs, FormInput, PhoneInput, AddressForm, StripeForm, Status, Livemode, Switch, ConfirmDialog, CheckoutForm, CheckoutTable, CheckoutDonate, CurrencySelector, Payment, PaymentSummary, PricingTable, ProductSkeleton, Amount, CustomerInvoiceList, CustomerPaymentList, TxLink, TxGas, SafeGuard, PricingItem, CountrySelect, Table, TruncatedText, Link, OverdueInvoicePayment, PaymentBeneficiaries, LoadingButton, };
|
package/es/index.js
CHANGED
|
@@ -30,6 +30,7 @@ import Link from "./components/link.js";
|
|
|
30
30
|
import { createLazyComponent } from "./components/lazy-loader.js";
|
|
31
31
|
import OverdueInvoicePayment from "./components/over-due-invoice-payment.js";
|
|
32
32
|
import PaymentBeneficiaries from "./components/payment-beneficiaries.js";
|
|
33
|
+
import LoadingButton from "./components/loading-button.js";
|
|
33
34
|
export { PaymentThemeProvider } from "./theme/index.js";
|
|
34
35
|
export * from "./libs/util.js";
|
|
35
36
|
export * from "./libs/connect.js";
|
|
@@ -74,5 +75,6 @@ export {
|
|
|
74
75
|
TruncatedText,
|
|
75
76
|
Link,
|
|
76
77
|
OverdueInvoicePayment,
|
|
77
|
-
PaymentBeneficiaries
|
|
78
|
+
PaymentBeneficiaries,
|
|
79
|
+
LoadingButton
|
|
78
80
|
};
|
package/es/payment/form/index.js
CHANGED
|
@@ -30,6 +30,7 @@ import PhoneInput from "./phone.js";
|
|
|
30
30
|
import StripeCheckout from "./stripe/index.js";
|
|
31
31
|
import { useMobile } from "../../hooks/mobile.js";
|
|
32
32
|
import { validatePhoneNumber } from "../../libs/phone-validator.js";
|
|
33
|
+
import LoadingButton from "../../components/loading-button.js";
|
|
33
34
|
export const waitForCheckoutComplete = async (sessionId) => {
|
|
34
35
|
let result;
|
|
35
36
|
await pWaitFor(
|
|
@@ -143,7 +144,7 @@ export default function PaymentForm({
|
|
|
143
144
|
}, [paymentCurrencyIndex, currencies, setValue]);
|
|
144
145
|
const paymentMethod = useWatch({ control, name: "payment_method" });
|
|
145
146
|
const afterUserLoggedIn = useMemoizedFn(() => {
|
|
146
|
-
if (hasDidWallet(session.user)) {
|
|
147
|
+
if (hasDidWallet(session.user) || skipBindWallet) {
|
|
147
148
|
handleSubmit(onFormSubmit, onFormError)();
|
|
148
149
|
} else {
|
|
149
150
|
session.bindWallet(() => {
|
|
@@ -166,6 +167,8 @@ export default function PaymentForm({
|
|
|
166
167
|
}
|
|
167
168
|
buttonText = session?.user ? buttonText : t("payment.checkout.connect", { action: buttonText });
|
|
168
169
|
const method = paymentMethods.find((x) => x.id === paymentMethod);
|
|
170
|
+
const showForm = session?.user;
|
|
171
|
+
const skipBindWallet = method.type === "stripe";
|
|
169
172
|
const handleConnected = async () => {
|
|
170
173
|
try {
|
|
171
174
|
const result = await waitForCheckoutComplete(checkoutSession.id);
|
|
@@ -292,6 +295,10 @@ export default function PaymentForm({
|
|
|
292
295
|
errorRef.current.scrollIntoView({ behavior: "smooth" });
|
|
293
296
|
}
|
|
294
297
|
if (session?.user) {
|
|
298
|
+
if (skipBindWallet) {
|
|
299
|
+
handleSubmit(onFormSubmit, onFormError)();
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
295
302
|
if (hasDidWallet(session.user)) {
|
|
296
303
|
handleSubmit(onFormSubmit, onFormError)();
|
|
297
304
|
} else {
|
|
@@ -406,7 +413,7 @@ export default function PaymentForm({
|
|
|
406
413
|
}
|
|
407
414
|
)
|
|
408
415
|
] }) }),
|
|
409
|
-
/* @__PURE__ */ jsxs(
|
|
416
|
+
showForm && /* @__PURE__ */ jsxs(
|
|
410
417
|
Stack,
|
|
411
418
|
{
|
|
412
419
|
direction: "column",
|
|
@@ -474,25 +481,20 @@ export default function PaymentForm({
|
|
|
474
481
|
] }) }),
|
|
475
482
|
/* @__PURE__ */ jsx(Divider, { sx: { mt: 2.5, mb: 2.5 } }),
|
|
476
483
|
/* @__PURE__ */ jsx(Fade, { in: true, children: /* @__PURE__ */ jsxs(Stack, { className: "cko-payment-submit", children: [
|
|
477
|
-
/* @__PURE__ */ jsx(Box, { className: "cko-payment-submit-btn", children: /* @__PURE__ */
|
|
478
|
-
|
|
484
|
+
/* @__PURE__ */ jsx(Box, { className: "cko-payment-submit-btn", children: /* @__PURE__ */ jsx(
|
|
485
|
+
LoadingButton,
|
|
479
486
|
{
|
|
480
487
|
variant: "contained",
|
|
481
488
|
color: "primary",
|
|
482
489
|
size: "large",
|
|
483
490
|
className: "cko-submit-button",
|
|
484
491
|
onClick: () => {
|
|
485
|
-
if (state.submitting || state.paying) {
|
|
486
|
-
return;
|
|
487
|
-
}
|
|
488
492
|
onAction();
|
|
489
493
|
},
|
|
490
494
|
fullWidth: true,
|
|
495
|
+
loading: state.submitting || state.paying,
|
|
491
496
|
disabled: state.stripePaying || !quantityInventoryStatus || !payable,
|
|
492
|
-
children:
|
|
493
|
-
(state.submitting || state.paying) && /* @__PURE__ */ jsx(CircularProgress, { size: 16, sx: { mr: 0.5, color: "var(--foregrounds-fg-on-color, #fff)" } }),
|
|
494
|
-
state.submitting || state.paying ? t("payment.checkout.processing") : buttonText
|
|
495
|
-
]
|
|
497
|
+
children: state.submitting || state.paying ? t("payment.checkout.processing") : buttonText
|
|
496
498
|
}
|
|
497
499
|
) }),
|
|
498
500
|
["subscription", "setup"].includes(checkoutSession.mode) && /* @__PURE__ */ jsx(Typography, { sx: { mt: 2.5, color: "text.lighter", fontSize: "0.9rem", lineHeight: "1.1rem" }, children: t("payment.checkout.confirm", { payee }) })
|
|
@@ -2,11 +2,12 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import Center from "@arcblock/ux/lib/Center";
|
|
3
3
|
import Dialog from "@arcblock/ux/lib/Dialog";
|
|
4
4
|
import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
|
|
5
|
-
import { LoadingButton } from "@mui/lab";
|
|
6
5
|
import { CircularProgress, Typography } from "@mui/material";
|
|
7
6
|
import { styled } from "@mui/system";
|
|
8
7
|
import { useSetState } from "ahooks";
|
|
9
8
|
import { useEffect, useCallback } from "react";
|
|
9
|
+
import { useMobile } from "../../../hooks/mobile.js";
|
|
10
|
+
import LoadingButton from "../../../components/loading-button.js";
|
|
10
11
|
const { Elements, PaymentElement, useElements, useStripe, loadStripe } = globalThis.__STRIPE_COMPONENTS__;
|
|
11
12
|
function StripeCheckoutForm({
|
|
12
13
|
clientSecret,
|
|
@@ -105,7 +106,6 @@ function StripeCheckoutForm({
|
|
|
105
106
|
type: "submit",
|
|
106
107
|
disabled: state.confirming || !state.loaded,
|
|
107
108
|
loading: state.confirming,
|
|
108
|
-
loadingPosition: "end",
|
|
109
109
|
variant: "contained",
|
|
110
110
|
color: "primary",
|
|
111
111
|
size: "large",
|
|
@@ -135,7 +135,8 @@ export default function StripeCheckout({
|
|
|
135
135
|
returnUrl = ""
|
|
136
136
|
}) {
|
|
137
137
|
const stripePromise = loadStripe(publicKey);
|
|
138
|
-
const {
|
|
138
|
+
const { isMobile } = useMobile();
|
|
139
|
+
const { t, locale } = useLocaleContext();
|
|
139
140
|
const [state, setState] = useSetState({
|
|
140
141
|
open: true,
|
|
141
142
|
closable: true
|
|
@@ -155,7 +156,21 @@ export default function StripeCheckout({
|
|
|
155
156
|
open: state.open,
|
|
156
157
|
onClose: handleClose,
|
|
157
158
|
disableEscapeKeyDown: true,
|
|
158
|
-
|
|
159
|
+
sx: {
|
|
160
|
+
".StripeElement": {
|
|
161
|
+
minWidth: isMobile ? "100%" : "500px",
|
|
162
|
+
py: 1
|
|
163
|
+
},
|
|
164
|
+
form: {
|
|
165
|
+
justifyContent: "flex-start"
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
PaperProps: {
|
|
169
|
+
style: {
|
|
170
|
+
minWidth: isMobile ? "100%" : "500px"
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
children: /* @__PURE__ */ jsx(Elements, { options: { clientSecret, locale: locale === "zh" ? "zh-CN" : "en" }, stripe: stripePromise, children: /* @__PURE__ */ jsx(
|
|
159
174
|
StripeCheckoutForm,
|
|
160
175
|
{
|
|
161
176
|
clientSecret,
|
package/es/payment/index.js
CHANGED
package/es/payment/summary.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
|
|
3
3
|
import { HelpOutline } from "@mui/icons-material";
|
|
4
|
-
import { LoadingButton } from "@mui/lab";
|
|
5
4
|
import { Box, Divider, Fade, Grow, Stack, Tooltip, Typography, Collapse, IconButton } from "@mui/material";
|
|
6
5
|
import { BN, fromTokenToUnit, fromUnitToToken } from "@ocap/util";
|
|
7
6
|
import { useRequest, useSetState } from "ahooks";
|
|
@@ -18,6 +17,7 @@ import ProductItem from "./product-item.js";
|
|
|
18
17
|
import Livemode from "../components/livemode.js";
|
|
19
18
|
import { usePaymentContext } from "../contexts/payment.js";
|
|
20
19
|
import { useMobile } from "../hooks/mobile.js";
|
|
20
|
+
import LoadingButton from "../components/loading-button.js";
|
|
21
21
|
const ExpandMore = styled((props) => {
|
|
22
22
|
const { expand, ...other } = props;
|
|
23
23
|
return /* @__PURE__ */ jsx(IconButton, { ...other });
|
package/es/theme/index.js
CHANGED
package/lib/checkout/donate.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DonationSettings, TCheckoutSessionExpanded, TPaymentCurrency, TPaymentMethod } from '@blocklet/payment-types';
|
|
1
|
+
import type { DonationSettings, PaymentBeneficiary, TCheckoutSessionExpanded, TPaymentCurrency, TPaymentMethod } from '@blocklet/payment-types';
|
|
2
2
|
import { type ButtonProps as MUIButtonProps } from '@mui/material';
|
|
3
3
|
import type { CheckoutProps, PaymentThemeOptions } from '../types';
|
|
4
4
|
export type DonateHistory = {
|
|
@@ -7,14 +7,38 @@ export type DonateHistory = {
|
|
|
7
7
|
method: TPaymentMethod;
|
|
8
8
|
totalAmount: string;
|
|
9
9
|
};
|
|
10
|
-
export type
|
|
11
|
-
|
|
10
|
+
export type CheckoutDonateSettings = {
|
|
11
|
+
target: string;
|
|
12
|
+
title: string;
|
|
13
|
+
description: string;
|
|
14
|
+
reference: string;
|
|
15
|
+
beneficiaries: PaymentBeneficiary[];
|
|
16
|
+
amount?: {
|
|
17
|
+
presets?: string[];
|
|
18
|
+
preset?: string;
|
|
19
|
+
minimum?: string;
|
|
20
|
+
maximum?: string;
|
|
21
|
+
custom?: boolean;
|
|
22
|
+
};
|
|
23
|
+
appearance?: {
|
|
24
|
+
button?: {
|
|
25
|
+
text?: any;
|
|
26
|
+
icon?: any;
|
|
27
|
+
size?: string;
|
|
28
|
+
color?: string;
|
|
29
|
+
variant?: string;
|
|
30
|
+
};
|
|
31
|
+
history?: {
|
|
32
|
+
variant?: string;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
};
|
|
12
36
|
export interface ButtonType extends Omit<MUIButtonProps, 'text' | 'icon'> {
|
|
13
37
|
text?: string | React.ReactNode;
|
|
14
38
|
icon: React.ReactNode;
|
|
15
39
|
}
|
|
16
40
|
export type DonateProps = Pick<CheckoutProps, 'onPaid' | 'onError'> & {
|
|
17
|
-
settings:
|
|
41
|
+
settings: CheckoutDonateSettings;
|
|
18
42
|
livemode?: boolean;
|
|
19
43
|
timeout?: number;
|
|
20
44
|
mode?: 'inline' | 'default' | 'custom';
|
package/lib/checkout/donate.js
CHANGED
|
@@ -385,10 +385,7 @@ function CheckoutDonateInner({
|
|
|
385
385
|
}, timeout);
|
|
386
386
|
};
|
|
387
387
|
if (donation.error) {
|
|
388
|
-
return
|
|
389
|
-
severity: "error",
|
|
390
|
-
children: (0, _util.formatError)(donation.error)
|
|
391
|
-
});
|
|
388
|
+
return null;
|
|
392
389
|
}
|
|
393
390
|
const handlePopoverOpen = event => {
|
|
394
391
|
donation.run();
|
|
@@ -519,10 +516,10 @@ function CheckoutDonateInner({
|
|
|
519
516
|
}
|
|
520
517
|
if (mode === "custom") {
|
|
521
518
|
return children && typeof children === "function" ? /* @__PURE__ */(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
|
|
522
|
-
children: children(startDonate, `${(0, _util.formatAmount)(supporters.data?.totalAmount || "0", supporters.data?.currency?.decimal)} ${supporters.data?.currency?.symbol}`, supporters.data || {}, !!supporters.loading, donateSettings)
|
|
519
|
+
children: children(startDonate, `${(0, _util.formatAmount)(supporters.data?.totalAmount || "0", supporters.data?.currency?.decimal)} ${supporters.data?.currency?.symbol || ""}`, supporters.data || {}, !!supporters.loading, donateSettings)
|
|
523
520
|
}) : /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Typography, {
|
|
524
|
-
children: ["Please provide a valid render function ", /* @__PURE__ */(0, _jsxRuntime.jsx)("pre", {
|
|
525
|
-
children: "(openDonate, donateTotalAmount, supporters) => ReactNode"
|
|
521
|
+
children: ["Please provide a valid render function", " ", /* @__PURE__ */(0, _jsxRuntime.jsx)("pre", {
|
|
522
|
+
children: "(openDonate, donateTotalAmount, supporters, loading, donateSettings) => ReactNode"
|
|
526
523
|
})]
|
|
527
524
|
});
|
|
528
525
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type ButtonProps, type CircularProgressProps } from '@mui/material';
|
|
2
|
+
export interface LoadingButtonProps extends ButtonProps {
|
|
3
|
+
loading?: boolean;
|
|
4
|
+
loadingIndicator?: React.ReactNode;
|
|
5
|
+
loadingPosition?: 'start' | 'center' | 'end';
|
|
6
|
+
loadingProps?: Partial<CircularProgressProps>;
|
|
7
|
+
loadingOnly?: boolean;
|
|
8
|
+
}
|
|
9
|
+
declare const LoadingButton: import("react").ForwardRefExoticComponent<Omit<LoadingButtonProps, "ref"> & import("react").RefAttributes<HTMLButtonElement>>;
|
|
10
|
+
export default LoadingButton;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
8
|
+
var _material = require("@mui/material");
|
|
9
|
+
var _react = require("react");
|
|
10
|
+
const LoadingButton = (0, _react.forwardRef)(({
|
|
11
|
+
children,
|
|
12
|
+
loading,
|
|
13
|
+
loadingPosition = "start",
|
|
14
|
+
loadingIndicator,
|
|
15
|
+
loadingProps = {},
|
|
16
|
+
onClick,
|
|
17
|
+
sx,
|
|
18
|
+
loadingOnly = false,
|
|
19
|
+
...props
|
|
20
|
+
}, ref) => {
|
|
21
|
+
const handleClick = e => {
|
|
22
|
+
if (loading) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
onClick?.(e);
|
|
26
|
+
};
|
|
27
|
+
const getPositionStyles = position => {
|
|
28
|
+
return {
|
|
29
|
+
color: "inherit",
|
|
30
|
+
...(position === "start" && {
|
|
31
|
+
mr: 1
|
|
32
|
+
}),
|
|
33
|
+
...(position === "end" && {
|
|
34
|
+
ml: 1
|
|
35
|
+
}),
|
|
36
|
+
...(position === "center" && {
|
|
37
|
+
position: "absolute",
|
|
38
|
+
left: "50%",
|
|
39
|
+
transform: "translateY(-50%) translateX(-50%)",
|
|
40
|
+
top: "50%"
|
|
41
|
+
}),
|
|
42
|
+
display: "inline-flex",
|
|
43
|
+
alignItems: "center"
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
const defaultIndicator = /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.CircularProgress, {
|
|
47
|
+
size: 16,
|
|
48
|
+
...loadingProps,
|
|
49
|
+
sx: {
|
|
50
|
+
color: "inherit",
|
|
51
|
+
...(loadingProps?.sx || {})
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
const indicator = /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
55
|
+
sx: getPositionStyles(loadingPosition),
|
|
56
|
+
children: loadingIndicator || defaultIndicator
|
|
57
|
+
});
|
|
58
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Button, {
|
|
59
|
+
ref,
|
|
60
|
+
disabled: props.disabled,
|
|
61
|
+
onClick: handleClick,
|
|
62
|
+
sx: {
|
|
63
|
+
position: "relative",
|
|
64
|
+
display: "inline-flex",
|
|
65
|
+
alignItems: "center",
|
|
66
|
+
justifyContent: "center",
|
|
67
|
+
...sx
|
|
68
|
+
},
|
|
69
|
+
...props,
|
|
70
|
+
children: [loading && loadingPosition === "start" && indicator, /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
71
|
+
sx: {
|
|
72
|
+
visibility: loading && loadingOnly ? "hidden" : "visible"
|
|
73
|
+
},
|
|
74
|
+
children
|
|
75
|
+
}), loading && loadingPosition === "center" && indicator, loading && loadingPosition === "end" && indicator]
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
LoadingButton.displayName = "LoadingButton";
|
|
79
|
+
LoadingButton.defaultProps = {
|
|
80
|
+
loading: false,
|
|
81
|
+
loadingIndicator: void 0,
|
|
82
|
+
loadingPosition: "start",
|
|
83
|
+
loadingProps: {},
|
|
84
|
+
loadingOnly: false
|
|
85
|
+
};
|
|
86
|
+
module.exports = LoadingButton;
|
|
@@ -8,7 +8,6 @@ var _jsxRuntime = require("react/jsx-runtime");
|
|
|
8
8
|
var _context = require("@arcblock/ux/lib/Locale/context");
|
|
9
9
|
var _Toast = _interopRequireDefault(require("@arcblock/ux/lib/Toast"));
|
|
10
10
|
var _iconsMaterial = require("@mui/icons-material");
|
|
11
|
-
var _lab = require("@mui/lab");
|
|
12
11
|
var _material = require("@mui/material");
|
|
13
12
|
var _system = require("@mui/system");
|
|
14
13
|
var _ahooks = require("ahooks");
|
|
@@ -19,6 +18,7 @@ var _payment = require("../contexts/payment");
|
|
|
19
18
|
var _util2 = require("../libs/util");
|
|
20
19
|
var _mobile = require("../hooks/mobile");
|
|
21
20
|
var _truncatedText = _interopRequireDefault(require("./truncated-text"));
|
|
21
|
+
var _loadingButton = _interopRequireDefault(require("./loading-button"));
|
|
22
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
23
|
const sortOrder = {
|
|
24
24
|
year: 1,
|
|
@@ -314,7 +314,6 @@ function PricingTable({
|
|
|
314
314
|
justifyContent: alignItems === "center" ? "center" : "flex-start",
|
|
315
315
|
sx: {
|
|
316
316
|
flex: "0 1 auto",
|
|
317
|
-
overflow: "auto",
|
|
318
317
|
pb: 2.5
|
|
319
318
|
},
|
|
320
319
|
className: "price-table-wrap",
|
|
@@ -341,7 +340,7 @@ function PricingTable({
|
|
|
341
340
|
boxShadow: "0px 0px 0px 1px rgba(3, 7, 18, 0.08), 0px 1px 2px -1px rgba(3, 7, 18, 0.08), 0px 2px 4px rgba(3, 7, 18, 0.04)",
|
|
342
341
|
"&:hover": {
|
|
343
342
|
borderColor: mode === "select" && x.is_selected ? "primary.main" : "#ddd",
|
|
344
|
-
boxShadow: "
|
|
343
|
+
boxShadow: "0px 0px 0px 1px var(--shadows-card-hover-1, rgba(2, 7, 19, 0.08)),0px 1px 2px -1px var(--shadows-card-hover-2, rgba(2, 7, 19, 0.08)),0px 2px 8px 0px var(--shadows-card-hover-3, rgba(2, 7, 19, 0.10))"
|
|
345
344
|
},
|
|
346
345
|
width: {
|
|
347
346
|
xs: "100%",
|
|
@@ -510,7 +509,7 @@ function Subscribe({
|
|
|
510
509
|
_Toast.default.error((0, _util2.formatError)(err));
|
|
511
510
|
}
|
|
512
511
|
};
|
|
513
|
-
return /* @__PURE__ */(0, _jsxRuntime.jsx)(
|
|
512
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsx)(_loadingButton.default, {
|
|
514
513
|
fullWidth: true,
|
|
515
514
|
size: "medium",
|
|
516
515
|
variant: "contained",
|
package/lib/index.d.ts
CHANGED
|
@@ -30,6 +30,7 @@ import Link from './components/link';
|
|
|
30
30
|
import { createLazyComponent } from './components/lazy-loader';
|
|
31
31
|
import OverdueInvoicePayment from './components/over-due-invoice-payment';
|
|
32
32
|
import PaymentBeneficiaries from './components/payment-beneficiaries';
|
|
33
|
+
import LoadingButton from './components/loading-button';
|
|
33
34
|
export { PaymentThemeProvider } from './theme';
|
|
34
35
|
export * from './libs/util';
|
|
35
36
|
export * from './libs/connect';
|
|
@@ -42,4 +43,4 @@ export * from './hooks/mobile';
|
|
|
42
43
|
export * from './hooks/table';
|
|
43
44
|
export * from './hooks/scroll';
|
|
44
45
|
export { translations, createTranslator } from './locales';
|
|
45
|
-
export { createLazyComponent, api, dayjs, FormInput, PhoneInput, AddressForm, StripeForm, Status, Livemode, Switch, ConfirmDialog, CheckoutForm, CheckoutTable, CheckoutDonate, CurrencySelector, Payment, PaymentSummary, PricingTable, ProductSkeleton, Amount, CustomerInvoiceList, CustomerPaymentList, TxLink, TxGas, SafeGuard, PricingItem, CountrySelect, Table, TruncatedText, Link, OverdueInvoicePayment, PaymentBeneficiaries, };
|
|
46
|
+
export { createLazyComponent, api, dayjs, FormInput, PhoneInput, AddressForm, StripeForm, Status, Livemode, Switch, ConfirmDialog, CheckoutForm, CheckoutTable, CheckoutDonate, CurrencySelector, Payment, PaymentSummary, PricingTable, ProductSkeleton, Amount, CustomerInvoiceList, CustomerPaymentList, TxLink, TxGas, SafeGuard, PricingItem, CountrySelect, Table, TruncatedText, Link, OverdueInvoicePayment, PaymentBeneficiaries, LoadingButton, };
|