@blocklet/payment-react 1.17.12 → 1.18.1

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 (54) hide show
  1. package/es/checkout/donate.js +40 -10
  2. package/es/checkout/form.d.ts +2 -1
  3. package/es/checkout/form.js +32 -45
  4. package/es/components/payment-beneficiaries.d.ts +24 -0
  5. package/es/components/payment-beneficiaries.js +70 -0
  6. package/es/index.d.ts +2 -1
  7. package/es/index.js +3 -1
  8. package/es/locales/en.js +13 -1
  9. package/es/locales/zh.js +13 -1
  10. package/es/payment/donation-form.d.ts +24 -0
  11. package/es/payment/donation-form.js +603 -0
  12. package/es/payment/error.d.ts +1 -1
  13. package/es/payment/error.js +11 -1
  14. package/es/payment/form/index.d.ts +9 -3
  15. package/es/payment/form/index.js +39 -4
  16. package/es/payment/product-donation.js +98 -57
  17. package/es/payment/skeleton/donation.d.ts +1 -0
  18. package/es/payment/skeleton/donation.js +30 -0
  19. package/es/theme/index.js +3 -0
  20. package/es/types/index.d.ts +2 -0
  21. package/lib/checkout/donate.js +76 -10
  22. package/lib/checkout/form.d.ts +2 -1
  23. package/lib/checkout/form.js +39 -49
  24. package/lib/components/payment-beneficiaries.d.ts +24 -0
  25. package/lib/components/payment-beneficiaries.js +113 -0
  26. package/lib/index.d.ts +2 -1
  27. package/lib/index.js +8 -0
  28. package/lib/locales/en.js +13 -1
  29. package/lib/locales/zh.js +13 -1
  30. package/lib/payment/donation-form.d.ts +24 -0
  31. package/lib/payment/donation-form.js +644 -0
  32. package/lib/payment/error.d.ts +1 -1
  33. package/lib/payment/error.js +2 -2
  34. package/lib/payment/form/index.d.ts +9 -3
  35. package/lib/payment/form/index.js +35 -2
  36. package/lib/payment/product-donation.js +140 -73
  37. package/lib/payment/skeleton/donation.d.ts +1 -0
  38. package/lib/payment/skeleton/donation.js +66 -0
  39. package/lib/theme/index.js +3 -0
  40. package/lib/types/index.d.ts +2 -0
  41. package/package.json +3 -3
  42. package/src/checkout/donate.tsx +54 -11
  43. package/src/checkout/form.tsx +17 -31
  44. package/src/components/payment-beneficiaries.tsx +97 -0
  45. package/src/index.ts +2 -0
  46. package/src/locales/en.tsx +12 -0
  47. package/src/locales/zh.tsx +12 -0
  48. package/src/payment/donation-form.tsx +646 -0
  49. package/src/payment/error.tsx +13 -4
  50. package/src/payment/form/index.tsx +46 -4
  51. package/src/payment/product-donation.tsx +91 -40
  52. package/src/payment/skeleton/donation.tsx +35 -0
  53. package/src/theme/index.tsx +3 -0
  54. package/src/types/index.ts +2 -0
@@ -27,6 +27,8 @@ import { formatAmount, formatBNStr, formatDateTime, formatError, getCustomerAvat
27
27
  import CheckoutForm from "./form.js";
28
28
  import { PaymentThemeProvider } from "../theme/index.js";
29
29
  import { usePaymentContext } from "../contexts/payment.js";
30
+ import Livemode from "../components/livemode.js";
31
+ import { useMobile } from "../hooks/mobile.js";
30
32
  const donationCache = {};
31
33
  const createOrUpdateDonation = (settings, livemode = true) => {
32
34
  const donationKey = `${settings.target}-${livemode}`;
@@ -232,8 +234,11 @@ function CheckoutDonateInner({
232
234
  children
233
235
  }) {
234
236
  const { state, setState, donation, supporters } = useDonation(settings, livemode, mode);
237
+ const customers = uniqBy(supporters?.data?.supporters || [], "customer_did");
238
+ const { t } = useLocaleContext();
235
239
  const [anchorEl, setAnchorEl] = useState(null);
236
240
  const [popoverOpen, setPopoverOpen] = useState(false);
241
+ const { isMobile } = useMobile();
237
242
  const handlePaid = (...args) => {
238
243
  if (onPaid) {
239
244
  onPaid(...args);
@@ -380,23 +385,43 @@ function CheckoutDonateInner({
380
385
  Dialog,
381
386
  {
382
387
  open: state.open,
383
- title: settings.title,
388
+ title: /* @__PURE__ */ jsxs(Box, { display: "flex", alignItems: "center", gap: 0.5, children: [
389
+ /* @__PURE__ */ jsx(Typography, { variant: "h3", sx: { maxWidth: 320, textOverflow: "ellipsis", overflow: "hidden" }, children: settings.title }),
390
+ !donation.data.livemode && /* @__PURE__ */ jsx(Livemode, { sx: { width: "fit-content" } })
391
+ ] }),
384
392
  maxWidth: "md",
385
- showCloseButton: true,
393
+ toolbar: isMobile ? null : /* @__PURE__ */ jsxs(Box, { display: "flex", alignItems: "center", gap: 1, sx: { color: "text.secondary" }, children: [
394
+ /* @__PURE__ */ jsx(AvatarGroup, { total: customers?.length, max: 5, children: customers.map((x) => /* @__PURE__ */ jsx(
395
+ Avatar,
396
+ {
397
+ title: x.customer?.name,
398
+ src: getCustomerAvatar(
399
+ x.customer?.did,
400
+ x?.updated_at ? new Date(x.updated_at).toISOString() : "",
401
+ 18
402
+ ),
403
+ variant: "circular",
404
+ sx: { width: 18, height: 18 }
405
+ },
406
+ x.id
407
+ )) }),
408
+ customers?.length > 0 && t("payment.checkout.donation.gaveTips", { count: customers?.length })
409
+ ] }),
410
+ showCloseButton: false,
386
411
  disableEscapeKeyDown: true,
387
412
  sx: {
388
413
  ".MuiDialogContent-root": {
389
- padding: {
390
- xs: 0,
391
- md: "0 16px 0"
392
- },
414
+ padding: "16px 24px",
393
415
  borderTop: "1px solid var(--stroke-border-base, #EFF1F5)",
394
- width: {
395
- xs: "100%",
396
- md: 900
397
- }
416
+ width: "100%"
417
+ },
418
+ ".ux-dialog_header": {
419
+ gap: 5
398
420
  }
399
421
  },
422
+ PaperProps: {
423
+ style: { minHeight: "auto", width: 680 }
424
+ },
400
425
  onClose: (e, reason) => setState({ open: reason === "backdropClick" }),
401
426
  children: /* @__PURE__ */ jsx(Box, { sx: { height: "100%", width: "100%" }, children: /* @__PURE__ */ jsx(
402
427
  CheckoutForm,
@@ -407,8 +432,13 @@ function CheckoutDonateInner({
407
432
  action: settings.appearance?.button?.text,
408
433
  mode: "inline",
409
434
  theme,
435
+ formType: "donation",
410
436
  extraParams: {
411
437
  livemode
438
+ },
439
+ formRender: {
440
+ cancel: /* @__PURE__ */ jsx(Button, { variant: "outlined", size: "large", onClick: () => setState({ open: false }), children: t("common.cancel") }),
441
+ onCancel: () => setState({ open: false })
412
442
  }
413
443
  }
414
444
  ) })
@@ -1,5 +1,5 @@
1
1
  import type { CheckoutProps } from '../types';
2
- declare function CheckoutForm({ id, mode, onPaid, onError, onChange, goBack, extraParams, action, theme, ...restProps }: CheckoutProps): import("react").JSX.Element;
2
+ declare function CheckoutForm({ id, mode, onPaid, onError, onChange, goBack, extraParams, action, theme, formType, ...restProps }: CheckoutProps): import("react").JSX.Element;
3
3
  declare namespace CheckoutForm {
4
4
  var defaultProps: {
5
5
  onPaid: any;
@@ -10,6 +10,7 @@ declare namespace CheckoutForm {
10
10
  mode: string;
11
11
  action: string;
12
12
  extraParams: {};
13
+ formType: string;
13
14
  };
14
15
  }
15
16
  export default CheckoutForm;
@@ -7,6 +7,7 @@ import api from "../libs/api.js";
7
7
  import { getPrefix, mergeExtraParams } from "../libs/util.js";
8
8
  import Payment from "../payment/index.js";
9
9
  import { PaymentThemeProvider } from "../theme/index.js";
10
+ import DonationForm from "../payment/donation-form.js";
10
11
  const promises = {};
11
12
  const startFromPaymentLink = (id, params) => {
12
13
  if (!promises[id]) {
@@ -32,6 +33,7 @@ export default function CheckoutForm({
32
33
  extraParams,
33
34
  action,
34
35
  theme = "default",
36
+ formType = "payment",
35
37
  ...restProps
36
38
  }) {
37
39
  if (!id.startsWith("plink_") && !id.startsWith("cs_")) {
@@ -60,49 +62,26 @@ export default function CheckoutForm({
60
62
  setState({ appError: err });
61
63
  onError?.(err);
62
64
  };
63
- if (theme === "inherit") {
64
- return /* @__PURE__ */ jsx(
65
- Payment,
66
- {
67
- checkoutSession: data?.checkoutSession,
68
- paymentMethods: data?.paymentMethods,
69
- paymentIntent: data?.paymentIntent,
70
- paymentLink: data?.paymentLink,
71
- customer: data?.customer,
72
- completed: state.completed,
73
- error: apiError,
74
- onPaid: handlePaid,
75
- onError: handleError,
76
- onChange,
77
- goBack,
78
- mode,
79
- action,
80
- ...restProps
81
- }
82
- );
83
- }
84
- if (theme && typeof theme === "object") {
85
- return /* @__PURE__ */ jsx(PaymentThemeProvider, { theme, children: /* @__PURE__ */ jsx(
86
- Payment,
87
- {
88
- checkoutSession: data?.checkoutSession,
89
- paymentMethods: data?.paymentMethods,
90
- paymentIntent: data?.paymentIntent,
91
- paymentLink: data?.paymentLink,
92
- customer: data?.customer,
93
- completed: state.completed,
94
- error: apiError,
95
- onPaid: handlePaid,
96
- onError: handleError,
97
- onChange,
98
- goBack,
99
- mode,
100
- action,
101
- ...restProps
102
- }
103
- ) });
104
- }
105
- return /* @__PURE__ */ jsx(PaymentThemeProvider, { children: /* @__PURE__ */ jsx(
65
+ const Checkout = formType === "donation" ? /* @__PURE__ */ jsx(
66
+ DonationForm,
67
+ {
68
+ checkoutSession: data?.checkoutSession,
69
+ paymentMethods: data?.paymentMethods,
70
+ paymentIntent: data?.paymentIntent,
71
+ paymentLink: data?.paymentLink,
72
+ customer: data?.customer,
73
+ completed: state.completed,
74
+ error: apiError,
75
+ onPaid: handlePaid,
76
+ onError: handleError,
77
+ onChange,
78
+ goBack,
79
+ mode,
80
+ action,
81
+ id,
82
+ ...restProps
83
+ }
84
+ ) : /* @__PURE__ */ jsx(
106
85
  Payment,
107
86
  {
108
87
  checkoutSession: data?.checkoutSession,
@@ -120,12 +99,20 @@ export default function CheckoutForm({
120
99
  action,
121
100
  ...restProps
122
101
  }
123
- ) });
102
+ );
103
+ if (theme === "inherit") {
104
+ return Checkout;
105
+ }
106
+ if (theme && typeof theme === "object") {
107
+ return /* @__PURE__ */ jsx(PaymentThemeProvider, { theme, children: Checkout });
108
+ }
109
+ return /* @__PURE__ */ jsx(PaymentThemeProvider, { children: Checkout });
124
110
  }
125
111
  CheckoutForm.defaultProps = {
126
112
  onPaid: noop,
127
113
  onError: console.error,
128
114
  mode: "inline",
129
115
  action: "",
130
- extraParams: {}
116
+ extraParams: {},
117
+ formType: "payment"
131
118
  };
@@ -0,0 +1,24 @@
1
+ export interface TBeneficiary {
2
+ name: string;
3
+ address: string;
4
+ avatar?: string;
5
+ percent: number;
6
+ amount?: string;
7
+ url?: string;
8
+ type?: 'user' | 'dapp';
9
+ }
10
+ interface BenefitsProps {
11
+ data: TBeneficiary[];
12
+ currency: {
13
+ symbol: string;
14
+ decimal: number;
15
+ };
16
+ totalAmount?: string;
17
+ }
18
+ declare function PaymentBeneficiaries({ data, currency, totalAmount }: BenefitsProps): import("react").JSX.Element;
19
+ declare namespace PaymentBeneficiaries {
20
+ var defaultProps: {
21
+ totalAmount: string;
22
+ };
23
+ }
24
+ export default PaymentBeneficiaries;
@@ -0,0 +1,70 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { Avatar, Box, Stack, Typography } from "@mui/material";
3
+ import { BN, fromUnitToToken } from "@ocap/util";
4
+ import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
5
+ PaymentBeneficiaries.defaultProps = {
6
+ totalAmount: "0"
7
+ };
8
+ export default function PaymentBeneficiaries({ data, currency, totalAmount }) {
9
+ const { t } = useLocaleContext();
10
+ return /* @__PURE__ */ jsxs(Stack, { spacing: 2, children: [
11
+ /* @__PURE__ */ jsx(Typography, { variant: "subtitle2", color: "text.secondary", children: t("benefits.title", { count: data.length }) }),
12
+ data.map((item) => {
13
+ const amount = item.amount || (totalAmount ? new BN(totalAmount).mul(new BN(Number(item.percent))).div(new BN(100)).toString() : "0");
14
+ return /* @__PURE__ */ jsxs(
15
+ Stack,
16
+ {
17
+ direction: { xs: "column", sm: "row" },
18
+ alignItems: "center",
19
+ justifyContent: "space-between",
20
+ sx: {
21
+ px: 0.5,
22
+ borderRadius: 1,
23
+ bgcolor: "background.paper",
24
+ "&:hover": {
25
+ bgcolor: "action.hover"
26
+ }
27
+ },
28
+ children: [
29
+ /* @__PURE__ */ jsxs(Stack, { direction: "row", spacing: 1.5, alignItems: "center", sx: { width: { xs: "100%", sm: "auto" } }, children: [
30
+ /* @__PURE__ */ jsx(Avatar, { src: item.avatar, alt: item.name, sx: { width: 32, height: 32 }, variant: "square" }),
31
+ /* @__PURE__ */ jsxs(Box, { children: [
32
+ /* @__PURE__ */ jsx(
33
+ Typography,
34
+ {
35
+ variant: "subtitle2",
36
+ onClick: () => {
37
+ if (item.url) {
38
+ window.open(item.url, "_blank");
39
+ }
40
+ },
41
+ sx: {
42
+ cursor: item.url ? "pointer" : "default",
43
+ "&:hover": {
44
+ color: item.url ? "text.link" : "inherit"
45
+ }
46
+ },
47
+ children: item.name
48
+ }
49
+ ),
50
+ /* @__PURE__ */ jsx(Typography, { variant: "caption", color: "text.secondary", sx: { cursor: "pointer" }, children: item.address })
51
+ ] })
52
+ ] }),
53
+ /* @__PURE__ */ jsxs(Stack, { alignItems: "flex-end", sx: { width: { xs: "100%", sm: "auto" }, mt: { xs: 1, sm: 0 } }, children: [
54
+ /* @__PURE__ */ jsxs(Typography, { variant: "subtitle2", children: [
55
+ fromUnitToToken(amount, currency.decimal),
56
+ " ",
57
+ currency.symbol
58
+ ] }),
59
+ /* @__PURE__ */ jsxs(Typography, { variant: "caption", color: "text.secondary", children: [
60
+ Number(item.percent),
61
+ "%"
62
+ ] })
63
+ ] })
64
+ ]
65
+ },
66
+ item.address
67
+ );
68
+ })
69
+ ] });
70
+ }
package/es/index.d.ts CHANGED
@@ -29,6 +29,7 @@ import TruncatedText from './components/truncated-text';
29
29
  import Link from './components/link';
30
30
  import { createLazyComponent } from './components/lazy-loader';
31
31
  import OverdueInvoicePayment from './components/over-due-invoice-payment';
32
+ import PaymentBeneficiaries from './components/payment-beneficiaries';
32
33
  export { PaymentThemeProvider } from './theme';
33
34
  export * from './libs/util';
34
35
  export * from './libs/connect';
@@ -39,4 +40,4 @@ export * from './hooks/mobile';
39
40
  export * from './hooks/table';
40
41
  export * from './hooks/scroll';
41
42
  export { translations, createTranslator } from './locales';
42
- 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, };
43
+ 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, };
package/es/index.js CHANGED
@@ -29,6 +29,7 @@ import TruncatedText from "./components/truncated-text.js";
29
29
  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
+ import PaymentBeneficiaries from "./components/payment-beneficiaries.js";
32
33
  export { PaymentThemeProvider } from "./theme/index.js";
33
34
  export * from "./libs/util.js";
34
35
  export * from "./libs/connect.js";
@@ -70,5 +71,6 @@ export {
70
71
  Table,
71
72
  TruncatedText,
72
73
  Link,
73
- OverdueInvoicePayment
74
+ OverdueInvoicePayment,
75
+ PaymentBeneficiaries
74
76
  };
package/es/locales/en.js CHANGED
@@ -31,6 +31,8 @@ export default flat({
31
31
  upload: "Upload",
32
32
  change: "Change",
33
33
  cancel: "Cancel",
34
+ close: "Close",
35
+ back: "Back",
34
36
  every: "every",
35
37
  per: "per {interval}",
36
38
  slash: "/ {interval}",
@@ -125,7 +127,14 @@ export default flat({
125
127
  custom: "Custom Amount",
126
128
  select: "Select Amount",
127
129
  summary: "{total} supporters {totalAmount} {symbol}",
128
- empty: "No supporters yet"
130
+ empty: "No supporters yet",
131
+ gaveTips: "{count} people gave tips",
132
+ tipAmount: "Tip Amount",
133
+ benefits: {
134
+ one: "{name} will receive all tips",
135
+ multiple: "Tips will be distributed to {count} beneficiaries",
136
+ view: "Click to view details"
137
+ }
129
138
  },
130
139
  cardPay: "{action} with card",
131
140
  empty: "No thing to pay",
@@ -347,5 +356,8 @@ export default flat({
347
356
  },
348
357
  empty: {
349
358
  records: "No matching records found"
359
+ },
360
+ benefits: {
361
+ title: "{count} Beneficiaries"
350
362
  }
351
363
  });
package/es/locales/zh.js CHANGED
@@ -31,6 +31,8 @@ export default flat({
31
31
  change: "\u66F4\u6362",
32
32
  confirm: "\u786E\u8BA4",
33
33
  cancel: "\u53D6\u6D88",
34
+ close: "\u5173\u95ED",
35
+ back: "\u8FD4\u56DE",
34
36
  every: "\u6BCF",
35
37
  per: "\u6BCF{interval}",
36
38
  slash: "\u6BCF{interval}",
@@ -125,7 +127,14 @@ export default flat({
125
127
  custom: "\u8F93\u5165\u91D1\u989D",
126
128
  select: "\u9009\u62E9\u91D1\u989D",
127
129
  summary: "\u5171\u6709 {total} \u4EBA\u652F\u6301 {totalAmount} {symbol}",
128
- empty: "\u2764\uFE0F \u652F\u6301\u4E00\u4E0B"
130
+ empty: "\u2764\uFE0F \u652F\u6301\u4E00\u4E0B",
131
+ gaveTips: "\u5DF2\u6709 {count} \u4EBA\u6253\u8D4F",
132
+ tipAmount: "\u6253\u8D4F\u91D1\u989D",
133
+ benefits: {
134
+ one: "{name} \u5C06\u83B7\u5F97\u5168\u90E8\u6253\u8D4F",
135
+ multiple: "\u6253\u8D4F\u5C06\u6309\u6BD4\u4F8B\u5206\u914D\u7ED9 {count} \u4F4D\u53D7\u76CA\u4EBA",
136
+ view: "\u70B9\u51FB\u67E5\u770B\u8BE6\u60C5"
137
+ }
129
138
  },
130
139
  cardPay: "\u4F7F\u7528\u5361\u7247{action}",
131
140
  empty: "\u6CA1\u6709\u53EF\u652F\u4ED8\u7684\u9879\u76EE",
@@ -347,5 +356,8 @@ export default flat({
347
356
  },
348
357
  empty: {
349
358
  records: "\u6CA1\u6709\u627E\u5230\u5339\u914D\u7684\u8BB0\u5F55"
359
+ },
360
+ benefits: {
361
+ title: "{count} \u4F4D\u53D7\u76CA\u4EBA"
350
362
  }
351
363
  });
@@ -0,0 +1,24 @@
1
+ import { type BoxProps } from '@mui/material';
2
+ import type { LiteralUnion } from 'type-fest';
3
+ import type { CheckoutCallbacks, CheckoutContext } from '../types';
4
+ type Props = CheckoutContext & CheckoutCallbacks & {
5
+ completed?: boolean;
6
+ error?: any;
7
+ showCheckoutSummary?: boolean;
8
+ formRender?: Record<string, any>;
9
+ id: string;
10
+ };
11
+ declare function DonationForm({ checkoutSession, paymentMethods, paymentIntent, paymentLink, customer, completed, error, mode, onPaid, onError, onChange, goBack, action, showCheckoutSummary, formRender, id, }: Props): import("react").JSX.Element;
12
+ declare namespace DonationForm {
13
+ var defaultProps: {
14
+ completed: boolean;
15
+ error: null;
16
+ showCheckoutSummary: boolean;
17
+ formRender: {};
18
+ };
19
+ }
20
+ export default DonationForm;
21
+ type RootProps = {
22
+ mode: LiteralUnion<'standalone' | 'inline' | 'popup', string>;
23
+ } & BoxProps;
24
+ export declare const Root: React.FC<RootProps>;