@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.
@@ -41,6 +41,7 @@ import PhoneInput from './phone';
41
41
  import StripeCheckout from './stripe';
42
42
  import { useMobile } from '../../hooks/mobile';
43
43
  import { validatePhoneNumber } from '../../libs/phone-validator';
44
+ import LoadingButton from '../../components/loading-button';
44
45
 
45
46
  export const waitForCheckoutComplete = async (sessionId: string) => {
46
47
  let result: CheckoutContext;
@@ -212,7 +213,7 @@ export default function PaymentForm({
212
213
  // }, [domSize, theme]);
213
214
 
214
215
  const afterUserLoggedIn = useMemoizedFn(() => {
215
- if (hasDidWallet(session.user)) {
216
+ if (hasDidWallet(session.user) || skipBindWallet) {
216
217
  handleSubmit(onFormSubmit, onFormError)();
217
218
  } else {
218
219
  session.bindWallet(() => {
@@ -239,6 +240,9 @@ export default function PaymentForm({
239
240
 
240
241
  const method = paymentMethods.find((x) => x.id === paymentMethod) as TPaymentMethodExpanded;
241
242
 
243
+ const showForm = session?.user;
244
+ const skipBindWallet = method.type === 'stripe';
245
+
242
246
  const handleConnected = async () => {
243
247
  try {
244
248
  const result = await waitForCheckoutComplete(checkoutSession.id);
@@ -372,6 +376,10 @@ export default function PaymentForm({
372
376
  errorRef.current.scrollIntoView({ behavior: 'smooth' });
373
377
  }
374
378
  if (session?.user) {
379
+ if (skipBindWallet) {
380
+ handleSubmit(onFormSubmit, onFormError)();
381
+ return;
382
+ }
375
383
  if (hasDidWallet(session.user)) {
376
384
  handleSubmit(onFormSubmit, onFormError)();
377
385
  } else {
@@ -492,56 +500,58 @@ export default function PaymentForm({
492
500
  )}
493
501
  </Stack>
494
502
  </Fade>
495
- <Stack
496
- direction="column"
497
- className="cko-payment-form"
498
- id="cko-payment-form"
499
- spacing={0}
500
- ref={!isEmpty(errors) ? (errorRef as any) : undefined}
501
- sx={{ flex: 1, overflow: 'auto', py: 1 }}>
502
- <FormLabel className="base-label">{t('payment.checkout.customer.name')}</FormLabel>
503
- <FormInput
504
- name="customer_name"
505
- variant="outlined"
506
- errorPosition="right"
507
- rules={{
508
- required: t('payment.checkout.required'),
509
- }}
510
- />
511
- <FormLabel className="base-label">{t('payment.checkout.customer.email')}</FormLabel>
512
- <FormInput
513
- name="customer_email"
514
- variant="outlined"
515
- errorPosition="right"
516
- rules={{
517
- required: t('payment.checkout.required'),
518
- validate: (x) => (isEmail(x) ? true : t('payment.checkout.invalid')),
519
- }}
520
- />
521
- {checkoutSession.phone_number_collection?.enabled && (
522
- <>
523
- <FormLabel className="base-label">{t('payment.checkout.customer.phone')}</FormLabel>
524
- <PhoneInput
525
- name="customer_phone"
526
- variant="outlined"
527
- errorPosition="right"
528
- placeholder="Phone number"
529
- rules={{
530
- required: t('payment.checkout.required'),
531
- validate: async (x: string) => {
532
- const isValid = await validatePhoneNumber(x);
533
- return isValid ? true : t('payment.checkout.invalid');
534
- },
535
- }}
536
- />
537
- </>
538
- )}
539
- <AddressForm
540
- mode={checkoutSession.billing_address_collection as string}
541
- stripe={method?.type === 'stripe'}
542
- sx={{ marginTop: '0 !important' }}
543
- />
544
- </Stack>
503
+ {showForm && (
504
+ <Stack
505
+ direction="column"
506
+ className="cko-payment-form"
507
+ id="cko-payment-form"
508
+ spacing={0}
509
+ ref={!isEmpty(errors) ? (errorRef as any) : undefined}
510
+ sx={{ flex: 1, overflow: 'auto', py: 1 }}>
511
+ <FormLabel className="base-label">{t('payment.checkout.customer.name')}</FormLabel>
512
+ <FormInput
513
+ name="customer_name"
514
+ variant="outlined"
515
+ errorPosition="right"
516
+ rules={{
517
+ required: t('payment.checkout.required'),
518
+ }}
519
+ />
520
+ <FormLabel className="base-label">{t('payment.checkout.customer.email')}</FormLabel>
521
+ <FormInput
522
+ name="customer_email"
523
+ variant="outlined"
524
+ errorPosition="right"
525
+ rules={{
526
+ required: t('payment.checkout.required'),
527
+ validate: (x) => (isEmail(x) ? true : t('payment.checkout.invalid')),
528
+ }}
529
+ />
530
+ {checkoutSession.phone_number_collection?.enabled && (
531
+ <>
532
+ <FormLabel className="base-label">{t('payment.checkout.customer.phone')}</FormLabel>
533
+ <PhoneInput
534
+ name="customer_phone"
535
+ variant="outlined"
536
+ errorPosition="right"
537
+ placeholder="Phone number"
538
+ rules={{
539
+ required: t('payment.checkout.required'),
540
+ validate: async (x: string) => {
541
+ const isValid = await validatePhoneNumber(x);
542
+ return isValid ? true : t('payment.checkout.invalid');
543
+ },
544
+ }}
545
+ />
546
+ </>
547
+ )}
548
+ <AddressForm
549
+ mode={checkoutSession.billing_address_collection as string}
550
+ stripe={method?.type === 'stripe'}
551
+ sx={{ marginTop: '0 !important' }}
552
+ />
553
+ </Stack>
554
+ )}
545
555
  </Stack>
546
556
  </Fade>
547
557
  <Divider sx={{ mt: 2.5, mb: 2.5 }} />
@@ -549,24 +559,19 @@ export default function PaymentForm({
549
559
  <Fade in>
550
560
  <Stack className="cko-payment-submit">
551
561
  <Box className="cko-payment-submit-btn">
552
- <Button
562
+ <LoadingButton
553
563
  variant="contained"
554
564
  color="primary"
555
565
  size="large"
556
566
  className="cko-submit-button"
557
567
  onClick={() => {
558
- if (state.submitting || state.paying) {
559
- return;
560
- }
561
568
  onAction();
562
569
  }}
563
570
  fullWidth
571
+ loading={state.submitting || state.paying}
564
572
  disabled={state.stripePaying || !quantityInventoryStatus || !payable}>
565
- {(state.submitting || state.paying) && (
566
- <CircularProgress size={16} sx={{ mr: 0.5, color: 'var(--foregrounds-fg-on-color, #fff)' }} />
567
- )}
568
573
  {state.submitting || state.paying ? t('payment.checkout.processing') : buttonText}
569
- </Button>
574
+ </LoadingButton>
570
575
  </Box>
571
576
 
572
577
  {['subscription', 'setup'].includes(checkoutSession.mode) && (
@@ -2,11 +2,12 @@ import Center from '@arcblock/ux/lib/Center';
2
2
  import Dialog from '@arcblock/ux/lib/Dialog';
3
3
  import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
4
4
  import type { TCustomer } from '@blocklet/payment-types';
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';
10
+ import LoadingButton from '../../../components/loading-button';
10
11
 
11
12
  const { Elements, PaymentElement, useElements, useStripe, loadStripe } = (globalThis as any).__STRIPE_COMPONENTS__;
12
13
 
@@ -128,7 +129,6 @@ function StripeCheckoutForm({
128
129
  type="submit"
129
130
  disabled={state.confirming || !state.loaded}
130
131
  loading={state.confirming}
131
- loadingPosition="end"
132
132
  variant="contained"
133
133
  color="primary"
134
134
  size="large">
@@ -171,7 +171,8 @@ export default function StripeCheckout({
171
171
  returnUrl = '',
172
172
  }: StripeCheckoutProps) {
173
173
  const stripePromise = loadStripe(publicKey);
174
- const { t } = useLocaleContext();
174
+ const { isMobile } = useMobile();
175
+ const { t, locale } = useLocaleContext();
175
176
  const [state, setState] = useSetState({
176
177
  open: true,
177
178
  closable: true,
@@ -192,8 +193,22 @@ export default function StripeCheckout({
192
193
  showCloseButton={state.closable}
193
194
  open={state.open}
194
195
  onClose={handleClose}
195
- disableEscapeKeyDown>
196
- <Elements options={{ clientSecret }} stripe={stripePromise}>
196
+ disableEscapeKeyDown
197
+ sx={{
198
+ '.StripeElement': {
199
+ minWidth: isMobile ? '100%' : '500px',
200
+ py: 1,
201
+ },
202
+ form: {
203
+ justifyContent: 'flex-start',
204
+ },
205
+ }}
206
+ PaperProps={{
207
+ style: {
208
+ minWidth: isMobile ? '100%' : '500px',
209
+ },
210
+ }}>
211
+ <Elements options={{ clientSecret, locale: locale === 'zh' ? 'zh-CN' : 'en' }} stripe={stripePromise}>
197
212
  <StripeCheckoutForm
198
213
  clientSecret={clientSecret}
199
214
  intentType={intentType}
@@ -577,7 +577,6 @@ export const Root: React.FC<RootProps> = styled(Box)<RootProps>`
577
577
  .MuiButtonBase-root {
578
578
  font-size: 1.3rem;
579
579
  position: relative;
580
- padding: 4px 22px;
581
580
  }
582
581
 
583
582
  .cko-submit-progress {
@@ -1,7 +1,6 @@
1
1
  import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
2
2
  import type { DonationSettings, TLineItemExpanded, TPaymentCurrency } from '@blocklet/payment-types';
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 type { IconButtonProps } from '@mui/material';
7
6
  import { BN, fromTokenToUnit, fromUnitToToken } from '@ocap/util';
@@ -19,6 +18,7 @@ import ProductItem from './product-item';
19
18
  import Livemode from '../components/livemode';
20
19
  import { usePaymentContext } from '../contexts/payment';
21
20
  import { useMobile } from '../hooks/mobile';
21
+ import LoadingButton from '../components/loading-button';
22
22
 
23
23
  // const shake = keyframes`
24
24
  // 0% {
@@ -63,6 +63,7 @@ export function PaymentThemeProvider({
63
63
  fontSize: '1rem',
64
64
  fontWeight: 500,
65
65
  textTransform: 'none',
66
+ boxShadow: 'none',
66
67
  },
67
68
  containedPrimary: {
68
69
  backgroundColor: 'var(--buttons-button-inverted, #010714)',