@blocklet/payment-react 1.18.6 → 1.18.8

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.
Files changed (70) hide show
  1. package/README.md +394 -341
  2. package/es/checkout/donate.d.ts +29 -4
  3. package/es/checkout/donate.js +193 -95
  4. package/es/components/livemode.js +1 -1
  5. package/es/components/loading-button.d.ts +10 -0
  6. package/es/components/loading-button.js +75 -0
  7. package/es/components/pricing-table.js +2 -3
  8. package/es/components/table.js +1 -1
  9. package/es/index.d.ts +2 -1
  10. package/es/index.js +3 -1
  11. package/es/libs/util.d.ts +1 -0
  12. package/es/libs/util.js +10 -1
  13. package/es/payment/amount.js +1 -1
  14. package/es/payment/form/index.js +14 -12
  15. package/es/payment/form/stripe/form.js +20 -5
  16. package/es/payment/index.js +0 -1
  17. package/es/payment/product-card.js +2 -2
  18. package/es/payment/product-item.js +1 -1
  19. package/es/payment/product-skeleton.js +2 -2
  20. package/es/payment/skeleton/donation.js +1 -1
  21. package/es/payment/skeleton/overview.js +1 -1
  22. package/es/payment/skeleton/payment.js +1 -1
  23. package/es/payment/summary.js +2 -2
  24. package/es/theme/index.js +5 -3
  25. package/es/theme/typography.js +8 -8
  26. package/lib/checkout/donate.d.ts +29 -4
  27. package/lib/checkout/donate.js +197 -136
  28. package/lib/components/livemode.js +1 -1
  29. package/lib/components/loading-button.d.ts +10 -0
  30. package/lib/components/loading-button.js +86 -0
  31. package/lib/components/pricing-table.js +3 -4
  32. package/lib/components/table.js +1 -1
  33. package/lib/index.d.ts +2 -1
  34. package/lib/index.js +8 -0
  35. package/lib/libs/util.d.ts +1 -0
  36. package/lib/libs/util.js +7 -0
  37. package/lib/payment/amount.js +1 -1
  38. package/lib/payment/form/index.js +14 -15
  39. package/lib/payment/form/stripe/form.js +25 -6
  40. package/lib/payment/index.js +0 -1
  41. package/lib/payment/product-card.js +2 -2
  42. package/lib/payment/product-item.js +1 -1
  43. package/lib/payment/product-skeleton.js +2 -2
  44. package/lib/payment/skeleton/donation.js +1 -1
  45. package/lib/payment/skeleton/overview.js +1 -1
  46. package/lib/payment/skeleton/payment.js +1 -1
  47. package/lib/payment/summary.js +4 -4
  48. package/lib/theme/index.js +5 -3
  49. package/lib/theme/typography.js +8 -8
  50. package/package.json +8 -8
  51. package/src/checkout/donate.tsx +209 -128
  52. package/src/components/livemode.tsx +1 -1
  53. package/src/components/loading-button.tsx +100 -0
  54. package/src/components/pricing-table.tsx +3 -3
  55. package/src/components/table.tsx +1 -1
  56. package/src/index.ts +2 -0
  57. package/src/libs/util.ts +11 -1
  58. package/src/payment/amount.tsx +1 -1
  59. package/src/payment/form/index.tsx +65 -60
  60. package/src/payment/form/stripe/form.tsx +21 -6
  61. package/src/payment/index.tsx +0 -1
  62. package/src/payment/product-card.tsx +2 -2
  63. package/src/payment/product-item.tsx +1 -1
  64. package/src/payment/product-skeleton.tsx +2 -2
  65. package/src/payment/skeleton/donation.tsx +1 -1
  66. package/src/payment/skeleton/overview.tsx +1 -1
  67. package/src/payment/skeleton/payment.tsx +1 -1
  68. package/src/payment/summary.tsx +2 -2
  69. package/src/theme/index.tsx +3 -1
  70. package/src/theme/typography.ts +8 -8
@@ -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,28 +481,23 @@ 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__ */ jsxs(
478
- Button,
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
- ["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 }) })
500
+ ["subscription", "setup"].includes(checkoutSession.mode) && /* @__PURE__ */ jsx(Typography, { sx: { mt: 2.5, color: "text.lighter", fontSize: "0.7875rem", lineHeight: "0.9625rem" }, children: t("payment.checkout.confirm", { payee }) })
499
501
  ] }) }),
500
502
  state.customerLimited && /* @__PURE__ */ jsx(
501
503
  ConfirmDialog,
@@ -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,
@@ -101,11 +102,10 @@ function StripeCheckoutForm({
101
102
  LoadingButton,
102
103
  {
103
104
  fullWidth: true,
104
- sx: { mt: 2, mb: 1, borderRadius: 0, fontSize: "1.1rem" },
105
+ sx: { mt: 2, mb: 1, borderRadius: 0, fontSize: "0.875rem" },
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 { t } = useLocaleContext();
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
- children: /* @__PURE__ */ jsx(Elements, { options: { clientSecret }, stripe: stripePromise, children: /* @__PURE__ */ jsx(
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,
@@ -514,7 +514,6 @@ export const Root = styled(Box)`
514
514
  .MuiButtonBase-root {
515
515
  font-size: 1.3rem;
516
516
  position: relative;
517
- padding: 4px 22px;
518
517
  }
519
518
 
520
519
  .cko-submit-progress {
@@ -34,12 +34,12 @@ export default function ProductCard({ size, variant, name, logo, description, ex
34
34
  {
35
35
  variant: "body1",
36
36
  title: description,
37
- sx: { fontSize: "0.85rem", mb: 0.5, lineHeight: 1.2, textAlign: "left" },
37
+ sx: { fontSize: "0.74375rem", mb: 0.5, lineHeight: 1.2, textAlign: "left" },
38
38
  color: "text.lighter",
39
39
  children: description
40
40
  }
41
41
  ),
42
- extra && /* @__PURE__ */ jsx(Box, { sx: { fontSize: "0.85rem" }, color: "text.lighter", children: extra })
42
+ extra && /* @__PURE__ */ jsx(Box, { sx: { fontSize: "0.74375rem" }, color: "text.lighter", children: extra })
43
43
  ]
44
44
  }
45
45
  )
@@ -65,7 +65,7 @@ export default function ProductItem({
65
65
  ),
66
66
  /* @__PURE__ */ jsxs(Stack, { direction: "column", alignItems: "flex-end", flex: 1, children: [
67
67
  /* @__PURE__ */ jsx(Typography, { sx: { color: "text.primary", fontWeight: 500, whiteSpace: "nowrap" }, gutterBottom: true, children: primaryText }),
68
- pricing.secondary && /* @__PURE__ */ jsx(Typography, { sx: { fontSize: "0.85rem", color: "text.lighter" }, children: pricing.secondary })
68
+ pricing.secondary && /* @__PURE__ */ jsx(Typography, { sx: { fontSize: "0.74375rem", color: "text.lighter" }, children: pricing.secondary })
69
69
  ] })
70
70
  ]
71
71
  }
@@ -21,12 +21,12 @@ export default function ProductSkeleton({ count }) {
21
21
  },
22
22
  children: [
23
23
  /* @__PURE__ */ jsx(Typography, { component: "div", variant: "h4", sx: { width: "50%" }, children: /* @__PURE__ */ jsx(Skeleton, {}) }),
24
- /* @__PURE__ */ jsx(Skeleton, { variant: "text", sx: { fontSize: "1rem", width: "60%" } }),
24
+ /* @__PURE__ */ jsx(Skeleton, { variant: "text", sx: { fontSize: "0.875rem", width: "60%" } }),
25
25
  /* @__PURE__ */ jsx(Typography, { component: "div", variant: "h3", sx: { width: "60%" }, children: /* @__PURE__ */ jsx(Skeleton, {}) }),
26
26
  /* @__PURE__ */ jsx(Typography, { component: "div", variant: "h3", sx: { width: "100%" }, children: /* @__PURE__ */ jsx(Skeleton, {}) }),
27
27
  Array.from({ length: count }).map((_, i) => (
28
28
  // eslint-disable-next-line react/no-array-index-key
29
- /* @__PURE__ */ jsx(Skeleton, { variant: "text", sx: { fontSize: "1rem", width: "60%" } }, i)
29
+ /* @__PURE__ */ jsx(Skeleton, { variant: "text", sx: { fontSize: "0.875rem", width: "60%" } }, i)
30
30
  ))
31
31
  ]
32
32
  }
@@ -2,7 +2,7 @@ import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { Box, Divider, Fade, Skeleton, Stack } from "@mui/material";
3
3
  export default function DonationSkeleton() {
4
4
  return /* @__PURE__ */ jsx(Fade, { in: true, children: /* @__PURE__ */ jsxs(Stack, { direction: "column", children: [
5
- /* @__PURE__ */ jsx(Skeleton, { variant: "text", sx: { fontSize: "2rem", width: "40%" } }),
5
+ /* @__PURE__ */ jsx(Skeleton, { variant: "text", sx: { fontSize: "1.75rem", width: "40%" } }),
6
6
  /* @__PURE__ */ jsx(Skeleton, { sx: { mt: 2 }, variant: "rounded", height: 40 }),
7
7
  /* @__PURE__ */ jsx(
8
8
  Divider,
@@ -2,7 +2,7 @@ import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { Fade, Skeleton, Stack, Typography } from "@mui/material";
3
3
  export default function OverviewSkeleton() {
4
4
  return /* @__PURE__ */ jsx(Fade, { in: true, children: /* @__PURE__ */ jsxs(Stack, { direction: "column", children: [
5
- /* @__PURE__ */ jsx(Stack, { direction: "row", alignItems: "center", spacing: 2, children: /* @__PURE__ */ jsx(Skeleton, { variant: "text", sx: { fontSize: "2rem", width: "40%" } }) }),
5
+ /* @__PURE__ */ jsx(Stack, { direction: "row", alignItems: "center", spacing: 2, children: /* @__PURE__ */ jsx(Skeleton, { variant: "text", sx: { fontSize: "1.75rem", width: "40%" } }) }),
6
6
  /* @__PURE__ */ jsx(Skeleton, { sx: { mt: 2 }, variant: "rounded", height: 100 }),
7
7
  /* @__PURE__ */ jsx(Typography, { mt: 2, component: "div", variant: "h4", children: /* @__PURE__ */ jsx(Skeleton, {}) }),
8
8
  /* @__PURE__ */ jsx(Typography, { component: "div", variant: "h2", children: /* @__PURE__ */ jsx(Skeleton, {}) })
@@ -2,7 +2,7 @@ import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { Box, Fade, Skeleton, Stack, Typography } from "@mui/material";
3
3
  export default function PaymentSkeleton() {
4
4
  return /* @__PURE__ */ jsx(Fade, { in: true, children: /* @__PURE__ */ jsxs(Stack, { direction: "column", children: [
5
- /* @__PURE__ */ jsx(Skeleton, { variant: "text", sx: { fontSize: "2rem", width: "40%" } }),
5
+ /* @__PURE__ */ jsx(Skeleton, { variant: "text", sx: { fontSize: "1.75rem", width: "40%" } }),
6
6
  /* @__PURE__ */ jsx(Skeleton, { sx: { mt: 2 }, variant: "rounded", height: 68 }),
7
7
  /* @__PURE__ */ jsxs(Box, { mt: 1, children: [
8
8
  /* @__PURE__ */ jsx(Typography, { component: "div", variant: "h4", mb: -1, children: /* @__PURE__ */ jsx(Skeleton, {}) }),
@@ -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 });
@@ -309,7 +309,7 @@ export default function PaymentSummary({
309
309
  Typography,
310
310
  {
311
311
  component: "div",
312
- sx: { fontSize: "0.9rem", color: "text.lighter", textAlign: "right", margin: "-2px 0 8px" },
312
+ sx: { fontSize: "0.7875rem", color: "text.lighter", textAlign: "right", margin: "-2px 0 8px" },
313
313
  children: headlines.then
314
314
  }
315
315
  )
package/es/theme/index.js CHANGED
@@ -50,9 +50,10 @@ export function PaymentThemeProvider({
50
50
  },
51
51
  styleOverrides: {
52
52
  root: {
53
- fontSize: "1rem",
53
+ fontSize: "0.875rem",
54
54
  fontWeight: 500,
55
- textTransform: "none"
55
+ textTransform: "none",
56
+ boxShadow: "none"
56
57
  },
57
58
  containedPrimary: {
58
59
  backgroundColor: "var(--buttons-button-inverted, #010714)",
@@ -97,7 +98,8 @@ export function PaymentThemeProvider({
97
98
  MuiTab: {
98
99
  styleOverrides: {
99
100
  root: {
100
- textTransform: "none"
101
+ textTransform: "none",
102
+ fontSize: "0.875rem"
101
103
  }
102
104
  }
103
105
  },
@@ -1,6 +1,6 @@
1
1
  export const typography = {
2
2
  h1: {
3
- fontSize: "1.875rem",
3
+ fontSize: "1.5rem",
4
4
  lineHeight: 1.2,
5
5
  fontWeight: 800,
6
6
  letterSpacing: "-.025em"
@@ -12,38 +12,38 @@ export const typography = {
12
12
  letterSpacing: "-.025em"
13
13
  },
14
14
  h3: {
15
- fontSize: "1.25rem",
15
+ fontSize: "1.09375rem",
16
16
  lineHeight: 1.4,
17
17
  fontWeight: 600,
18
18
  letterSpacing: "-.025em"
19
19
  },
20
20
  h4: {
21
- fontSize: "1.125rem",
21
+ fontSize: "1.09375rem",
22
22
  lineHeight: 1.5,
23
23
  fontWeight: 600
24
24
  },
25
25
  h5: {
26
- fontSize: "1rem",
26
+ fontSize: "0.875rem",
27
27
  lineHeight: 1.75,
28
28
  fontWeight: 400
29
29
  },
30
30
  h6: {
31
- fontSize: "1rem",
31
+ fontSize: "0.875rem",
32
32
  lineHeight: 1.75,
33
33
  fontWeight: 400
34
34
  },
35
35
  subtitle1: {
36
- fontSize: "1rem",
36
+ fontSize: "0.875rem",
37
37
  lineHeight: 1.75,
38
38
  fontWeight: 400
39
39
  },
40
40
  subtitle2: {
41
- fontSize: "1rem",
41
+ fontSize: "0.875rem",
42
42
  lineHeight: 1.75,
43
43
  fontWeight: 400
44
44
  },
45
45
  body1: {
46
- fontSize: "1rem",
46
+ fontSize: "0.875rem",
47
47
  lineHeight: 1.75
48
48
  },
49
49
  fontWeightLight: 300,
@@ -1,20 +1,45 @@
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 = {
5
5
  supporters: TCheckoutSessionExpanded[];
6
6
  currency: TPaymentCurrency;
7
7
  method: TPaymentMethod;
8
+ total?: number;
8
9
  totalAmount: string;
9
10
  };
10
- export type RequiredDonationSettings = Pick<DonationSettings, 'target' | 'title' | 'description' | 'reference' | 'beneficiaries'>;
11
- type OptionalDonationSettings = Partial<Omit<DonationSettings, keyof RequiredDonationSettings>>;
11
+ export type CheckoutDonateSettings = {
12
+ target: string;
13
+ title: string;
14
+ description: string;
15
+ reference: string;
16
+ beneficiaries: PaymentBeneficiary[];
17
+ amount?: {
18
+ presets?: string[];
19
+ preset?: string;
20
+ minimum?: string;
21
+ maximum?: string;
22
+ custom?: boolean;
23
+ };
24
+ appearance?: {
25
+ button?: {
26
+ text?: any;
27
+ icon?: any;
28
+ size?: string;
29
+ color?: string;
30
+ variant?: string;
31
+ };
32
+ history?: {
33
+ variant?: string;
34
+ };
35
+ };
36
+ };
12
37
  export interface ButtonType extends Omit<MUIButtonProps, 'text' | 'icon'> {
13
38
  text?: string | React.ReactNode;
14
39
  icon: React.ReactNode;
15
40
  }
16
41
  export type DonateProps = Pick<CheckoutProps, 'onPaid' | 'onError'> & {
17
- settings: RequiredDonationSettings & OptionalDonationSettings;
42
+ settings: CheckoutDonateSettings;
18
43
  livemode?: boolean;
19
44
  timeout?: number;
20
45
  mode?: 'inline' | 'default' | 'custom';