@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.
- package/es/components/country-select.d.ts +1 -0
- package/es/components/country-select.js +359 -276
- package/es/contexts/payment.js +21 -1
- package/es/libs/cached-request.d.ts +1 -1
- package/es/payment/form/address.js +6 -6
- package/es/payment/form/index.js +1 -1
- package/es/payment/form/phone.js +2 -1
- package/es/payment/form/stripe/form.js +1 -0
- package/lib/components/country-select.d.ts +1 -0
- package/lib/components/country-select.js +188 -80
- package/lib/contexts/payment.js +21 -0
- package/lib/libs/cached-request.d.ts +1 -1
- package/lib/payment/form/address.js +7 -6
- package/lib/payment/form/index.js +1 -1
- package/lib/payment/form/phone.js +2 -1
- package/lib/payment/form/stripe/form.js +1 -0
- package/package.json +6 -6
- package/src/components/country-select.tsx +381 -290
- package/src/contexts/payment.tsx +29 -1
- package/src/libs/cached-request.ts +1 -1
- package/src/payment/form/address.tsx +6 -6
- package/src/payment/form/index.tsx +1 -1
- package/src/payment/form/phone.tsx +1 -0
- package/src/payment/form/stripe/form.tsx +1 -0
package/es/contexts/payment.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Alert } from "@mui/material";
|
|
3
3
|
import { useLocalStorageState, useRequest } from "ahooks";
|
|
4
|
-
import { createContext, useContext, useState } from "react";
|
|
4
|
+
import { createContext, useContext, useEffect, useState } from "react";
|
|
5
5
|
import api from "../libs/api.js";
|
|
6
6
|
import { getPrefix } from "../libs/util.js";
|
|
7
7
|
import { CachedRequest } from "../libs/cached-request.js";
|
|
@@ -33,6 +33,19 @@ const getCurrency = (currencyId, methods) => {
|
|
|
33
33
|
const getMethod = (methodId, methods) => {
|
|
34
34
|
return methods.find((x) => x.id === methodId);
|
|
35
35
|
};
|
|
36
|
+
const syncToSpaceRequest = (userDid, spaceDid) => {
|
|
37
|
+
const cacheKey = `sync-space-${userDid}-${spaceDid}`;
|
|
38
|
+
const cachedRequest = new CachedRequest(cacheKey, () => api.post("/api/customers/sync-to-space"), {
|
|
39
|
+
ttl: 1e3 * 60 * 60
|
|
40
|
+
// 1 hour
|
|
41
|
+
});
|
|
42
|
+
return cachedRequest.fetch(false).then((res) => {
|
|
43
|
+
if (!res.success) {
|
|
44
|
+
cachedRequest.clearCache();
|
|
45
|
+
}
|
|
46
|
+
return res;
|
|
47
|
+
});
|
|
48
|
+
};
|
|
36
49
|
function PaymentProvider({ session, connect, children, baseUrl, authToken }) {
|
|
37
50
|
if (baseUrl) {
|
|
38
51
|
window.__PAYMENT_KIT_BASE_URL = baseUrl;
|
|
@@ -56,6 +69,13 @@ function PaymentProvider({ session, connect, children, baseUrl, authToken }) {
|
|
|
56
69
|
} = useRequest(getSettings, {
|
|
57
70
|
refreshDeps: [livemode]
|
|
58
71
|
});
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
const didSpace = session?.user?.didSpace;
|
|
74
|
+
const userDid = session?.user?.did;
|
|
75
|
+
if (userDid && didSpace && didSpace.endpoint && didSpace.did) {
|
|
76
|
+
syncToSpaceRequest(userDid, didSpace.did);
|
|
77
|
+
}
|
|
78
|
+
}, [session?.user]);
|
|
59
79
|
const prefix = getPrefix();
|
|
60
80
|
const [payable, setPayable] = useState(true);
|
|
61
81
|
if (error) {
|
|
@@ -11,7 +11,7 @@ AddressForm.defaultProps = {
|
|
|
11
11
|
errorPosition: "right"
|
|
12
12
|
};
|
|
13
13
|
export default function AddressForm({ mode, stripe, sx = {}, fieldValidation, errorPosition }) {
|
|
14
|
-
const { t } = useLocaleContext();
|
|
14
|
+
const { t, locale } = useLocaleContext();
|
|
15
15
|
const { control } = useFormContext();
|
|
16
16
|
const country = useWatch({ control, name: "billing_address.country" });
|
|
17
17
|
if (mode === "required") {
|
|
@@ -23,7 +23,7 @@ export default function AddressForm({ mode, stripe, sx = {}, fieldValidation, er
|
|
|
23
23
|
name: "billing_address.line1",
|
|
24
24
|
rules: {
|
|
25
25
|
required: t("payment.checkout.required"),
|
|
26
|
-
...getFieldValidation("billing_address.line1", fieldValidation)
|
|
26
|
+
...getFieldValidation("billing_address.line1", fieldValidation, locale)
|
|
27
27
|
},
|
|
28
28
|
errorPosition,
|
|
29
29
|
variant: "outlined",
|
|
@@ -37,7 +37,7 @@ export default function AddressForm({ mode, stripe, sx = {}, fieldValidation, er
|
|
|
37
37
|
name: "billing_address.city",
|
|
38
38
|
rules: {
|
|
39
39
|
required: t("payment.checkout.required"),
|
|
40
|
-
...getFieldValidation("billing_address.city", fieldValidation)
|
|
40
|
+
...getFieldValidation("billing_address.city", fieldValidation, locale)
|
|
41
41
|
},
|
|
42
42
|
errorPosition,
|
|
43
43
|
variant: "outlined",
|
|
@@ -51,7 +51,7 @@ export default function AddressForm({ mode, stripe, sx = {}, fieldValidation, er
|
|
|
51
51
|
name: "billing_address.state",
|
|
52
52
|
rules: {
|
|
53
53
|
required: t("payment.checkout.required"),
|
|
54
|
-
...getFieldValidation("billing_address.state", fieldValidation)
|
|
54
|
+
...getFieldValidation("billing_address.state", fieldValidation, locale)
|
|
55
55
|
},
|
|
56
56
|
errorPosition,
|
|
57
57
|
variant: "outlined",
|
|
@@ -69,7 +69,7 @@ export default function AddressForm({ mode, stripe, sx = {}, fieldValidation, er
|
|
|
69
69
|
const isValid = validatePostalCode(x, country);
|
|
70
70
|
return isValid ? true : t("payment.checkout.invalid");
|
|
71
71
|
},
|
|
72
|
-
...getFieldValidation("billing_address.postal_code", fieldValidation)
|
|
72
|
+
...getFieldValidation("billing_address.postal_code", fieldValidation, locale)
|
|
73
73
|
},
|
|
74
74
|
errorPosition,
|
|
75
75
|
variant: "outlined",
|
|
@@ -111,7 +111,7 @@ export default function AddressForm({ mode, stripe, sx = {}, fieldValidation, er
|
|
|
111
111
|
const isValid = validatePostalCode(x, country);
|
|
112
112
|
return isValid ? true : t("payment.checkout.invalid");
|
|
113
113
|
},
|
|
114
|
-
...getFieldValidation("billing_address.postal_code", fieldValidation)
|
|
114
|
+
...getFieldValidation("billing_address.postal_code", fieldValidation, locale)
|
|
115
115
|
},
|
|
116
116
|
errorPosition,
|
|
117
117
|
variant: "outlined",
|
package/es/payment/form/index.js
CHANGED
|
@@ -106,7 +106,7 @@ export default function PaymentForm({
|
|
|
106
106
|
const { isMobile } = useMobile();
|
|
107
107
|
const { session, connect, payable } = usePaymentContext();
|
|
108
108
|
const subscription = useSubscription("events");
|
|
109
|
-
const formErrorPosition =
|
|
109
|
+
const formErrorPosition = "bottom";
|
|
110
110
|
const {
|
|
111
111
|
control,
|
|
112
112
|
getValues,
|
package/es/payment/form/phone.js
CHANGED
|
@@ -10,6 +10,7 @@ import { useMobile } from "../../../hooks/mobile.js";
|
|
|
10
10
|
import LoadingButton from "../../../components/loading-button.js";
|
|
11
11
|
const { Elements, PaymentElement, useElements, useStripe, loadStripe, LinkAuthenticationElement } = globalThis.__STRIPE_COMPONENTS__;
|
|
12
12
|
const PaymentElementContainer = styled("div")`
|
|
13
|
+
width: 100%;
|
|
13
14
|
opacity: 0;
|
|
14
15
|
transition: opacity 300ms ease;
|
|
15
16
|
&.visible {
|
|
@@ -5,6 +5,7 @@ export type CountrySelectProps = {
|
|
|
5
5
|
onChange: (value: CountryIso2) => void;
|
|
6
6
|
name: string;
|
|
7
7
|
sx?: SxProps;
|
|
8
|
+
showDialCode?: boolean;
|
|
8
9
|
};
|
|
9
10
|
declare const CountrySelect: import("react").ForwardRefExoticComponent<CountrySelectProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
10
11
|
export default CountrySelect;
|
|
@@ -10,11 +10,20 @@ var _material = require("@mui/material");
|
|
|
10
10
|
var _reactHookForm = require("react-hook-form");
|
|
11
11
|
var _reactInternationalPhone = require("react-international-phone");
|
|
12
12
|
var _mobile = require("../hooks/mobile");
|
|
13
|
+
const Transition = (0, _react.forwardRef)(function Transition2(props, ref) {
|
|
14
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Slide, {
|
|
15
|
+
direction: "up",
|
|
16
|
+
ref,
|
|
17
|
+
timeout: 200,
|
|
18
|
+
...props
|
|
19
|
+
});
|
|
20
|
+
});
|
|
13
21
|
const CountrySelect = (0, _react.forwardRef)(({
|
|
14
22
|
value,
|
|
15
23
|
onChange,
|
|
16
24
|
name,
|
|
17
|
-
sx
|
|
25
|
+
sx,
|
|
26
|
+
showDialCode = false
|
|
18
27
|
}, ref) => {
|
|
19
28
|
const {
|
|
20
29
|
setValue
|
|
@@ -121,10 +130,6 @@ const CountrySelect = (0, _react.forwardRef)(({
|
|
|
121
130
|
name: ""
|
|
122
131
|
};
|
|
123
132
|
}, [value]);
|
|
124
|
-
const onCountryChange = e => {
|
|
125
|
-
onChange(e.target.value);
|
|
126
|
-
setValue(name, e.target.value);
|
|
127
|
-
};
|
|
128
133
|
const handleCountryClick = code => {
|
|
129
134
|
onChange(code);
|
|
130
135
|
setValue(name, code);
|
|
@@ -169,79 +174,7 @@ const CountrySelect = (0, _react.forwardRef)(({
|
|
|
169
174
|
handleCountryClick(country.iso2);
|
|
170
175
|
}
|
|
171
176
|
};
|
|
172
|
-
|
|
173
|
-
ref,
|
|
174
|
-
open,
|
|
175
|
-
onOpen: () => setOpen(true),
|
|
176
|
-
onClose: () => setOpen(false),
|
|
177
|
-
MenuProps: {
|
|
178
|
-
style: {
|
|
179
|
-
maxHeight: "300px",
|
|
180
|
-
top: "10px"
|
|
181
|
-
},
|
|
182
|
-
anchorOrigin: {
|
|
183
|
-
vertical: "bottom",
|
|
184
|
-
horizontal: "left"
|
|
185
|
-
},
|
|
186
|
-
transformOrigin: {
|
|
187
|
-
vertical: "top",
|
|
188
|
-
horizontal: "left"
|
|
189
|
-
},
|
|
190
|
-
PaperProps: {
|
|
191
|
-
ref: menuRef,
|
|
192
|
-
sx: {
|
|
193
|
-
display: "flex",
|
|
194
|
-
"& .MuiList-root": {
|
|
195
|
-
pt: 0,
|
|
196
|
-
display: "flex",
|
|
197
|
-
flexDirection: "column",
|
|
198
|
-
overflowY: "hidden"
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
},
|
|
203
|
-
sx: {
|
|
204
|
-
width: "100%",
|
|
205
|
-
minWidth: "60px",
|
|
206
|
-
fieldset: {
|
|
207
|
-
display: "none"
|
|
208
|
-
},
|
|
209
|
-
'&.Mui-focused:has(div[aria-expanded="false"])': {
|
|
210
|
-
fieldset: {
|
|
211
|
-
display: "block"
|
|
212
|
-
}
|
|
213
|
-
},
|
|
214
|
-
".MuiSelect-select": {
|
|
215
|
-
padding: "8px",
|
|
216
|
-
paddingRight: "24px !important"
|
|
217
|
-
},
|
|
218
|
-
svg: {
|
|
219
|
-
right: 0
|
|
220
|
-
},
|
|
221
|
-
".MuiMenuItem-root": {
|
|
222
|
-
justifyContent: "flex-start"
|
|
223
|
-
},
|
|
224
|
-
...sx
|
|
225
|
-
},
|
|
226
|
-
value,
|
|
227
|
-
onChange: onCountryChange,
|
|
228
|
-
renderValue: code => /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
|
|
229
|
-
display: "flex",
|
|
230
|
-
alignItems: "center",
|
|
231
|
-
flexWrap: "nowrap",
|
|
232
|
-
gap: 0.5,
|
|
233
|
-
sx: {
|
|
234
|
-
cursor: "pointer"
|
|
235
|
-
},
|
|
236
|
-
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_reactInternationalPhone.FlagEmoji, {
|
|
237
|
-
iso2: code,
|
|
238
|
-
style: {
|
|
239
|
-
display: "flex"
|
|
240
|
-
}
|
|
241
|
-
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
242
|
-
children: countryDetail?.name
|
|
243
|
-
})]
|
|
244
|
-
}),
|
|
177
|
+
const countryListContent = /* @__PURE__ */(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
245
178
|
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
|
|
246
179
|
sx: {
|
|
247
180
|
position: "sticky",
|
|
@@ -271,7 +204,7 @@ const CountrySelect = (0, _react.forwardRef)(({
|
|
|
271
204
|
flex: 1,
|
|
272
205
|
overflowY: "auto",
|
|
273
206
|
overflowX: "hidden",
|
|
274
|
-
maxHeight: "calc(300px - 65px)",
|
|
207
|
+
maxHeight: isMobile ? "calc(60vh - 80px)" : "calc(300px - 65px)",
|
|
275
208
|
scrollBehavior: "smooth"
|
|
276
209
|
},
|
|
277
210
|
children: filteredCountries.length > 0 ? filteredCountries.map((c, index) => {
|
|
@@ -282,6 +215,8 @@ const CountrySelect = (0, _react.forwardRef)(({
|
|
|
282
215
|
selected: parsed.iso2 === value,
|
|
283
216
|
onClick: () => handleCountryClick(parsed.iso2),
|
|
284
217
|
sx: {
|
|
218
|
+
display: "flex",
|
|
219
|
+
alignItems: "center",
|
|
285
220
|
"&.Mui-selected": {
|
|
286
221
|
backgroundColor: "rgba(0, 0, 0, 0.04)"
|
|
287
222
|
},
|
|
@@ -300,6 +235,12 @@ const CountrySelect = (0, _react.forwardRef)(({
|
|
|
300
235
|
}
|
|
301
236
|
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
302
237
|
children: parsed.name
|
|
238
|
+
}), showDialCode && /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
239
|
+
sx: {
|
|
240
|
+
ml: 1
|
|
241
|
+
},
|
|
242
|
+
color: "text.secondary",
|
|
243
|
+
children: `+${parsed.dialCode}`
|
|
303
244
|
})]
|
|
304
245
|
}, parsed.iso2);
|
|
305
246
|
}) : /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.MenuItem, {
|
|
@@ -311,8 +252,175 @@ const CountrySelect = (0, _react.forwardRef)(({
|
|
|
311
252
|
})
|
|
312
253
|
})]
|
|
313
254
|
});
|
|
255
|
+
if (!isMobile) {
|
|
256
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Select, {
|
|
257
|
+
ref,
|
|
258
|
+
open,
|
|
259
|
+
onOpen: () => setOpen(true),
|
|
260
|
+
onClose: () => setOpen(false),
|
|
261
|
+
MenuProps: {
|
|
262
|
+
style: {
|
|
263
|
+
maxHeight: "300px",
|
|
264
|
+
top: "10px"
|
|
265
|
+
},
|
|
266
|
+
anchorOrigin: {
|
|
267
|
+
vertical: "bottom",
|
|
268
|
+
horizontal: "left"
|
|
269
|
+
},
|
|
270
|
+
transformOrigin: {
|
|
271
|
+
vertical: "top",
|
|
272
|
+
horizontal: "left"
|
|
273
|
+
},
|
|
274
|
+
PaperProps: {
|
|
275
|
+
ref: menuRef,
|
|
276
|
+
sx: {
|
|
277
|
+
display: "flex",
|
|
278
|
+
"& .MuiList-root": {
|
|
279
|
+
pt: 0,
|
|
280
|
+
display: "flex",
|
|
281
|
+
flexDirection: "column",
|
|
282
|
+
overflowY: "hidden"
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
},
|
|
287
|
+
sx: {
|
|
288
|
+
width: "100%",
|
|
289
|
+
minWidth: "60px",
|
|
290
|
+
fieldset: {
|
|
291
|
+
display: "none"
|
|
292
|
+
},
|
|
293
|
+
'&.Mui-focused:has(div[aria-expanded="false"])': {
|
|
294
|
+
fieldset: {
|
|
295
|
+
display: "block"
|
|
296
|
+
}
|
|
297
|
+
},
|
|
298
|
+
".MuiSelect-select": {
|
|
299
|
+
padding: "8px",
|
|
300
|
+
paddingRight: "24px !important"
|
|
301
|
+
},
|
|
302
|
+
svg: {
|
|
303
|
+
right: 0
|
|
304
|
+
},
|
|
305
|
+
".MuiMenuItem-root": {
|
|
306
|
+
justifyContent: "flex-start"
|
|
307
|
+
},
|
|
308
|
+
...sx
|
|
309
|
+
},
|
|
310
|
+
value,
|
|
311
|
+
onChange: e => {
|
|
312
|
+
onChange(e.target.value);
|
|
313
|
+
setValue(name, e.target.value);
|
|
314
|
+
},
|
|
315
|
+
renderValue: code => /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
|
|
316
|
+
display: "flex",
|
|
317
|
+
alignItems: "center",
|
|
318
|
+
flexWrap: "nowrap",
|
|
319
|
+
gap: 0.5,
|
|
320
|
+
sx: {
|
|
321
|
+
cursor: "pointer"
|
|
322
|
+
},
|
|
323
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_reactInternationalPhone.FlagEmoji, {
|
|
324
|
+
iso2: code,
|
|
325
|
+
style: {
|
|
326
|
+
display: "flex"
|
|
327
|
+
}
|
|
328
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
329
|
+
children: countryDetail?.name
|
|
330
|
+
})]
|
|
331
|
+
}),
|
|
332
|
+
children: countryListContent
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
|
|
336
|
+
ref,
|
|
337
|
+
sx: {
|
|
338
|
+
...sx
|
|
339
|
+
},
|
|
340
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
|
|
341
|
+
onClick: () => setOpen(true),
|
|
342
|
+
display: "flex",
|
|
343
|
+
alignItems: "center",
|
|
344
|
+
flexWrap: "nowrap",
|
|
345
|
+
gap: 0.5,
|
|
346
|
+
sx: {
|
|
347
|
+
cursor: "pointer",
|
|
348
|
+
padding: "8px",
|
|
349
|
+
paddingRight: "24px",
|
|
350
|
+
position: "relative",
|
|
351
|
+
border: "none",
|
|
352
|
+
"-webkit-tap-highlight-color": "transparent",
|
|
353
|
+
userSelect: "none",
|
|
354
|
+
background: "none",
|
|
355
|
+
"&:hover, &:focus, &:active": {
|
|
356
|
+
backgroundColor: "transparent",
|
|
357
|
+
outline: "none"
|
|
358
|
+
},
|
|
359
|
+
touchAction: "manipulation"
|
|
360
|
+
},
|
|
361
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_reactInternationalPhone.FlagEmoji, {
|
|
362
|
+
iso2: value,
|
|
363
|
+
style: {
|
|
364
|
+
display: "flex"
|
|
365
|
+
}
|
|
366
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
367
|
+
children: countryDetail?.name
|
|
368
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
|
|
369
|
+
sx: {
|
|
370
|
+
position: "absolute",
|
|
371
|
+
right: "8px",
|
|
372
|
+
width: 0,
|
|
373
|
+
height: 0,
|
|
374
|
+
borderLeft: "5px solid transparent",
|
|
375
|
+
borderRight: "5px solid transparent",
|
|
376
|
+
borderTop: "5px solid currentColor"
|
|
377
|
+
}
|
|
378
|
+
})]
|
|
379
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Dialog, {
|
|
380
|
+
open,
|
|
381
|
+
onClose: () => setOpen(false),
|
|
382
|
+
fullWidth: true,
|
|
383
|
+
maxWidth: "xs",
|
|
384
|
+
TransitionComponent: Transition,
|
|
385
|
+
PaperProps: {
|
|
386
|
+
sx: {
|
|
387
|
+
position: "absolute",
|
|
388
|
+
bottom: 0,
|
|
389
|
+
m: 0,
|
|
390
|
+
borderBottomLeftRadius: 0,
|
|
391
|
+
borderBottomRightRadius: 0,
|
|
392
|
+
width: "100%"
|
|
393
|
+
}
|
|
394
|
+
},
|
|
395
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
|
|
396
|
+
sx: {
|
|
397
|
+
p: 2,
|
|
398
|
+
display: "flex",
|
|
399
|
+
justifyContent: "space-between",
|
|
400
|
+
alignItems: "center"
|
|
401
|
+
},
|
|
402
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
403
|
+
variant: "h6",
|
|
404
|
+
children: "Select Country"
|
|
405
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.IconButton, {
|
|
406
|
+
edge: "end",
|
|
407
|
+
onClick: () => setOpen(false),
|
|
408
|
+
sx: {
|
|
409
|
+
"-webkit-tap-highlight-color": "transparent"
|
|
410
|
+
},
|
|
411
|
+
children: "\u2715"
|
|
412
|
+
})]
|
|
413
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.DialogContent, {
|
|
414
|
+
sx: {
|
|
415
|
+
p: 0
|
|
416
|
+
},
|
|
417
|
+
children: countryListContent
|
|
418
|
+
})]
|
|
419
|
+
})]
|
|
420
|
+
});
|
|
314
421
|
});
|
|
315
422
|
CountrySelect.defaultProps = {
|
|
316
|
-
sx: {}
|
|
423
|
+
sx: {},
|
|
424
|
+
showDialCode: false
|
|
317
425
|
};
|
|
318
426
|
module.exports = CountrySelect;
|
package/lib/contexts/payment.js
CHANGED
|
@@ -53,6 +53,20 @@ const getCurrency = (currencyId, methods) => {
|
|
|
53
53
|
const getMethod = (methodId, methods) => {
|
|
54
54
|
return methods.find(x => x.id === methodId);
|
|
55
55
|
};
|
|
56
|
+
const syncToSpaceRequest = (userDid, spaceDid) => {
|
|
57
|
+
const cacheKey = `sync-space-${userDid}-${spaceDid}`;
|
|
58
|
+
const cachedRequest = new _cachedRequest.CachedRequest(cacheKey, () => _api.default.post("/api/customers/sync-to-space"), {
|
|
59
|
+
ttl: 1e3 * 60 * 60
|
|
60
|
+
// 1 hour
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
return cachedRequest.fetch(false).then(res => {
|
|
64
|
+
if (!res.success) {
|
|
65
|
+
cachedRequest.clearCache();
|
|
66
|
+
}
|
|
67
|
+
return res;
|
|
68
|
+
});
|
|
69
|
+
};
|
|
56
70
|
function PaymentProvider({
|
|
57
71
|
session,
|
|
58
72
|
connect,
|
|
@@ -84,6 +98,13 @@ function PaymentProvider({
|
|
|
84
98
|
} = (0, _ahooks.useRequest)(getSettings, {
|
|
85
99
|
refreshDeps: [livemode]
|
|
86
100
|
});
|
|
101
|
+
(0, _react.useEffect)(() => {
|
|
102
|
+
const didSpace = session?.user?.didSpace;
|
|
103
|
+
const userDid = session?.user?.did;
|
|
104
|
+
if (userDid && didSpace && didSpace.endpoint && didSpace.did) {
|
|
105
|
+
syncToSpaceRequest(userDid, didSpace.did);
|
|
106
|
+
}
|
|
107
|
+
}, [session?.user]);
|
|
87
108
|
const prefix = (0, _util.getPrefix)();
|
|
88
109
|
const [payable, setPayable] = (0, _react.useState)(true);
|
|
89
110
|
if (error) {
|
|
@@ -25,7 +25,8 @@ function AddressForm({
|
|
|
25
25
|
errorPosition
|
|
26
26
|
}) {
|
|
27
27
|
const {
|
|
28
|
-
t
|
|
28
|
+
t,
|
|
29
|
+
locale
|
|
29
30
|
} = (0, _context.useLocaleContext)();
|
|
30
31
|
const {
|
|
31
32
|
control
|
|
@@ -51,7 +52,7 @@ function AddressForm({
|
|
|
51
52
|
name: "billing_address.line1",
|
|
52
53
|
rules: {
|
|
53
54
|
required: t("payment.checkout.required"),
|
|
54
|
-
...(0, _validator.getFieldValidation)("billing_address.line1", fieldValidation)
|
|
55
|
+
...(0, _validator.getFieldValidation)("billing_address.line1", fieldValidation, locale)
|
|
55
56
|
},
|
|
56
57
|
errorPosition,
|
|
57
58
|
variant: "outlined",
|
|
@@ -63,7 +64,7 @@ function AddressForm({
|
|
|
63
64
|
name: "billing_address.city",
|
|
64
65
|
rules: {
|
|
65
66
|
required: t("payment.checkout.required"),
|
|
66
|
-
...(0, _validator.getFieldValidation)("billing_address.city", fieldValidation)
|
|
67
|
+
...(0, _validator.getFieldValidation)("billing_address.city", fieldValidation, locale)
|
|
67
68
|
},
|
|
68
69
|
errorPosition,
|
|
69
70
|
variant: "outlined",
|
|
@@ -75,7 +76,7 @@ function AddressForm({
|
|
|
75
76
|
name: "billing_address.state",
|
|
76
77
|
rules: {
|
|
77
78
|
required: t("payment.checkout.required"),
|
|
78
|
-
...(0, _validator.getFieldValidation)("billing_address.state", fieldValidation)
|
|
79
|
+
...(0, _validator.getFieldValidation)("billing_address.state", fieldValidation, locale)
|
|
79
80
|
},
|
|
80
81
|
errorPosition,
|
|
81
82
|
variant: "outlined",
|
|
@@ -91,7 +92,7 @@ function AddressForm({
|
|
|
91
92
|
const isValid = (0, _validator.validatePostalCode)(x, country);
|
|
92
93
|
return isValid ? true : t("payment.checkout.invalid");
|
|
93
94
|
},
|
|
94
|
-
...(0, _validator.getFieldValidation)("billing_address.postal_code", fieldValidation)
|
|
95
|
+
...(0, _validator.getFieldValidation)("billing_address.postal_code", fieldValidation, locale)
|
|
95
96
|
},
|
|
96
97
|
errorPosition,
|
|
97
98
|
variant: "outlined",
|
|
@@ -148,7 +149,7 @@ function AddressForm({
|
|
|
148
149
|
const isValid = (0, _validator.validatePostalCode)(x, country);
|
|
149
150
|
return isValid ? true : t("payment.checkout.invalid");
|
|
150
151
|
},
|
|
151
|
-
...(0, _validator.getFieldValidation)("billing_address.postal_code", fieldValidation)
|
|
152
|
+
...(0, _validator.getFieldValidation)("billing_address.postal_code", fieldValidation, locale)
|
|
152
153
|
},
|
|
153
154
|
errorPosition,
|
|
154
155
|
variant: "outlined",
|
|
@@ -124,7 +124,7 @@ function PaymentForm({
|
|
|
124
124
|
payable
|
|
125
125
|
} = (0, _payment.usePaymentContext)();
|
|
126
126
|
const subscription = (0, _subscription.useSubscription)("events");
|
|
127
|
-
const formErrorPosition =
|
|
127
|
+
const formErrorPosition = "bottom";
|
|
128
128
|
const {
|
|
129
129
|
control,
|
|
130
130
|
getValues,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/payment-react",
|
|
3
|
-
"version": "1.18.
|
|
3
|
+
"version": "1.18.37",
|
|
4
4
|
"description": "Reusable react components for payment kit v2",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -54,10 +54,10 @@
|
|
|
54
54
|
}
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@arcblock/did-connect": "^2.13.
|
|
58
|
-
"@arcblock/ux": "^2.13.
|
|
57
|
+
"@arcblock/did-connect": "^2.13.13",
|
|
58
|
+
"@arcblock/ux": "^2.13.13",
|
|
59
59
|
"@arcblock/ws": "^1.20.2",
|
|
60
|
-
"@blocklet/ui-react": "^2.13.
|
|
60
|
+
"@blocklet/ui-react": "^2.13.13",
|
|
61
61
|
"@mui/icons-material": "^5.16.6",
|
|
62
62
|
"@mui/lab": "^5.0.0-alpha.173",
|
|
63
63
|
"@mui/material": "^5.16.6",
|
|
@@ -93,7 +93,7 @@
|
|
|
93
93
|
"@babel/core": "^7.25.2",
|
|
94
94
|
"@babel/preset-env": "^7.25.2",
|
|
95
95
|
"@babel/preset-react": "^7.24.7",
|
|
96
|
-
"@blocklet/payment-types": "1.18.
|
|
96
|
+
"@blocklet/payment-types": "1.18.37",
|
|
97
97
|
"@storybook/addon-essentials": "^7.6.20",
|
|
98
98
|
"@storybook/addon-interactions": "^7.6.20",
|
|
99
99
|
"@storybook/addon-links": "^7.6.20",
|
|
@@ -124,5 +124,5 @@
|
|
|
124
124
|
"vite-plugin-babel": "^1.2.0",
|
|
125
125
|
"vite-plugin-node-polyfills": "^0.21.0"
|
|
126
126
|
},
|
|
127
|
-
"gitHead": "
|
|
127
|
+
"gitHead": "ea43bad3259d340da14fc0dd0e5b02f2c88c5093"
|
|
128
128
|
}
|