@blocklet/payment-react 1.18.5 → 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/lib/index.js CHANGED
@@ -36,6 +36,7 @@ var _exportNames = {
36
36
  createLazyComponent: true,
37
37
  OverdueInvoicePayment: true,
38
38
  PaymentBeneficiaries: true,
39
+ LoadingButton: true,
39
40
  PaymentThemeProvider: true,
40
41
  translations: true,
41
42
  createTranslator: true
@@ -118,6 +119,12 @@ Object.defineProperty(exports, "Livemode", {
118
119
  return _livemode.default;
119
120
  }
120
121
  });
122
+ Object.defineProperty(exports, "LoadingButton", {
123
+ enumerable: true,
124
+ get: function () {
125
+ return _loadingButton.default;
126
+ }
127
+ });
121
128
  Object.defineProperty(exports, "OverdueInvoicePayment", {
122
129
  enumerable: true,
123
130
  get: function () {
@@ -282,6 +289,7 @@ var _link = _interopRequireDefault(require("./components/link"));
282
289
  var _lazyLoader = require("./components/lazy-loader");
283
290
  var _overDueInvoicePayment = _interopRequireDefault(require("./components/over-due-invoice-payment"));
284
291
  var _paymentBeneficiaries = _interopRequireDefault(require("./components/payment-beneficiaries"));
292
+ var _loadingButton = _interopRequireDefault(require("./components/loading-button"));
285
293
  var _theme = require("./theme");
286
294
  var _util = require("./libs/util");
287
295
  Object.keys(_util).forEach(function (key) {
@@ -30,6 +30,7 @@ var _phone = _interopRequireDefault(require("./phone"));
30
30
  var _stripe = _interopRequireDefault(require("./stripe"));
31
31
  var _mobile = require("../../hooks/mobile");
32
32
  var _phoneValidator = require("../../libs/phone-validator");
33
+ var _loadingButton = _interopRequireDefault(require("../../components/loading-button"));
33
34
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
34
35
  const waitForCheckoutComplete = async sessionId => {
35
36
  let result;
@@ -165,7 +166,7 @@ function PaymentForm({
165
166
  name: "payment_method"
166
167
  });
167
168
  const afterUserLoggedIn = (0, _ahooks.useMemoizedFn)(() => {
168
- if (hasDidWallet(session.user)) {
169
+ if (hasDidWallet(session.user) || skipBindWallet) {
169
170
  handleSubmit(onFormSubmit, onFormError)();
170
171
  } else {
171
172
  session.bindWallet(() => {
@@ -190,6 +191,8 @@ function PaymentForm({
190
191
  action: buttonText
191
192
  });
192
193
  const method = paymentMethods.find(x => x.id === paymentMethod);
194
+ const showForm = session?.user;
195
+ const skipBindWallet = method.type === "stripe";
193
196
  const handleConnected = async () => {
194
197
  try {
195
198
  const result = await waitForCheckoutComplete(checkoutSession.id);
@@ -276,7 +279,8 @@ function PaymentForm({
276
279
  prefix: (0, _ufo.joinURL)((0, _util.getPrefix)(), "/api/did"),
277
280
  saveConnect: false,
278
281
  extraParams: {
279
- checkoutSessionId: checkoutSession.id
282
+ checkoutSessionId: checkoutSession.id,
283
+ sessionUserDid: session?.user?.did
280
284
  },
281
285
  onSuccess: async () => {
282
286
  connect.close();
@@ -349,6 +353,10 @@ function PaymentForm({
349
353
  });
350
354
  }
351
355
  if (session?.user) {
356
+ if (skipBindWallet) {
357
+ handleSubmit(onFormSubmit, onFormError)();
358
+ return;
359
+ }
352
360
  if (hasDidWallet(session.user)) {
353
361
  handleSubmit(onFormSubmit, onFormError)();
354
362
  } else {
@@ -470,7 +478,7 @@ function PaymentForm({
470
478
  returnUrl: checkoutSession?.success_url
471
479
  })]
472
480
  })
473
- }), /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
481
+ }), showForm && /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
474
482
  direction: "column",
475
483
  className: "cko-payment-form",
476
484
  id: "cko-payment-form",
@@ -539,26 +547,18 @@ function PaymentForm({
539
547
  className: "cko-payment-submit",
540
548
  children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
541
549
  className: "cko-payment-submit-btn",
542
- children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Button, {
550
+ children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_loadingButton.default, {
543
551
  variant: "contained",
544
552
  color: "primary",
545
553
  size: "large",
546
554
  className: "cko-submit-button",
547
555
  onClick: () => {
548
- if (state.submitting || state.paying) {
549
- return;
550
- }
551
556
  onAction();
552
557
  },
553
558
  fullWidth: true,
559
+ loading: state.submitting || state.paying,
554
560
  disabled: state.stripePaying || !quantityInventoryStatus || !payable,
555
- children: [(state.submitting || state.paying) && /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.CircularProgress, {
556
- size: 16,
557
- sx: {
558
- mr: 0.5,
559
- color: "var(--foregrounds-fg-on-color, #fff)"
560
- }
561
- }), state.submitting || state.paying ? t("payment.checkout.processing") : buttonText]
561
+ children: state.submitting || state.paying ? t("payment.checkout.processing") : buttonText
562
562
  })
563
563
  }), ["subscription", "setup"].includes(checkoutSession.mode) && /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
564
564
  sx: {
@@ -8,11 +8,12 @@ var _jsxRuntime = require("react/jsx-runtime");
8
8
  var _Center = _interopRequireDefault(require("@arcblock/ux/lib/Center"));
9
9
  var _Dialog = _interopRequireDefault(require("@arcblock/ux/lib/Dialog"));
10
10
  var _context = require("@arcblock/ux/lib/Locale/context");
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");
15
14
  var _react = require("react");
15
+ var _mobile = require("../../../hooks/mobile");
16
+ var _loadingButton = _interopRequireDefault(require("../../../components/loading-button"));
16
17
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
18
  const {
18
19
  Elements,
@@ -136,7 +137,7 @@ function StripeCheckoutForm({
136
137
  }), (!stripe || !elements || !state.loaded) && /* @__PURE__ */(0, _jsxRuntime.jsx)(_Center.default, {
137
138
  relative: "parent",
138
139
  children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.CircularProgress, {})
139
- }), stripe && elements && state.loaded && /* @__PURE__ */(0, _jsxRuntime.jsx)(_lab.LoadingButton, {
140
+ }), stripe && elements && state.loaded && /* @__PURE__ */(0, _jsxRuntime.jsx)(_loadingButton.default, {
140
141
  fullWidth: true,
141
142
  sx: {
142
143
  mt: 2,
@@ -147,7 +148,6 @@ function StripeCheckoutForm({
147
148
  type: "submit",
148
149
  disabled: state.confirming || !state.loaded,
149
150
  loading: state.confirming,
150
- loadingPosition: "end",
151
151
  variant: "contained",
152
152
  color: "primary",
153
153
  size: "large",
@@ -184,7 +184,11 @@ function StripeCheckout({
184
184
  }) {
185
185
  const stripePromise = loadStripe(publicKey);
186
186
  const {
187
- t
187
+ isMobile
188
+ } = (0, _mobile.useMobile)();
189
+ const {
190
+ t,
191
+ locale
188
192
  } = (0, _context.useLocaleContext)();
189
193
  const [state, setState] = (0, _ahooks.useSetState)({
190
194
  open: true,
@@ -207,9 +211,24 @@ function StripeCheckout({
207
211
  open: state.open,
208
212
  onClose: handleClose,
209
213
  disableEscapeKeyDown: true,
214
+ sx: {
215
+ ".StripeElement": {
216
+ minWidth: isMobile ? "100%" : "500px",
217
+ py: 1
218
+ },
219
+ form: {
220
+ justifyContent: "flex-start"
221
+ }
222
+ },
223
+ PaperProps: {
224
+ style: {
225
+ minWidth: isMobile ? "100%" : "500px"
226
+ }
227
+ },
210
228
  children: /* @__PURE__ */(0, _jsxRuntime.jsx)(Elements, {
211
229
  options: {
212
- clientSecret
230
+ clientSecret,
231
+ locale: locale === "zh" ? "zh-CN" : "en"
213
232
  },
214
233
  stripe: stripePromise,
215
234
  children: /* @__PURE__ */(0, _jsxRuntime.jsx)(StripeCheckoutForm, {
@@ -574,7 +574,6 @@ const Root = exports.Root = (0, _system.styled)(_material.Box)`
574
574
  .MuiButtonBase-root {
575
575
  font-size: 1.3rem;
576
576
  position: relative;
577
- padding: 4px 22px;
578
577
  }
579
578
 
580
579
  .cko-submit-progress {
@@ -7,7 +7,6 @@ module.exports = PaymentSummary;
7
7
  var _jsxRuntime = require("react/jsx-runtime");
8
8
  var _context = require("@arcblock/ux/lib/Locale/context");
9
9
  var _iconsMaterial = require("@mui/icons-material");
10
- var _lab = require("@mui/lab");
11
10
  var _material = require("@mui/material");
12
11
  var _util = require("@ocap/util");
13
12
  var _ahooks = require("ahooks");
@@ -24,6 +23,7 @@ var _productItem = _interopRequireDefault(require("./product-item"));
24
23
  var _livemode = _interopRequireDefault(require("../components/livemode"));
25
24
  var _payment = require("../contexts/payment");
26
25
  var _mobile = require("../hooks/mobile");
26
+ var _loadingButton = _interopRequireDefault(require("../components/loading-button"));
27
27
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
28
28
  const ExpandMore = (0, _styles.styled)(props => {
29
29
  const {
@@ -216,7 +216,7 @@ function PaymentSummary({
216
216
  sx: {
217
217
  width: 1
218
218
  },
219
- children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_lab.LoadingButton, {
219
+ children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_loadingButton.default, {
220
220
  size: "small",
221
221
  loadingPosition: "end",
222
222
  endIcon: null,
@@ -261,7 +261,7 @@ function PaymentSummary({
261
261
  mr: 1
262
262
  }
263
263
  })
264
- }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_lab.LoadingButton, {
264
+ }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_loadingButton.default, {
265
265
  size: "small",
266
266
  loadingPosition: "end",
267
267
  endIcon: null,
@@ -67,7 +67,8 @@ function PaymentThemeProvider({
67
67
  root: {
68
68
  fontSize: "1rem",
69
69
  fontWeight: 500,
70
- textTransform: "none"
70
+ textTransform: "none",
71
+ boxShadow: "none"
71
72
  },
72
73
  containedPrimary: {
73
74
  backgroundColor: "var(--buttons-button-inverted, #010714)",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/payment-react",
3
- "version": "1.18.5",
3
+ "version": "1.18.7",
4
4
  "description": "Reusable react components for payment kit v2",
5
5
  "keywords": [
6
6
  "react",
@@ -53,10 +53,10 @@
53
53
  }
54
54
  },
55
55
  "dependencies": {
56
- "@arcblock/did-connect": "^2.11.34",
57
- "@arcblock/ux": "^2.11.34",
56
+ "@arcblock/did-connect": "^2.11.40",
57
+ "@arcblock/ux": "^2.11.40",
58
58
  "@arcblock/ws": "^1.19.9",
59
- "@blocklet/ui-react": "^2.11.34",
59
+ "@blocklet/ui-react": "^2.11.40",
60
60
  "@mui/icons-material": "^5.16.6",
61
61
  "@mui/lab": "^5.0.0-alpha.173",
62
62
  "@mui/material": "^5.16.6",
@@ -92,7 +92,7 @@
92
92
  "@babel/core": "^7.25.2",
93
93
  "@babel/preset-env": "^7.25.2",
94
94
  "@babel/preset-react": "^7.24.7",
95
- "@blocklet/payment-types": "1.18.5",
95
+ "@blocklet/payment-types": "1.18.7",
96
96
  "@storybook/addon-essentials": "^7.6.20",
97
97
  "@storybook/addon-interactions": "^7.6.20",
98
98
  "@storybook/addon-links": "^7.6.20",
@@ -123,5 +123,5 @@
123
123
  "vite-plugin-babel": "^1.2.0",
124
124
  "vite-plugin-node-polyfills": "^0.21.0"
125
125
  },
126
- "gitHead": "83cca0f1ac5814964c8bedd04f34a3a2a986f554"
126
+ "gitHead": "b75168ab5e2cd939571e6e26543374c8d0dab963"
127
127
  }
@@ -4,6 +4,7 @@ import Dialog from '@arcblock/ux/lib/Dialog';
4
4
  import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
5
5
  import type {
6
6
  DonationSettings,
7
+ PaymentBeneficiary,
7
8
  PaymentDetails,
8
9
  TCheckoutSessionExpanded,
9
10
  TPaymentCurrency,
@@ -12,7 +13,6 @@ import type {
12
13
  TSetting,
13
14
  } from '@blocklet/payment-types';
14
15
  import {
15
- Alert,
16
16
  Avatar,
17
17
  AvatarGroup,
18
18
  Box,
@@ -42,7 +42,6 @@ import {
42
42
  formatAmount,
43
43
  formatBNStr,
44
44
  formatDateTime,
45
- formatError,
46
45
  getCustomerAvatar,
47
46
  lazyLoad,
48
47
  openDonationSettings,
@@ -62,19 +61,40 @@ export type DonateHistory = {
62
61
  // total?: number;
63
62
  totalAmount: string;
64
63
  };
65
- export type RequiredDonationSettings = Pick<
66
- DonationSettings,
67
- 'target' | 'title' | 'description' | 'reference' | 'beneficiaries'
68
- >;
69
- type OptionalDonationSettings = Partial<Omit<DonationSettings, keyof RequiredDonationSettings>>;
70
64
 
65
+ export type CheckoutDonateSettings = {
66
+ target: string;
67
+ title: string;
68
+ description: string;
69
+ reference: string;
70
+ beneficiaries: PaymentBeneficiary[];
71
+ amount?: {
72
+ presets?: string[];
73
+ preset?: string;
74
+ minimum?: string;
75
+ maximum?: string;
76
+ custom?: boolean;
77
+ };
78
+ appearance?: {
79
+ button?: {
80
+ text?: any;
81
+ icon?: any;
82
+ size?: string;
83
+ color?: string;
84
+ variant?: string;
85
+ };
86
+ history?: {
87
+ variant?: string;
88
+ };
89
+ };
90
+ };
71
91
  export interface ButtonType extends Omit<MUIButtonProps, 'text' | 'icon'> {
72
92
  text?: string | React.ReactNode;
73
93
  icon: React.ReactNode;
74
94
  }
75
95
 
76
96
  export type DonateProps = Pick<CheckoutProps, 'onPaid' | 'onError'> & {
77
- settings: RequiredDonationSettings & OptionalDonationSettings;
97
+ settings: CheckoutDonateSettings;
78
98
  livemode?: boolean;
79
99
  timeout?: number;
80
100
  mode?: 'inline' | 'default' | 'custom';
@@ -300,11 +320,7 @@ const defaultDonateAmount = {
300
320
  maximum: '100',
301
321
  custom: true,
302
322
  };
303
- function useDonation(
304
- settings: RequiredDonationSettings & OptionalDonationSettings,
305
- livemode: boolean,
306
- mode = 'default'
307
- ) {
323
+ function useDonation(settings: CheckoutDonateSettings, livemode: boolean, mode = 'default') {
308
324
  const [state, setState] = useSetState({
309
325
  open: false,
310
326
  supporterLoaded: false,
@@ -425,7 +441,7 @@ function CheckoutDonateInner({
425
441
  };
426
442
 
427
443
  if (donation.error) {
428
- return <Alert severity="error">{formatError(donation.error)}</Alert>;
444
+ return null;
429
445
  }
430
446
 
431
447
  const handlePopoverOpen = (event: any) => {
@@ -555,7 +571,7 @@ function CheckoutDonateInner({
555
571
  `${formatAmount(
556
572
  (supporters.data as DonateHistory)?.totalAmount || '0',
557
573
  (supporters.data as DonateHistory)?.currency?.decimal
558
- )} ${(supporters.data as DonateHistory)?.currency?.symbol}`,
574
+ )} ${(supporters.data as DonateHistory)?.currency?.symbol || ''}`,
559
575
  (supporters.data as DonateHistory) || {},
560
576
  !!supporters.loading,
561
577
  donateSettings
@@ -563,7 +579,8 @@ function CheckoutDonateInner({
563
579
  </>
564
580
  ) : (
565
581
  <Typography>
566
- Please provide a valid render function <pre>{'(openDonate, donateTotalAmount, supporters) => ReactNode'}</pre>
582
+ Please provide a valid render function{' '}
583
+ <pre>{'(openDonate, donateTotalAmount, supporters, loading, donateSettings) => ReactNode'}</pre>
567
584
  </Typography>
568
585
  );
569
586
  }
@@ -0,0 +1,100 @@
1
+ import {
2
+ Button,
3
+ type ButtonProps,
4
+ CircularProgress,
5
+ type CircularProgressProps,
6
+ SxProps,
7
+ Theme,
8
+ Typography,
9
+ } from '@mui/material';
10
+ import { forwardRef } from 'react';
11
+
12
+ export interface LoadingButtonProps extends ButtonProps {
13
+ loading?: boolean;
14
+ loadingIndicator?: React.ReactNode;
15
+ loadingPosition?: 'start' | 'center' | 'end';
16
+ loadingProps?: Partial<CircularProgressProps>;
17
+ loadingOnly?: boolean;
18
+ }
19
+
20
+ const LoadingButton = forwardRef<HTMLButtonElement, LoadingButtonProps>(
21
+ (
22
+ {
23
+ children,
24
+ loading,
25
+ loadingPosition = 'start',
26
+ loadingIndicator,
27
+ loadingProps = {},
28
+ onClick,
29
+ sx,
30
+ loadingOnly = false,
31
+ ...props
32
+ },
33
+ ref
34
+ ) => {
35
+ const handleClick = (e: React.MouseEvent<HTMLButtonElement>) => {
36
+ if (loading) {
37
+ return;
38
+ }
39
+ onClick?.(e);
40
+ };
41
+
42
+ const getPositionStyles = (position: string) => {
43
+ return {
44
+ color: 'inherit',
45
+ ...(position === 'start' && { mr: 1 }),
46
+ ...(position === 'end' && { ml: 1 }),
47
+ ...(position === 'center' && {
48
+ position: 'absolute',
49
+ left: '50%',
50
+ transform: 'translateY(-50%) translateX(-50%)',
51
+ top: '50%',
52
+ }),
53
+ display: 'inline-flex',
54
+ alignItems: 'center',
55
+ } as const;
56
+ };
57
+
58
+ const defaultIndicator = (
59
+ <CircularProgress size={16} {...loadingProps} sx={{ color: 'inherit', ...(loadingProps?.sx || {}) }} />
60
+ );
61
+
62
+ const indicator = (
63
+ <Typography sx={getPositionStyles(loadingPosition) as SxProps<Theme>}>
64
+ {loadingIndicator || defaultIndicator}
65
+ </Typography>
66
+ );
67
+
68
+ return (
69
+ <Button
70
+ ref={ref}
71
+ disabled={props.disabled}
72
+ onClick={handleClick}
73
+ sx={{
74
+ position: 'relative',
75
+ display: 'inline-flex',
76
+ alignItems: 'center',
77
+ justifyContent: 'center',
78
+ ...sx,
79
+ }}
80
+ {...props}>
81
+ {loading && loadingPosition === 'start' && indicator}
82
+ <Typography sx={{ visibility: loading && loadingOnly ? 'hidden' : 'visible' }}>{children}</Typography>
83
+ {loading && loadingPosition === 'center' && indicator}
84
+ {loading && loadingPosition === 'end' && indicator}
85
+ </Button>
86
+ );
87
+ }
88
+ );
89
+
90
+ LoadingButton.displayName = 'LoadingButton';
91
+
92
+ LoadingButton.defaultProps = {
93
+ loading: false,
94
+ loadingIndicator: undefined,
95
+ loadingPosition: 'start',
96
+ loadingProps: {},
97
+ loadingOnly: false,
98
+ };
99
+
100
+ export default LoadingButton;
@@ -3,7 +3,6 @@ import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
3
3
  import Toast from '@arcblock/ux/lib/Toast';
4
4
  import type { PriceCurrency, PriceRecurring, TPricingTableExpanded, TPricingTableItem } from '@blocklet/payment-types';
5
5
  import { CheckOutlined } from '@mui/icons-material';
6
- import { LoadingButton } from '@mui/lab';
7
6
  import {
8
7
  Avatar,
9
8
  Box,
@@ -36,6 +35,7 @@ import {
36
35
  } from '../libs/util';
37
36
  import { useMobile } from '../hooks/mobile';
38
37
  import TruncatedText from './truncated-text';
38
+ import LoadingButton from './loading-button';
39
39
 
40
40
  type SortOrder = { [key: string]: number };
41
41
 
@@ -322,7 +322,6 @@ export default function PricingTable({ table, alignItems, interval, mode, onSele
322
322
  justifyContent={alignItems === 'center' ? 'center' : 'flex-start'}
323
323
  sx={{
324
324
  flex: '0 1 auto',
325
- overflow: 'auto',
326
325
  pb: 2.5,
327
326
  }}
328
327
  className="price-table-wrap">
@@ -354,7 +353,8 @@ export default function PricingTable({ table, alignItems, interval, mode, onSele
354
353
  '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)',
355
354
  '&:hover': {
356
355
  borderColor: mode === 'select' && x.is_selected ? 'primary.main' : '#ddd',
357
- boxShadow: '0 8px 16px rgba(0, 0, 0, 20%)',
356
+ boxShadow:
357
+ '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))',
358
358
  },
359
359
  width: {
360
360
  xs: '100%',
package/src/index.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
 
34
35
  export { PaymentThemeProvider } from './theme';
35
36
 
@@ -79,4 +80,5 @@ export {
79
80
  Link,
80
81
  OverdueInvoicePayment,
81
82
  PaymentBeneficiaries,
83
+ LoadingButton,
82
84
  };