@blocklet/payment-react 1.18.35 → 1.18.37

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.
@@ -1,8 +1,9 @@
1
+ /* eslint-disable @typescript-eslint/indent */
1
2
  import type { TPaymentCurrency, TPaymentMethodExpanded } from '@blocklet/payment-types';
2
3
  import { Alert } from '@mui/material';
3
4
  import { useLocalStorageState, useRequest } from 'ahooks';
4
5
  import type { Axios } from 'axios';
5
- import { createContext, useContext, useState } from 'react';
6
+ import { createContext, useContext, useEffect, useState } from 'react';
6
7
 
7
8
  import api from '../libs/api';
8
9
  import { getPrefix } from '../libs/util';
@@ -74,6 +75,19 @@ const getMethod = (methodId: string, methods: TPaymentMethodExpanded[]) => {
74
75
  return methods.find((x) => x.id === methodId);
75
76
  };
76
77
 
78
+ const syncToSpaceRequest = (userDid: string, spaceDid: string) => {
79
+ const cacheKey = `sync-space-${userDid}-${spaceDid}`;
80
+ const cachedRequest = new CachedRequest(cacheKey, () => api.post('/api/customers/sync-to-space'), {
81
+ ttl: 1000 * 60 * 60, // 1 hour
82
+ });
83
+ return cachedRequest.fetch(false).then((res) => {
84
+ if (!res.success) {
85
+ cachedRequest.clearCache();
86
+ }
87
+ return res;
88
+ });
89
+ };
90
+
77
91
  function PaymentProvider({ session, connect, children, baseUrl, authToken }: PaymentContextProps) {
78
92
  if (baseUrl) {
79
93
  // This is hack but efficient to share
@@ -101,6 +115,20 @@ function PaymentProvider({ session, connect, children, baseUrl, authToken }: Pay
101
115
  } = useRequest(getSettings, {
102
116
  refreshDeps: [livemode],
103
117
  });
118
+
119
+ useEffect(() => {
120
+ const didSpace = session?.user?.didSpace as
121
+ | {
122
+ endpoint: string;
123
+ did: string;
124
+ }
125
+ | undefined;
126
+ const userDid = session?.user?.did;
127
+ if (userDid && didSpace && didSpace.endpoint && didSpace.did) {
128
+ syncToSpaceRequest(userDid, didSpace.did);
129
+ }
130
+ }, [session?.user]);
131
+
104
132
  const prefix = getPrefix();
105
133
  const [payable, setPayable] = useState(true);
106
134
 
@@ -70,7 +70,7 @@ export class CachedRequest {
70
70
  }
71
71
  }
72
72
 
73
- private clearCache() {
73
+ clearCache() {
74
74
  const cache = this.getCache();
75
75
  if (this.options.strategy === 'memory') {
76
76
  cache.delete(this.cacheKey);
@@ -21,7 +21,7 @@ AddressForm.defaultProps = {
21
21
  };
22
22
 
23
23
  export default function AddressForm({ mode, stripe, sx = {}, fieldValidation, errorPosition }: Props) {
24
- const { t } = useLocaleContext();
24
+ const { t, locale } = useLocaleContext();
25
25
  const { control } = useFormContext();
26
26
  const country = useWatch({ control, name: 'billing_address.country' });
27
27
  if (mode === 'required') {
@@ -34,7 +34,7 @@ export default function AddressForm({ mode, stripe, sx = {}, fieldValidation, er
34
34
  name="billing_address.line1"
35
35
  rules={{
36
36
  required: t('payment.checkout.required'),
37
- ...getFieldValidation('billing_address.line1', fieldValidation),
37
+ ...getFieldValidation('billing_address.line1', fieldValidation, locale),
38
38
  }}
39
39
  errorPosition={errorPosition}
40
40
  variant="outlined"
@@ -45,7 +45,7 @@ export default function AddressForm({ mode, stripe, sx = {}, fieldValidation, er
45
45
  name="billing_address.city"
46
46
  rules={{
47
47
  required: t('payment.checkout.required'),
48
- ...getFieldValidation('billing_address.city', fieldValidation),
48
+ ...getFieldValidation('billing_address.city', fieldValidation, locale),
49
49
  }}
50
50
  errorPosition={errorPosition}
51
51
  variant="outlined"
@@ -56,7 +56,7 @@ export default function AddressForm({ mode, stripe, sx = {}, fieldValidation, er
56
56
  name="billing_address.state"
57
57
  rules={{
58
58
  required: t('payment.checkout.required'),
59
- ...getFieldValidation('billing_address.state', fieldValidation),
59
+ ...getFieldValidation('billing_address.state', fieldValidation, locale),
60
60
  }}
61
61
  errorPosition={errorPosition}
62
62
  variant="outlined"
@@ -71,7 +71,7 @@ export default function AddressForm({ mode, stripe, sx = {}, fieldValidation, er
71
71
  const isValid = validatePostalCode(x, country);
72
72
  return isValid ? true : t('payment.checkout.invalid');
73
73
  },
74
- ...getFieldValidation('billing_address.postal_code', fieldValidation),
74
+ ...getFieldValidation('billing_address.postal_code', fieldValidation, locale),
75
75
  }}
76
76
  errorPosition={errorPosition}
77
77
  variant="outlined"
@@ -118,7 +118,7 @@ export default function AddressForm({ mode, stripe, sx = {}, fieldValidation, er
118
118
  const isValid = validatePostalCode(x, country);
119
119
  return isValid ? true : t('payment.checkout.invalid');
120
120
  },
121
- ...getFieldValidation('billing_address.postal_code', fieldValidation),
121
+ ...getFieldValidation('billing_address.postal_code', fieldValidation, locale),
122
122
  }}
123
123
  errorPosition={errorPosition}
124
124
  variant="outlined"
@@ -177,7 +177,7 @@ export default function PaymentForm({
177
177
  const { isMobile } = useMobile();
178
178
  const { session, connect, payable } = usePaymentContext();
179
179
  const subscription = useSubscription('events');
180
- const formErrorPosition = isMobile ? 'bottom' : 'right';
180
+ const formErrorPosition = 'bottom';
181
181
  const {
182
182
  control,
183
183
  getValues,
@@ -93,6 +93,7 @@ export default function PhoneInput({ ...props }) {
93
93
  borderColor: 'transparent',
94
94
  },
95
95
  }}
96
+ showDialCode
96
97
  />
97
98
  </InputAdornment>
98
99
  ),
@@ -23,6 +23,7 @@ export type StripeCheckoutFormProps = {
23
23
  };
24
24
 
25
25
  const PaymentElementContainer = styled('div')`
26
+ width: 100%;
26
27
  opacity: 0;
27
28
  transition: opacity 300ms ease;
28
29
  &.visible {