@blocklet/payment-react 1.18.56 → 1.19.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 (251) hide show
  1. package/es/checkout/donate.d.ts +1 -15
  2. package/es/checkout/donate.js +301 -189
  3. package/es/checkout/form.d.ts +1 -15
  4. package/es/checkout/form.js +5 -13
  5. package/es/checkout/table.js +3 -3
  6. package/es/components/blockchain/gas.d.ts +1 -5
  7. package/es/components/blockchain/gas.js +10 -2
  8. package/es/components/blockchain/tx.d.ts +1 -8
  9. package/es/components/blockchain/tx.js +29 -10
  10. package/es/components/confirm.d.ts +1 -10
  11. package/es/components/confirm.js +4 -10
  12. package/es/components/country-select.d.ts +3 -2
  13. package/es/components/country-select.js +375 -352
  14. package/es/components/date-range-picker.d.ts +13 -0
  15. package/es/components/date-range-picker.js +279 -0
  16. package/es/components/input.d.ts +14 -20
  17. package/es/components/input.js +51 -44
  18. package/es/components/label.d.ts +7 -0
  19. package/es/components/label.js +49 -0
  20. package/es/components/lazy-loader.js +1 -2
  21. package/es/components/link.d.ts +2 -9
  22. package/es/components/link.js +9 -6
  23. package/es/components/livemode.d.ts +2 -8
  24. package/es/components/livemode.js +1 -5
  25. package/es/components/loading-button.d.ts +6 -1
  26. package/es/components/loading-button.js +56 -66
  27. package/es/components/over-due-invoice-payment.d.ts +0 -18
  28. package/es/components/over-due-invoice-payment.js +138 -95
  29. package/es/components/payment-beneficiaries.d.ts +2 -7
  30. package/es/components/payment-beneficiaries.js +86 -40
  31. package/es/components/pricing-item.d.ts +0 -5
  32. package/es/components/pricing-item.js +1 -4
  33. package/es/components/pricing-table.d.ts +2 -10
  34. package/es/components/pricing-table.js +8 -7
  35. package/es/components/resume-subscription.d.ts +0 -10
  36. package/es/components/resume-subscription.js +42 -21
  37. package/es/components/truncated-text.d.ts +2 -9
  38. package/es/components/truncated-text.js +0 -5
  39. package/es/contexts/donate.d.ts +0 -7
  40. package/es/contexts/donate.js +10 -8
  41. package/es/contexts/payment.d.ts +1 -4
  42. package/es/contexts/payment.js +7 -2
  43. package/es/history/credit/grants-list.d.ts +14 -0
  44. package/es/history/credit/grants-list.js +215 -0
  45. package/es/history/credit/transactions-list.d.ts +13 -0
  46. package/es/history/credit/transactions-list.js +255 -0
  47. package/es/history/invoice/list.d.ts +2 -18
  48. package/es/history/invoice/list.js +172 -74
  49. package/es/history/payment/list.js +115 -38
  50. package/es/hooks/keyboard.d.ts +1 -1
  51. package/es/hooks/keyboard.js +2 -4
  52. package/es/index.d.ts +5 -1
  53. package/es/index.js +10 -1
  54. package/es/libs/cached-request.js +2 -4
  55. package/es/libs/phone-validator.js +1 -2
  56. package/es/libs/util.d.ts +2 -0
  57. package/es/libs/util.js +14 -4
  58. package/es/libs/validator.js +2 -4
  59. package/es/locales/en.js +20 -2
  60. package/es/locales/zh.js +20 -2
  61. package/es/payment/amount.d.ts +2 -7
  62. package/es/payment/amount.js +1 -5
  63. package/es/payment/donation-form.d.ts +2 -10
  64. package/es/payment/donation-form.js +196 -160
  65. package/es/payment/error.d.ts +2 -8
  66. package/es/payment/error.js +40 -20
  67. package/es/payment/footer.d.ts +2 -3
  68. package/es/payment/footer.js +19 -6
  69. package/es/payment/form/addon.js +14 -4
  70. package/es/payment/form/address.d.ts +2 -9
  71. package/es/payment/form/address.js +3 -6
  72. package/es/payment/form/currency.js +45 -25
  73. package/es/payment/form/index.d.ts +2 -8
  74. package/es/payment/form/index.js +151 -71
  75. package/es/payment/form/phone.js +2 -4
  76. package/es/payment/form/stripe/form.d.ts +2 -8
  77. package/es/payment/form/stripe/form.js +1 -3
  78. package/es/payment/header.js +38 -16
  79. package/es/payment/index.d.ts +2 -9
  80. package/es/payment/index.js +23 -17
  81. package/es/payment/product-card.d.ts +2 -11
  82. package/es/payment/product-card.js +84 -50
  83. package/es/payment/product-donation.js +175 -114
  84. package/es/payment/product-item.d.ts +9 -9
  85. package/es/payment/product-item.js +320 -145
  86. package/es/payment/product-skeleton.js +2 -2
  87. package/es/payment/skeleton/donation.js +27 -7
  88. package/es/payment/skeleton/overview.js +22 -2
  89. package/es/payment/skeleton/payment.js +33 -5
  90. package/es/payment/success.d.ts +2 -9
  91. package/es/payment/success.js +41 -14
  92. package/es/payment/summary.d.ts +4 -17
  93. package/es/payment/summary.js +193 -111
  94. package/es/theme/index.d.ts +0 -5
  95. package/es/theme/index.js +2 -5
  96. package/es/theme/typography.d.ts +2 -2
  97. package/lib/checkout/donate.d.ts +1 -15
  98. package/lib/checkout/donate.js +75 -54
  99. package/lib/checkout/form.d.ts +1 -15
  100. package/lib/checkout/form.js +7 -15
  101. package/lib/checkout/table.js +4 -4
  102. package/lib/components/blockchain/gas.d.ts +1 -5
  103. package/lib/components/blockchain/gas.js +3 -2
  104. package/lib/components/blockchain/tx.d.ts +1 -8
  105. package/lib/components/blockchain/tx.js +15 -10
  106. package/lib/components/confirm.d.ts +1 -10
  107. package/lib/components/confirm.js +5 -11
  108. package/lib/components/country-select.d.ts +3 -2
  109. package/lib/components/country-select.js +23 -22
  110. package/lib/components/date-range-picker.d.ts +13 -0
  111. package/lib/components/date-range-picker.js +329 -0
  112. package/lib/components/input.d.ts +14 -20
  113. package/lib/components/input.js +28 -27
  114. package/lib/components/label.d.ts +7 -0
  115. package/lib/components/label.js +60 -0
  116. package/lib/components/lazy-loader.js +1 -1
  117. package/lib/components/link.d.ts +2 -9
  118. package/lib/components/link.js +3 -8
  119. package/lib/components/livemode.d.ts +2 -8
  120. package/lib/components/livemode.js +3 -7
  121. package/lib/components/loading-button.d.ts +6 -1
  122. package/lib/components/loading-button.js +9 -17
  123. package/lib/components/over-due-invoice-payment.d.ts +0 -18
  124. package/lib/components/over-due-invoice-payment.js +31 -33
  125. package/lib/components/payment-beneficiaries.d.ts +2 -7
  126. package/lib/components/payment-beneficiaries.js +12 -11
  127. package/lib/components/pricing-item.d.ts +0 -5
  128. package/lib/components/pricing-item.js +2 -5
  129. package/lib/components/pricing-table.d.ts +2 -10
  130. package/lib/components/pricing-table.js +5 -11
  131. package/lib/components/resume-subscription.d.ts +0 -10
  132. package/lib/components/resume-subscription.js +16 -16
  133. package/lib/components/table.js +1 -1
  134. package/lib/components/truncated-text.d.ts +2 -9
  135. package/lib/components/truncated-text.js +1 -6
  136. package/lib/contexts/donate.d.ts +0 -7
  137. package/lib/contexts/donate.js +4 -7
  138. package/lib/contexts/payment.d.ts +1 -4
  139. package/lib/contexts/payment.js +4 -7
  140. package/lib/history/credit/grants-list.d.ts +14 -0
  141. package/lib/history/credit/grants-list.js +277 -0
  142. package/lib/history/credit/transactions-list.d.ts +13 -0
  143. package/lib/history/credit/transactions-list.js +301 -0
  144. package/lib/history/invoice/list.d.ts +2 -18
  145. package/lib/history/invoice/list.js +73 -37
  146. package/lib/history/payment/list.js +30 -16
  147. package/lib/hooks/keyboard.d.ts +1 -1
  148. package/lib/hooks/mobile.js +1 -1
  149. package/lib/hooks/subscription.js +1 -1
  150. package/lib/index.d.ts +5 -1
  151. package/lib/index.js +41 -2
  152. package/lib/libs/api.js +1 -1
  153. package/lib/libs/dayjs.js +1 -1
  154. package/lib/libs/phone-validator.js +0 -2
  155. package/lib/libs/theme.js +1 -1
  156. package/lib/libs/util.d.ts +2 -0
  157. package/lib/libs/util.js +15 -1
  158. package/lib/libs/validator.js +1 -1
  159. package/lib/locales/en.js +21 -3
  160. package/lib/locales/index.js +1 -1
  161. package/lib/locales/zh.js +21 -3
  162. package/lib/payment/amount.d.ts +2 -7
  163. package/lib/payment/amount.js +2 -6
  164. package/lib/payment/donation-form.d.ts +2 -10
  165. package/lib/payment/donation-form.js +33 -38
  166. package/lib/payment/error.d.ts +2 -8
  167. package/lib/payment/error.js +11 -13
  168. package/lib/payment/footer.d.ts +2 -3
  169. package/lib/payment/footer.js +5 -5
  170. package/lib/payment/form/addon.js +5 -3
  171. package/lib/payment/form/address.d.ts +2 -9
  172. package/lib/payment/form/address.js +5 -8
  173. package/lib/payment/form/currency.js +3 -3
  174. package/lib/payment/form/index.d.ts +2 -8
  175. package/lib/payment/form/index.js +64 -21
  176. package/lib/payment/form/phone.js +1 -1
  177. package/lib/payment/form/stripe/form.d.ts +2 -8
  178. package/lib/payment/form/stripe/form.js +3 -6
  179. package/lib/payment/header.js +8 -4
  180. package/lib/payment/index.d.ts +2 -9
  181. package/lib/payment/index.js +27 -18
  182. package/lib/payment/product-card.d.ts +2 -11
  183. package/lib/payment/product-card.js +13 -20
  184. package/lib/payment/product-donation.js +71 -66
  185. package/lib/payment/product-item.d.ts +9 -9
  186. package/lib/payment/product-item.js +168 -29
  187. package/lib/payment/product-skeleton.js +2 -2
  188. package/lib/payment/skeleton/donation.js +8 -4
  189. package/lib/payment/skeleton/overview.js +6 -2
  190. package/lib/payment/skeleton/payment.js +9 -3
  191. package/lib/payment/success.d.ts +2 -9
  192. package/lib/payment/success.js +12 -15
  193. package/lib/payment/summary.d.ts +4 -17
  194. package/lib/payment/summary.js +53 -45
  195. package/lib/theme/index.d.ts +0 -5
  196. package/lib/theme/index.js +2 -5
  197. package/lib/theme/typography.d.ts +2 -2
  198. package/package.json +40 -40
  199. package/src/checkout/donate.tsx +103 -35
  200. package/src/checkout/form.tsx +5 -14
  201. package/src/checkout/table.tsx +3 -3
  202. package/src/components/blockchain/gas.tsx +5 -3
  203. package/src/components/blockchain/tx.tsx +19 -11
  204. package/src/components/confirm.tsx +4 -11
  205. package/src/components/country-select.tsx +391 -378
  206. package/src/components/date-range-picker.tsx +310 -0
  207. package/src/components/input.tsx +61 -46
  208. package/src/components/label.tsx +58 -0
  209. package/src/components/link.tsx +9 -7
  210. package/src/components/livemode.tsx +2 -6
  211. package/src/components/loading-button.tsx +63 -76
  212. package/src/components/over-due-invoice-payment.tsx +43 -28
  213. package/src/components/payment-beneficiaries.tsx +33 -14
  214. package/src/components/pricing-item.tsx +1 -4
  215. package/src/components/pricing-table.tsx +8 -8
  216. package/src/components/resume-subscription.tsx +20 -14
  217. package/src/components/table.tsx +2 -2
  218. package/src/components/truncated-text.tsx +0 -6
  219. package/src/contexts/donate.tsx +6 -7
  220. package/src/contexts/payment.tsx +7 -3
  221. package/src/history/credit/grants-list.tsx +276 -0
  222. package/src/history/credit/transactions-list.tsx +317 -0
  223. package/src/history/invoice/list.tsx +92 -36
  224. package/src/history/payment/list.tsx +53 -16
  225. package/src/hooks/keyboard.ts +1 -1
  226. package/src/index.ts +9 -0
  227. package/src/libs/util.ts +14 -0
  228. package/src/locales/en.tsx +20 -0
  229. package/src/locales/zh.tsx +19 -0
  230. package/src/payment/amount.tsx +1 -6
  231. package/src/payment/donation-form.tsx +47 -29
  232. package/src/payment/error.tsx +16 -8
  233. package/src/payment/footer.tsx +11 -3
  234. package/src/payment/form/addon.tsx +6 -1
  235. package/src/payment/form/address.tsx +3 -7
  236. package/src/payment/form/currency.tsx +12 -2
  237. package/src/payment/form/index.tsx +121 -45
  238. package/src/payment/form/stripe/form.tsx +1 -5
  239. package/src/payment/header.tsx +14 -2
  240. package/src/payment/index.tsx +27 -22
  241. package/src/payment/product-card.tsx +41 -18
  242. package/src/payment/product-donation.tsx +85 -47
  243. package/src/payment/product-item.tsx +198 -28
  244. package/src/payment/product-skeleton.tsx +3 -2
  245. package/src/payment/skeleton/donation.tsx +12 -2
  246. package/src/payment/skeleton/overview.tsx +12 -2
  247. package/src/payment/skeleton/payment.tsx +16 -3
  248. package/src/payment/success.tsx +26 -15
  249. package/src/payment/summary.tsx +87 -44
  250. package/src/theme/index.tsx +5 -8
  251. package/src/theme/typography.ts +2 -2
@@ -21,31 +21,51 @@ export default function CurrencySelector({ value, currencies, onChange }) {
21
21
  variant: "outlined",
22
22
  onClick: () => onChange(x.id, x.method?.id),
23
23
  className: selected ? "cko-payment-card" : "cko-payment-card-unselect",
24
- children: /* @__PURE__ */ jsxs(Stack, { direction: "row", alignItems: "center", sx: { position: "relative" }, children: [
25
- /* @__PURE__ */ jsx(Avatar, { src: x.logo, alt: x.name, sx: { width: 40, height: 40, marginRight: "12px" } }),
26
- /* @__PURE__ */ jsxs("div", { children: [
27
- /* @__PURE__ */ jsx(
28
- Typography,
29
- {
30
- variant: "h5",
31
- component: "div",
32
- sx: { fontSize: "16px", color: "text.primary", fontWeight: "500" },
33
- children: x.symbol
34
- }
35
- ),
36
- /* @__PURE__ */ jsx(Typography, { sx: { fontSize: 14 }, color: "text.lighter", gutterBottom: true, children: x.method.name })
37
- ] }),
38
- /* @__PURE__ */ jsx(
39
- Radio,
40
- {
41
- checked: selected,
42
- sx: {
43
- position: "absolute",
44
- right: 0
45
- }
46
- }
47
- )
48
- ] })
24
+ children: /* @__PURE__ */ jsxs(
25
+ Stack,
26
+ {
27
+ direction: "row",
28
+ sx: {
29
+ alignItems: "center",
30
+ position: "relative"
31
+ },
32
+ children: [
33
+ /* @__PURE__ */ jsx(Avatar, { src: x.logo, alt: x.name, sx: { width: 40, height: 40, marginRight: "12px" } }),
34
+ /* @__PURE__ */ jsxs("div", { children: [
35
+ /* @__PURE__ */ jsx(
36
+ Typography,
37
+ {
38
+ variant: "h5",
39
+ component: "div",
40
+ sx: { fontSize: "16px", color: "text.primary", fontWeight: "500" },
41
+ children: x.symbol
42
+ }
43
+ ),
44
+ /* @__PURE__ */ jsx(
45
+ Typography,
46
+ {
47
+ gutterBottom: true,
48
+ sx: {
49
+ color: "text.lighter",
50
+ fontSize: 14
51
+ },
52
+ children: x.method.name
53
+ }
54
+ )
55
+ ] }),
56
+ /* @__PURE__ */ jsx(
57
+ Radio,
58
+ {
59
+ checked: selected,
60
+ sx: {
61
+ position: "absolute",
62
+ right: 0
63
+ }
64
+ }
65
+ )
66
+ ]
67
+ }
68
+ )
49
69
  },
50
70
  x.id
51
71
  );
@@ -6,11 +6,5 @@ type PageData = CheckoutContext & CheckoutCallbacks & {
6
6
  onlyShowBtn?: boolean;
7
7
  isDonation?: boolean;
8
8
  };
9
- declare function PaymentForm({ checkoutSession, paymentMethods, paymentIntent, paymentLink, customer, onPaid, onError, action, onlyShowBtn, isDonation, }: PageData): import("react").JSX.Element;
10
- declare namespace PaymentForm {
11
- var defaultProps: {
12
- onlyShowBtn: boolean;
13
- isDonation: boolean;
14
- };
15
- }
16
- export default PaymentForm;
9
+ export default function PaymentForm({ checkoutSession, paymentMethods, paymentIntent, paymentLink, customer, onPaid, onError, action, onlyShowBtn, isDonation, }: PageData): import("react").JSX.Element;
10
+ export {};
@@ -85,10 +85,6 @@ const setUserFormValues = (userInfo, currentValues, setValue, options = {}) => {
85
85
  }
86
86
  });
87
87
  };
88
- PaymentForm.defaultProps = {
89
- onlyShowBtn: false,
90
- isDonation: false
91
- };
92
88
  export default function PaymentForm({
93
89
  checkoutSession,
94
90
  paymentMethods,
@@ -99,7 +95,7 @@ export default function PaymentForm({
99
95
  onError,
100
96
  // mode,
101
97
  action,
102
- onlyShowBtn,
98
+ onlyShowBtn = false,
103
99
  isDonation = false
104
100
  }) {
105
101
  const { t, locale } = useLocaleContext();
@@ -135,7 +131,8 @@ export default function PaymentForm({
135
131
  customer,
136
132
  customerLimited: false,
137
133
  stripePaying: false,
138
- fastCheckoutInfo: null
134
+ fastCheckoutInfo: null,
135
+ creditInsufficientInfo: null
139
136
  });
140
137
  const currencies = flattenPaymentMethods(paymentMethods);
141
138
  const onCheckoutComplete = useMemoizedFn(async ({ response }) => {
@@ -270,8 +267,7 @@ export default function PaymentForm({
270
267
  }
271
268
  };
272
269
  const handleFastCheckoutConfirm = async () => {
273
- if (!state.fastCheckoutInfo)
274
- return;
270
+ if (!state.fastCheckoutInfo) return;
275
271
  setState({
276
272
  fastCheckoutInfo: {
277
273
  ...state.fastCheckoutInfo,
@@ -305,6 +301,9 @@ export default function PaymentForm({
305
301
  const handleFastCheckoutCancel = () => {
306
302
  setState({ fastCheckoutInfo: null });
307
303
  };
304
+ const handleCreditInsufficientClose = () => {
305
+ setState({ creditInsufficientInfo: null });
306
+ };
308
307
  const openConnect = () => {
309
308
  try {
310
309
  if (!["arcblock", "ethereum", "base"].includes(method.type)) {
@@ -360,7 +359,27 @@ export default function PaymentForm({
360
359
  customerLimited: false
361
360
  });
362
361
  if (["arcblock", "ethereum", "base"].includes(method.type)) {
363
- if ((result.data.balance?.sufficient || result.data.delegation?.sufficient) && !isDonationMode && result.data.fastPayInfo) {
362
+ if (paymentCurrency?.type === "credit") {
363
+ if (result.data.creditSufficient === true) {
364
+ setState({
365
+ fastCheckoutInfo: {
366
+ open: true,
367
+ loading: false,
368
+ sourceType: "credit",
369
+ amount: result.data.fastPayInfo?.amount || "0",
370
+ payer: result.data.fastPayInfo?.payer,
371
+ availableCredit: result.data.fastPayInfo?.amount || "0",
372
+ balance: result.data.fastPayInfo?.token?.balance || "0"
373
+ }
374
+ });
375
+ } else {
376
+ setState({
377
+ creditInsufficientInfo: {
378
+ open: true
379
+ }
380
+ });
381
+ }
382
+ } else if ((result.data.balance?.sufficient || result.data.delegation?.sufficient) && !isDonationMode && result.data.fastPayInfo) {
364
383
  setState({
365
384
  fastCheckoutInfo: {
366
385
  open: true,
@@ -450,45 +469,94 @@ export default function PaymentForm({
450
469
  {
451
470
  onConfirm: handleFastCheckoutConfirm,
452
471
  onCancel: handleFastCheckoutCancel,
453
- title: t("payment.checkout.fastPay.title"),
454
- message: /* @__PURE__ */ jsxs(Stack, { children: [
472
+ title: state.fastCheckoutInfo.sourceType === "credit" ? t("payment.checkout.fastPay.credit.title") : t("payment.checkout.fastPay.title"),
473
+ message: state.fastCheckoutInfo.sourceType === "credit" ? /* @__PURE__ */ jsx(Typography, { children: t("payment.checkout.fastPay.credit.meteringSubscriptionMessage", {
474
+ available: `${fromUnitToToken(state.fastCheckoutInfo?.balance || "0", paymentCurrency?.decimal || 18).toString()} ${paymentCurrency?.symbol}`
475
+ }) }) : /* @__PURE__ */ jsxs(Stack, { children: [
455
476
  /* @__PURE__ */ jsx(Typography, { children: t("payment.checkout.fastPay.autoPaymentReason") }),
456
477
  /* @__PURE__ */ jsx(Divider, { sx: { mt: 1.5, mb: 1.5 } }),
457
478
  /* @__PURE__ */ jsxs(Stack, { spacing: 1, children: [
458
- /* @__PURE__ */ jsxs(Stack, { flexDirection: "row", alignItems: "center", justifyContent: "space-between", children: [
459
- /* @__PURE__ */ jsx(Typography, { color: "text.primary", sx: { whiteSpace: "nowrap" }, children: t("payment.checkout.fastPay.payer") }),
460
- /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 0.5 }, children: [
461
- /* @__PURE__ */ jsx(DID, { did: state.fastCheckoutInfo.payer || "", compact: true, responsive: false }),
462
- balanceLink && /* @__PURE__ */ jsx(Tooltip, { title: t("payment.checkout.fastPay.balanceLink"), placement: "top", children: /* @__PURE__ */ jsx(
463
- OpenInNew,
464
- {
465
- sx: {
466
- color: "text.lighter",
467
- fontSize: "0.85rem",
468
- cursor: "pointer",
469
- "&:hover": { color: "text.primary" }
470
- },
471
- onClick: () => {
472
- window.open(balanceLink, "_blank");
479
+ /* @__PURE__ */ jsxs(
480
+ Stack,
481
+ {
482
+ sx: {
483
+ flexDirection: "row",
484
+ alignItems: "center",
485
+ justifyContent: "space-between"
486
+ },
487
+ children: [
488
+ /* @__PURE__ */ jsx(
489
+ Typography,
490
+ {
491
+ sx: {
492
+ color: "text.primary",
493
+ whiteSpace: "nowrap"
494
+ },
495
+ children: t("payment.checkout.fastPay.payer")
473
496
  }
474
- }
475
- ) })
476
- ] })
477
- ] }),
478
- /* @__PURE__ */ jsxs(Stack, { flexDirection: "row", alignItems: "center", justifyContent: "space-between", children: [
479
- /* @__PURE__ */ jsx(Typography, { color: "text.primary", children: t("payment.checkout.fastPay.amount") }),
480
- /* @__PURE__ */ jsxs(Typography, { children: [
481
- fromUnitToToken(state.fastCheckoutInfo.amount, paymentCurrency?.decimal || 18).toString(),
482
- " ",
483
- paymentCurrency?.symbol
484
- ] })
485
- ] })
497
+ ),
498
+ /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 0.5 }, children: [
499
+ /* @__PURE__ */ jsx(DID, { did: state.fastCheckoutInfo.payer || "", compact: true, responsive: false }),
500
+ balanceLink && /* @__PURE__ */ jsx(Tooltip, { title: t("payment.checkout.fastPay.balanceLink"), placement: "top", children: /* @__PURE__ */ jsx(
501
+ OpenInNew,
502
+ {
503
+ sx: {
504
+ color: "text.lighter",
505
+ fontSize: "0.85rem",
506
+ cursor: "pointer",
507
+ "&:hover": { color: "text.primary" }
508
+ },
509
+ onClick: () => {
510
+ window.open(balanceLink, "_blank");
511
+ }
512
+ }
513
+ ) })
514
+ ] })
515
+ ]
516
+ }
517
+ ),
518
+ /* @__PURE__ */ jsxs(
519
+ Stack,
520
+ {
521
+ sx: {
522
+ flexDirection: "row",
523
+ alignItems: "center",
524
+ justifyContent: "space-between"
525
+ },
526
+ children: [
527
+ /* @__PURE__ */ jsx(
528
+ Typography,
529
+ {
530
+ sx: {
531
+ color: "text.primary"
532
+ },
533
+ children: t("payment.checkout.fastPay.amount")
534
+ }
535
+ ),
536
+ /* @__PURE__ */ jsxs(Typography, { children: [
537
+ fromUnitToToken(state.fastCheckoutInfo.amount, paymentCurrency?.decimal || 18).toString(),
538
+ " ",
539
+ paymentCurrency?.symbol
540
+ ] })
541
+ ]
542
+ }
543
+ )
486
544
  ] })
487
545
  ] }),
488
546
  loading: state.fastCheckoutInfo.loading,
489
547
  color: "primary"
490
548
  }
491
549
  );
550
+ const CreditInsufficientDialog = state.creditInsufficientInfo && /* @__PURE__ */ jsx(
551
+ ConfirmDialog,
552
+ {
553
+ onConfirm: handleCreditInsufficientClose,
554
+ onCancel: handleCreditInsufficientClose,
555
+ title: t("payment.checkout.fastPay.credit.insufficientTitle"),
556
+ message: /* @__PURE__ */ jsx(Typography, { children: t("payment.checkout.fastPay.credit.insufficientMessage") }),
557
+ confirm: t("common.confirm")
558
+ }
559
+ );
492
560
  if (onlyShowBtn) {
493
561
  return /* @__PURE__ */ jsxs(Fragment, { children: [
494
562
  /* @__PURE__ */ jsx(Box, { className: "cko-payment-submit-btn", children: /* @__PURE__ */ jsxs(
@@ -541,7 +609,8 @@ export default function PaymentForm({
541
609
  }
542
610
  }
543
611
  ),
544
- FastCheckoutConfirmDialog
612
+ FastCheckoutConfirmDialog,
613
+ CreditInsufficientDialog
545
614
  ] });
546
615
  }
547
616
  return /* @__PURE__ */ jsxs(Fragment, { children: [
@@ -563,40 +632,50 @@ export default function PaymentForm({
563
632
  children: t("payment.checkout.paymentDetails")
564
633
  }
565
634
  ),
566
- /* @__PURE__ */ jsx(Fade, { in: true, children: /* @__PURE__ */ jsxs(Stack, { direction: "column", alignItems: "flex-start", className: "cko-payment-methods", children: [
567
- /* @__PURE__ */ jsx(Stack, { direction: "row", sx: { width: "100%" }, children: /* @__PURE__ */ jsx(
568
- Controller,
569
- {
570
- name: "payment_currency",
571
- control,
572
- render: ({ field }) => /* @__PURE__ */ jsx(
573
- CurrencySelector,
635
+ /* @__PURE__ */ jsx(Fade, { in: true, children: /* @__PURE__ */ jsxs(
636
+ Stack,
637
+ {
638
+ direction: "column",
639
+ className: "cko-payment-methods",
640
+ sx: {
641
+ alignItems: "flex-start"
642
+ },
643
+ children: [
644
+ /* @__PURE__ */ jsx(Stack, { direction: "row", sx: { width: "100%" }, children: /* @__PURE__ */ jsx(
645
+ Controller,
574
646
  {
575
- value: field.value,
576
- currencies,
577
- onChange: (id, methodId) => {
578
- field.onChange(id);
579
- setValue("payment_method", methodId);
580
- saveCurrencyPreference(id, session?.user?.did);
581
- }
647
+ name: "payment_currency",
648
+ control,
649
+ render: ({ field }) => /* @__PURE__ */ jsx(
650
+ CurrencySelector,
651
+ {
652
+ value: field.value,
653
+ currencies,
654
+ onChange: (id, methodId) => {
655
+ field.onChange(id);
656
+ setValue("payment_method", methodId);
657
+ saveCurrencyPreference(id, session?.user?.did);
658
+ }
659
+ }
660
+ )
661
+ }
662
+ ) }),
663
+ state.stripePaying && state.stripeContext && /* @__PURE__ */ jsx(
664
+ StripeCheckout,
665
+ {
666
+ clientSecret: state.stripeContext.client_secret,
667
+ intentType: state.stripeContext.intent_type,
668
+ publicKey: method.settings.stripe?.publishable_key,
669
+ customer: state.customer,
670
+ mode: checkoutSession.mode,
671
+ onConfirm: onStripeConfirm,
672
+ onCancel: onStripeCancel,
673
+ returnUrl: checkoutSession?.success_url
582
674
  }
583
675
  )
584
- }
585
- ) }),
586
- state.stripePaying && state.stripeContext && /* @__PURE__ */ jsx(
587
- StripeCheckout,
588
- {
589
- clientSecret: state.stripeContext.client_secret,
590
- intentType: state.stripeContext.intent_type,
591
- publicKey: method.settings.stripe?.publishable_key,
592
- customer: state.customer,
593
- mode: checkoutSession.mode,
594
- onConfirm: onStripeConfirm,
595
- onCancel: onStripeCancel,
596
- returnUrl: checkoutSession?.success_url
597
- }
598
- )
599
- ] }) }),
676
+ ]
677
+ }
678
+ ) }),
600
679
  showForm && /* @__PURE__ */ jsxs(
601
680
  Stack,
602
681
  {
@@ -726,6 +805,7 @@ export default function PaymentForm({
726
805
  }
727
806
  }
728
807
  ),
729
- FastCheckoutConfirmDialog
808
+ FastCheckoutConfirmDialog,
809
+ CreditInsufficientDialog
730
810
  ] });
731
811
  }
@@ -15,8 +15,7 @@ export default function PhoneInput({ ...props }) {
15
15
  const values = getValues();
16
16
  const isUpdatingRef = useRef(false);
17
17
  const safeUpdate = useCallback((callback) => {
18
- if (isUpdatingRef.current)
19
- return;
18
+ if (isUpdatingRef.current) return;
20
19
  try {
21
20
  isUpdatingRef.current = true;
22
21
  callback();
@@ -39,8 +38,7 @@ export default function PhoneInput({ ...props }) {
39
38
  });
40
39
  const userCountry = useWatch({ control, name: countryFieldName });
41
40
  useEffect(() => {
42
- if (!userCountry || userCountry === country)
43
- return;
41
+ if (!userCountry || userCountry === country) return;
44
42
  safeUpdate(() => {
45
43
  setCountry(userCountry);
46
44
  });
@@ -5,7 +5,7 @@ export type StripeCheckoutFormProps = {
5
5
  customer: TCustomer;
6
6
  mode: string;
7
7
  onConfirm: Function;
8
- returnUrl: string;
8
+ returnUrl?: string;
9
9
  };
10
10
  export type StripeCheckoutProps = {
11
11
  clientSecret: string;
@@ -17,10 +17,4 @@ export type StripeCheckoutProps = {
17
17
  onCancel: Function;
18
18
  returnUrl?: string;
19
19
  };
20
- declare function StripeCheckout({ clientSecret, intentType, publicKey, mode, customer, onConfirm, onCancel, returnUrl, }: StripeCheckoutProps): import("react").JSX.Element;
21
- declare namespace StripeCheckout {
22
- var defaultProps: {
23
- returnUrl: string;
24
- };
25
- }
26
- export default StripeCheckout;
20
+ export default function StripeCheckout({ clientSecret, intentType, publicKey, mode, customer, onConfirm, onCancel, returnUrl, }: StripeCheckoutProps): import("react").JSX.Element;
@@ -79,6 +79,7 @@ function StripeCheckoutForm({
79
79
  setState({ message: t("paymentCredit.preparePayMessage.processing") });
80
80
  break;
81
81
  case "requires_payment_method":
82
+ // 忽略该状态
82
83
  default:
83
84
  break;
84
85
  }
@@ -304,6 +305,3 @@ export default function StripeCheckout({
304
305
  }
305
306
  );
306
307
  }
307
- StripeCheckout.defaultProps = {
308
- returnUrl: ""
309
- };
@@ -18,20 +18,42 @@ export default function PaymentHeader({ checkoutSession }) {
18
18
  }
19
19
  return false;
20
20
  }, [domSize, theme]);
21
- return /* @__PURE__ */ jsxs(Stack, { className: "cko-header", direction: "row", spacing: 1, alignItems: "center", justifyContent: "space-between", children: [
22
- /* @__PURE__ */ jsxs(Stack, { direction: "row", spacing: 1, alignItems: "center", children: [
23
- /* @__PURE__ */ jsx(
24
- Avatar,
25
- {
26
- variant: "square",
27
- src: window.blocklet.appLogo,
28
- sx: { width: 32, height: 32 },
29
- alt: window.blocklet?.appName || "Logo"
30
- }
31
- ),
32
- /* @__PURE__ */ jsx(Typography, { sx: { color: "text.primary", fontWeight: 600 }, children: brand }),
33
- !livemode && /* @__PURE__ */ jsx(Livemode, {})
34
- ] }),
35
- isColumnLayout ? /* @__PURE__ */ jsx(UserButtons, {}) : null
36
- ] });
21
+ return /* @__PURE__ */ jsxs(
22
+ Stack,
23
+ {
24
+ className: "cko-header",
25
+ direction: "row",
26
+ spacing: 1,
27
+ sx: {
28
+ alignItems: "center",
29
+ justifyContent: "space-between"
30
+ },
31
+ children: [
32
+ /* @__PURE__ */ jsxs(
33
+ Stack,
34
+ {
35
+ direction: "row",
36
+ spacing: 1,
37
+ sx: {
38
+ alignItems: "center"
39
+ },
40
+ children: [
41
+ /* @__PURE__ */ jsx(
42
+ Avatar,
43
+ {
44
+ variant: "square",
45
+ src: window.blocklet.appLogo,
46
+ sx: { width: 32, height: 32 },
47
+ alt: window.blocklet?.appName || "Logo"
48
+ }
49
+ ),
50
+ /* @__PURE__ */ jsx(Typography, { sx: { color: "text.primary", fontWeight: 600 }, children: brand }),
51
+ !livemode && /* @__PURE__ */ jsx(Livemode, {})
52
+ ]
53
+ }
54
+ ),
55
+ isColumnLayout ? /* @__PURE__ */ jsx(UserButtons, {}) : null
56
+ ]
57
+ }
58
+ );
37
59
  }
@@ -6,16 +6,9 @@ type Props = CheckoutContext & CheckoutCallbacks & {
6
6
  error?: any;
7
7
  showCheckoutSummary?: boolean;
8
8
  };
9
- declare function Payment({ checkoutSession, paymentMethods, paymentIntent, paymentLink, customer, completed, error, mode, onPaid, onError, onChange, goBack, action, showCheckoutSummary, }: Props): import("react").JSX.Element;
10
- declare namespace Payment {
11
- var defaultProps: {
12
- completed: boolean;
13
- error: null;
14
- showCheckoutSummary: boolean;
15
- };
16
- }
17
- export default Payment;
9
+ export default function Payment({ checkoutSession, paymentMethods, paymentIntent, paymentLink, customer, completed, error, mode, onPaid, onError, onChange, goBack, action, showCheckoutSummary, }: Props): import("react").JSX.Element;
18
10
  type RootProps = {
19
11
  mode: LiteralUnion<'standalone' | 'inline' | 'popup', string>;
20
12
  } & BoxProps;
21
13
  export declare const Root: React.FC<RootProps>;
14
+ export {};
@@ -18,7 +18,8 @@ import {
18
18
  getQueryParams,
19
19
  getStatementDescriptor,
20
20
  isMobileSafari,
21
- isValidCountry
21
+ isValidCountry,
22
+ showStaking
22
23
  } from "../libs/util.js";
23
24
  import PaymentError from "./error.js";
24
25
  import CheckoutFooter from "./footer.js";
@@ -30,17 +31,13 @@ import PaymentSummary from "./summary.js";
30
31
  import { useMobile } from "../hooks/mobile.js";
31
32
  import { formatPhone } from "../libs/phone-validator.js";
32
33
  import { getCurrencyPreference } from "../libs/currency.js";
33
- PaymentInner.defaultProps = {
34
- completed: false,
35
- showCheckoutSummary: true
36
- };
37
34
  function PaymentInner({
38
35
  checkoutSession,
39
36
  paymentMethods,
40
37
  paymentLink,
41
38
  paymentIntent,
42
39
  customer,
43
- completed,
40
+ completed = false,
44
41
  mode,
45
42
  onPaid,
46
43
  onError,
@@ -170,6 +167,18 @@ function PaymentInner({
170
167
  Toast.error(formatError(err));
171
168
  }
172
169
  };
170
+ const onQuantityChange = async (itemId, quantity) => {
171
+ try {
172
+ const { data } = await api.put(`/api/checkout-sessions/${state.checkoutSession.id}/adjust-quantity`, {
173
+ itemId,
174
+ quantity
175
+ });
176
+ setState({ checkoutSession: data });
177
+ } catch (err) {
178
+ console.error(err);
179
+ Toast.error(formatError(err));
180
+ }
181
+ };
173
182
  const onCancelCrossSell = async () => {
174
183
  try {
175
184
  const { data } = await api.delete(`/api/checkout-sessions/${state.checkoutSession.id}/cross-sell`);
@@ -215,17 +224,19 @@ function PaymentInner({
215
224
  // @ts-ignore
216
225
  state.checkoutSession.subscription_data?.min_stake_amount || 0
217
226
  ),
218
- showStaking: method.type === "arcblock" && !state.checkoutSession.subscription_data?.no_stake,
227
+ showStaking: showStaking(method, currency, !!state.checkoutSession.subscription_data?.no_stake),
219
228
  currency,
220
229
  onUpsell,
221
230
  onDownsell,
231
+ onQuantityChange,
222
232
  onApplyCrossSell,
223
233
  onCancelCrossSell,
224
234
  onChangeAmount,
225
235
  checkoutSessionId: state.checkoutSession.id,
226
236
  crossSellBehavior: state.checkoutSession.cross_sell_behavior,
227
237
  donationSettings: paymentLink?.donation_settings,
228
- action
238
+ action,
239
+ completed
229
240
  }
230
241
  ),
231
242
  mode === "standalone" && !isMobile && /* @__PURE__ */ jsx(CheckoutFooter, { className: "cko-footer", sx: { color: "text.lighter" } })
@@ -275,19 +286,14 @@ function PaymentInner({
275
286
  mode === "standalone" && isMobile && /* @__PURE__ */ jsx(CheckoutFooter, { className: "cko-footer", sx: { color: "text.lighter" } })
276
287
  ] }) });
277
288
  }
278
- Payment.defaultProps = {
279
- completed: false,
280
- error: null,
281
- showCheckoutSummary: true
282
- };
283
289
  export default function Payment({
284
290
  checkoutSession,
285
291
  paymentMethods,
286
292
  paymentIntent,
287
293
  paymentLink,
288
294
  customer,
289
- completed,
290
- error,
295
+ completed = false,
296
+ error = null,
291
297
  mode,
292
298
  onPaid,
293
299
  onError,
@@ -366,9 +372,9 @@ export default function Payment({
366
372
  return /* @__PURE__ */ jsxs(
367
373
  Stack,
368
374
  {
369
- display: "flex",
370
- flexDirection: "column",
371
375
  sx: {
376
+ display: "flex",
377
+ flexDirection: "column",
372
378
  height: mode === "standalone" ? "100vh" : "auto",
373
379
  overflow: isMobileSafariEnv ? "visible" : "hidden"
374
380
  },
@@ -7,14 +7,5 @@ type Props = {
7
7
  extra?: React.ReactNode;
8
8
  variant?: LiteralUnion<'square' | 'rounded' | 'circular', string>;
9
9
  };
10
- declare function ProductCard({ size, variant, name, logo, description, extra }: Props): import("react").JSX.Element;
11
- declare namespace ProductCard {
12
- var defaultProps: {
13
- logo: string;
14
- size: number;
15
- description: string;
16
- variant: string;
17
- extra: undefined;
18
- };
19
- }
20
- export default ProductCard;
10
+ export default function ProductCard({ size, variant, name, logo, description, extra, }: Props): import("react").JSX.Element;
11
+ export {};