@blocklet/payment-react 1.18.29 → 1.18.31

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 (49) hide show
  1. package/es/checkout/donate.js +51 -23
  2. package/es/components/country-select.js +1 -0
  3. package/es/components/over-due-invoice-payment.js +44 -5
  4. package/es/history/invoice/list.js +3 -1
  5. package/es/libs/util.d.ts +2 -0
  6. package/es/libs/util.js +25 -2
  7. package/es/locales/en.js +2 -1
  8. package/es/locales/zh.js +2 -1
  9. package/es/payment/form/currency.d.ts +1 -1
  10. package/es/payment/form/currency.js +3 -3
  11. package/es/payment/form/index.d.ts +1 -1
  12. package/es/payment/form/index.js +22 -36
  13. package/es/payment/form/stripe/form.js +4 -2
  14. package/es/payment/index.js +10 -1
  15. package/es/payment/product-donation.js +4 -3
  16. package/es/payment/success.d.ts +3 -1
  17. package/es/payment/success.js +78 -6
  18. package/lib/checkout/donate.js +19 -11
  19. package/lib/components/country-select.js +1 -0
  20. package/lib/components/over-due-invoice-payment.js +42 -3
  21. package/lib/history/invoice/list.js +1 -0
  22. package/lib/libs/util.d.ts +2 -0
  23. package/lib/libs/util.js +27 -2
  24. package/lib/locales/en.js +2 -1
  25. package/lib/locales/zh.js +2 -1
  26. package/lib/payment/form/currency.d.ts +1 -1
  27. package/lib/payment/form/currency.js +3 -3
  28. package/lib/payment/form/index.d.ts +1 -1
  29. package/lib/payment/form/index.js +21 -35
  30. package/lib/payment/form/stripe/form.js +4 -2
  31. package/lib/payment/index.js +10 -1
  32. package/lib/payment/product-donation.js +4 -3
  33. package/lib/payment/success.d.ts +3 -1
  34. package/lib/payment/success.js +68 -15
  35. package/package.json +8 -8
  36. package/src/checkout/donate.tsx +23 -5
  37. package/src/components/country-select.tsx +1 -0
  38. package/src/components/over-due-invoice-payment.tsx +47 -4
  39. package/src/history/invoice/list.tsx +2 -0
  40. package/src/libs/util.ts +28 -2
  41. package/src/locales/en.tsx +1 -0
  42. package/src/locales/zh.tsx +1 -0
  43. package/src/payment/form/currency.tsx +4 -4
  44. package/src/payment/form/index.tsx +23 -47
  45. package/src/payment/form/stripe/form.tsx +4 -2
  46. package/src/payment/index.tsx +12 -1
  47. package/src/payment/product-donation.tsx +4 -3
  48. package/src/payment/success.tsx +73 -11
  49. package/src/payment/summary.tsx +1 -0
@@ -296,17 +296,31 @@ function SupporterSimple({ supporters = [], totalAmount = "0", currency, method
296
296
  symbol: currency.symbol,
297
297
  totalAmount: formatAmount(totalAmount || "0", currency.decimal)
298
298
  }) }),
299
- /* @__PURE__ */ jsx(AvatarGroup, { total: customersNum, max: 10, children: customers.map((x) => /* @__PURE__ */ jsx(
300
- Avatar,
299
+ /* @__PURE__ */ jsx(
300
+ AvatarGroup,
301
301
  {
302
- title: x.customer?.name,
303
- alt: x.customer?.metadata?.anonymous ? "" : x.customer?.name,
304
- src: getCustomerAvatar(x.customer?.did, x?.updated_at ? new Date(x.updated_at).toISOString() : "", 48),
305
- variant: "circular",
306
- sx: { width: 24, height: 24 }
307
- },
308
- x.id
309
- )) })
302
+ total: customersNum,
303
+ max: 10,
304
+ spacing: 4,
305
+ sx: {
306
+ "& .MuiAvatar-root": {
307
+ width: 24,
308
+ height: 24,
309
+ fontSize: "0.6rem"
310
+ }
311
+ },
312
+ children: customers.map((x) => /* @__PURE__ */ jsx(
313
+ Avatar,
314
+ {
315
+ title: x.customer?.name,
316
+ alt: x.customer?.metadata?.anonymous ? "" : x.customer?.name,
317
+ src: getCustomerAvatar(x.customer?.did, x?.updated_at ? new Date(x.updated_at).toISOString() : "", 48),
318
+ variant: "circular"
319
+ },
320
+ x.id
321
+ ))
322
+ }
323
+ )
310
324
  ]
311
325
  }
312
326
  );
@@ -593,20 +607,34 @@ function CheckoutDonateInner({
593
607
  ] }),
594
608
  maxWidth: "md",
595
609
  toolbar: isMobile ? null : /* @__PURE__ */ jsxs(Box, { display: "flex", alignItems: "center", gap: 1, sx: { color: "text.secondary" }, children: [
596
- /* @__PURE__ */ jsx(AvatarGroup, { total: customers?.length, max: 5, children: customers.map((x) => /* @__PURE__ */ jsx(
597
- Avatar,
610
+ /* @__PURE__ */ jsx(
611
+ AvatarGroup,
598
612
  {
599
- title: x.customer?.name,
600
- src: getCustomerAvatar(
601
- x.customer?.did,
602
- x?.updated_at ? new Date(x.updated_at).toISOString() : "",
603
- 18
604
- ),
605
- variant: "circular",
606
- sx: { width: 18, height: 18 }
607
- },
608
- x.id
609
- )) }),
613
+ total: customers?.length,
614
+ max: 5,
615
+ spacing: 4,
616
+ sx: {
617
+ "& .MuiAvatar-root": {
618
+ width: 18,
619
+ height: 18,
620
+ fontSize: "0.6rem"
621
+ }
622
+ },
623
+ children: customers.map((x) => /* @__PURE__ */ jsx(
624
+ Avatar,
625
+ {
626
+ title: x.customer?.name,
627
+ src: getCustomerAvatar(
628
+ x.customer?.did,
629
+ x?.updated_at ? new Date(x.updated_at).toISOString() : "",
630
+ 24
631
+ ),
632
+ variant: "circular"
633
+ },
634
+ x.id
635
+ ))
636
+ }
637
+ ),
610
638
  customers?.length > 0 && t("payment.checkout.donation.gaveTips", { count: customers?.length })
611
639
  ] }),
612
640
  showCloseButton: false,
@@ -194,6 +194,7 @@ const CountrySelect = forwardRef(({ value, onChange, name, sx }, ref) => {
194
194
  },
195
195
  sx: {
196
196
  width: "100%",
197
+ minWidth: "60px",
197
198
  fieldset: {
198
199
  display: "none"
199
200
  },
@@ -1,15 +1,16 @@
1
1
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
- import { useEffect, useMemo, useState } from "react";
2
+ import { useEffect, useMemo, useRef, useState } from "react";
3
3
  import { Button, Typography, Stack, Alert } from "@mui/material";
4
4
  import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
5
5
  import Toast from "@arcblock/ux/lib/Toast";
6
6
  import { joinURL } from "ufo";
7
7
  import { useRequest } from "ahooks";
8
+ import pWaitFor from "p-wait-for";
8
9
  import { Dialog } from "@arcblock/ux";
9
10
  import { CheckCircle as CheckCircleIcon } from "@mui/icons-material";
10
11
  import debounce from "lodash/debounce";
11
12
  import { usePaymentContext } from "../contexts/payment.js";
12
- import { formatAmount, formatError, getPrefix } from "../libs/util.js";
13
+ import { formatAmount, formatError, getPrefix, isCrossOrigin } from "../libs/util.js";
13
14
  import { useSubscription } from "../hooks/subscription.js";
14
15
  import api from "../libs/api.js";
15
16
  import LoadingButton from "./loading-button.js";
@@ -49,6 +50,7 @@ function OverdueInvoicePayment({
49
50
  const sourceType = subscriptionId ? "subscription" : "customer";
50
51
  const effectiveCustomerId = customerId || session?.user?.did;
51
52
  const sourceId = subscriptionId || effectiveCustomerId;
53
+ const customerIdRef = useRef(effectiveCustomerId);
52
54
  const {
53
55
  data = {
54
56
  summary: {},
@@ -58,7 +60,12 @@ function OverdueInvoicePayment({
58
60
  loading,
59
61
  runAsync: refresh
60
62
  } = useRequest(() => fetchOverdueInvoices({ subscriptionId, customerId: effectiveCustomerId, authToken }), {
61
- ready: !!subscriptionId || !!effectiveCustomerId
63
+ ready: !!subscriptionId || !!effectiveCustomerId,
64
+ onSuccess: (res) => {
65
+ if (res.customer?.id && res.customer?.id !== customerIdRef.current) {
66
+ customerIdRef.current = res.customer?.id;
67
+ }
68
+ }
62
69
  });
63
70
  const detailUrl = useMemo(() => {
64
71
  if (subscriptionId) {
@@ -95,13 +102,43 @@ function OverdueInvoicePayment({
95
102
  maxWait: 5e3
96
103
  }
97
104
  );
105
+ const isCrossOriginRequest = isCrossOrigin();
98
106
  const subscription = useSubscription("events");
107
+ const waitForInvoiceAllPaid = async () => {
108
+ let isPaid = false;
109
+ await pWaitFor(
110
+ async () => {
111
+ const res = await refresh();
112
+ isPaid = res.invoices?.length === 0;
113
+ return isPaid;
114
+ },
115
+ { interval: 2e3, timeout: 3 * 60 * 1e3 }
116
+ );
117
+ return isPaid;
118
+ };
119
+ const handleConnected = async () => {
120
+ if (isCrossOriginRequest) {
121
+ try {
122
+ const paid = await waitForInvoiceAllPaid();
123
+ if (successToast) {
124
+ Toast.close();
125
+ Toast.success(t("payment.customer.invoice.paySuccess"));
126
+ }
127
+ if (paid) {
128
+ setDialogOpen(false);
129
+ onPaid(sourceId, selectCurrencyId, sourceType);
130
+ }
131
+ } catch (err) {
132
+ console.error("Check payment status failed:", err);
133
+ }
134
+ }
135
+ };
99
136
  useEffect(() => {
100
- if (subscription) {
137
+ if (subscription && !isCrossOriginRequest) {
101
138
  subscription.on("invoice.paid", ({ response }) => {
102
139
  const relevantId = subscriptionId || response.customer_id;
103
140
  const uniqueKey = `${relevantId}-${response.currency_id}`;
104
- if (subscriptionId && response.subscription_id === subscriptionId || effectiveCustomerId && [data.customer?.id, effectiveCustomerId].includes(response.customer_id)) {
141
+ if (subscriptionId && response.subscription_id === subscriptionId || effectiveCustomerId && effectiveCustomerId === response.customer_id || customerIdRef.current && customerIdRef.current === response.customer_id) {
105
142
  if (!processedCurrencies[uniqueKey]) {
106
143
  setProcessedCurrencies((prev) => ({ ...prev, [uniqueKey]: 1 }));
107
144
  debouncedHandleInvoicePaid(response.currency_id);
@@ -137,9 +174,11 @@ function OverdueInvoicePayment({
137
174
  saveConnect: false,
138
175
  action: "collect-batch",
139
176
  prefix: joinURL(getPrefix(), "/api/did"),
177
+ useSocket: !isCrossOriginRequest,
140
178
  extraParams,
141
179
  onSuccess: () => {
142
180
  connect.close();
181
+ handleConnected();
143
182
  setPayLoading(false);
144
183
  setPaymentStatus((prev) => ({
145
184
  ...prev,
@@ -19,7 +19,8 @@ import {
19
19
  formatToDatetime,
20
20
  getInvoiceDescriptionAndReason,
21
21
  getInvoiceStatusColor,
22
- getTxLink
22
+ getTxLink,
23
+ isCrossOrigin
23
24
  } from "../../libs/util.js";
24
25
  import Table from "../../components/table.js";
25
26
  import { createLink, handleNavigation } from "../../libs/navigation.js";
@@ -479,6 +480,7 @@ export default function CustomerInvoiceList(props) {
479
480
  connect.open({
480
481
  action: "collect",
481
482
  saveConnect: false,
483
+ useSocket: isCrossOrigin() === false,
482
484
  messages: {
483
485
  scan: "",
484
486
  title: t(`payment.customer.invoice.${action || "pay"}`),
package/es/libs/util.d.ts CHANGED
@@ -3,6 +3,7 @@ import type { ActionProps, PricingRenderProps } from '../types';
3
3
  export declare const PAYMENT_KIT_DID = "z2qaCNvKMv5GjouKdcDWexv6WqtHbpNPQDnAk";
4
4
  export declare const isPaymentKitMounted: () => any;
5
5
  export declare const getPrefix: () => string;
6
+ export declare function isCrossOrigin(): boolean;
6
7
  export declare function formatToDate(date: Date | string | number, locale?: string, format?: string): any;
7
8
  export declare function formatToDatetime(date: Date | string | number, locale?: string): any;
8
9
  export declare function formatTime(date: Date | string | number, format?: string, locale?: string): any;
@@ -49,6 +50,7 @@ export declare function formatPriceDisplay({ amount, then, actualAmount, showThe
49
50
  actualAmount: string;
50
51
  showThen?: boolean;
51
52
  }, recurring: string, hasMetered: boolean, locale?: string): string;
53
+ export declare function hasMultipleRecurringIntervals(items: TLineItemExpanded[]): boolean;
52
54
  export declare function getFreeTrialTime({ trialInDays, trialEnd }: {
53
55
  trialInDays: number;
54
56
  trialEnd: number;
package/es/libs/util.js CHANGED
@@ -36,6 +36,16 @@ export const getPrefix = () => {
36
36
  }
37
37
  return joinURL(baseUrl, prefix);
38
38
  };
39
+ export function isCrossOrigin() {
40
+ try {
41
+ const prefix = getPrefix();
42
+ const prefixOrigin = new URL(prefix).origin;
43
+ const currentOrigin = window.location.origin;
44
+ return prefixOrigin !== currentOrigin;
45
+ } catch (error) {
46
+ return false;
47
+ }
48
+ }
39
49
  export function formatToDate(date, locale = "en", format = "YYYY-MM-DD HH:mm:ss") {
40
50
  if (!date) {
41
51
  return "-";
@@ -429,6 +439,18 @@ export function formatPriceDisplay({ amount, then, actualAmount, showThen }, rec
429
439
  }
430
440
  return [amount, then].filter(Boolean).join(" ");
431
441
  }
442
+ export function hasMultipleRecurringIntervals(items) {
443
+ const intervals = /* @__PURE__ */ new Set();
444
+ for (const item of items) {
445
+ if (item.price?.recurring?.interval && item.price?.type === "recurring") {
446
+ intervals.add(`${item.price.recurring.interval}-${item.price.recurring.interval_count}`);
447
+ if (intervals.size > 1) {
448
+ return true;
449
+ }
450
+ }
451
+ }
452
+ return false;
453
+ }
432
454
  export function getFreeTrialTime({ trialInDays, trialEnd }, locale = "en") {
433
455
  const now = dayjs().unix();
434
456
  if (trialEnd > 0 && trialEnd > now) {
@@ -491,6 +513,7 @@ export function formatCheckoutHeadlines(items, currency, { trialInDays, trialEnd
491
513
  locale
492
514
  );
493
515
  const hasMetered = items.some((x) => x.price.type === "recurring" && x.price.recurring?.usage_type === "metered");
516
+ const differentRecurring = hasMultipleRecurringIntervals(items);
494
517
  if (items.every((x) => x.price.type === "recurring")) {
495
518
  const subscription2 = [
496
519
  hasMetered ? t("payment.checkout.least", locale) : "",
@@ -550,7 +573,7 @@ export function formatCheckoutHeadlines(items, currency, { trialInDays, trialEnd
550
573
  action: t("payment.checkout.sub1", locale, { name }),
551
574
  amount,
552
575
  then: hasMetered ? t("payment.checkout.meteredThen", locale, { recurring }) : recurring,
553
- showThen: hasMetered,
576
+ showThen: hasMetered && !differentRecurring,
554
577
  actualAmount
555
578
  };
556
579
  return {
@@ -576,7 +599,7 @@ export function formatCheckoutHeadlines(items, currency, { trialInDays, trialEnd
576
599
  hasMetered && Number(subscription) === 0,
577
600
  locale
578
601
  ),
579
- showThen: true,
602
+ showThen: !differentRecurring,
580
603
  actualAmount
581
604
  };
582
605
  return {
package/es/locales/en.js CHANGED
@@ -115,7 +115,8 @@ export default flat({
115
115
  login: "Login to load and save contact information",
116
116
  next: {
117
117
  subscription: "View subscription",
118
- invoice: "View invoice"
118
+ invoice: "View invoice",
119
+ view: "View"
119
120
  },
120
121
  paymentRequired: "Payment Required",
121
122
  staking: {
package/es/locales/zh.js CHANGED
@@ -115,7 +115,8 @@ export default flat({
115
115
  login: "\u767B\u5F55\u4EE5\u52A0\u8F7D\u5E76\u4FDD\u5B58\u8054\u7CFB\u4FE1\u606F",
116
116
  next: {
117
117
  subscription: "\u67E5\u770B\u8BA2\u9605",
118
- invoice: "\u67E5\u770B\u8D26\u5355"
118
+ invoice: "\u67E5\u770B\u8D26\u5355",
119
+ view: "\u67E5\u770B"
119
120
  },
120
121
  paymentRequired: "\u652F\u4ED8\u91D1\u989D",
121
122
  staking: {
@@ -1,6 +1,6 @@
1
1
  import type { TPaymentCurrency } from '@blocklet/payment-types';
2
2
  type Props = {
3
- value: number;
3
+ value: string;
4
4
  currencies: TPaymentCurrency[];
5
5
  onChange: Function;
6
6
  };
@@ -12,13 +12,13 @@ export default function CurrencySelector({ value, currencies, onChange }) {
12
12
  gap: 12,
13
13
  gridTemplateColumns: "repeat(auto-fit, minmax(220px, 1fr))"
14
14
  },
15
- children: currencies.map((x, i) => {
16
- const selected = i === value;
15
+ children: currencies.map((x) => {
16
+ const selected = x.id === value;
17
17
  return /* @__PURE__ */ jsx(
18
18
  Card,
19
19
  {
20
20
  variant: "outlined",
21
- onClick: () => onChange(i),
21
+ onClick: () => onChange(x.id, x.method?.id),
22
22
  className: selected ? "cko-payment-card" : "cko-payment-card-unselect",
23
23
  children: /* @__PURE__ */ jsxs(Stack, { direction: "row", alignItems: "center", sx: { position: "relative" }, children: [
24
24
  /* @__PURE__ */ jsx(Avatar, { src: x.logo, alt: x.name, sx: { width: 40, height: 40, marginRight: "12px" } }),
@@ -6,7 +6,7 @@ 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, currencyId, onlyShowBtn, isDonation, }: PageData): import("react").JSX.Element;
9
+ declare function PaymentForm({ checkoutSession, paymentMethods, paymentIntent, paymentLink, customer, onPaid, onError, action, onlyShowBtn, isDonation, }: PageData): import("react").JSX.Element;
10
10
  declare namespace PaymentForm {
11
11
  var defaultProps: {
12
12
  onlyShowBtn: boolean;
@@ -5,7 +5,7 @@ import Toast from "@arcblock/ux/lib/Toast";
5
5
  import { Box, Button, CircularProgress, Divider, Fade, FormLabel, Stack, Typography } from "@mui/material";
6
6
  import { useMemoizedFn, useSetState } from "ahooks";
7
7
  import pWaitFor from "p-wait-for";
8
- import { useEffect, useMemo, useRef, useState } from "react";
8
+ import { useEffect, useMemo, useRef } from "react";
9
9
  import { Controller, useFormContext, useWatch } from "react-hook-form";
10
10
  import { joinURL } from "ufo";
11
11
  import { dispatch } from "use-bus";
@@ -20,8 +20,8 @@ import {
20
20
  formatError,
21
21
  formatQuantityInventory,
22
22
  getPrefix,
23
- getQueryParams,
24
- getStatementDescriptor
23
+ getStatementDescriptor,
24
+ isCrossOrigin
25
25
  } from "../../libs/util.js";
26
26
  import AddressForm from "./address.js";
27
27
  import CurrencySelector from "./currency.js";
@@ -93,7 +93,6 @@ export default function PaymentForm({
93
93
  onError,
94
94
  // mode,
95
95
  action,
96
- currencyId,
97
96
  onlyShowBtn,
98
97
  isDonation = false
99
98
  }) {
@@ -130,33 +129,14 @@ export default function PaymentForm({
130
129
  stripePaying: false
131
130
  });
132
131
  const currencies = flattenPaymentMethods(paymentMethods);
133
- const [paymentCurrencyIndex, setPaymentCurrencyIndex] = useState(() => {
134
- const query = getQueryParams(window.location.href);
135
- const queryCurrencyId = query.currencyId || currencyId;
136
- const index = currencies.findIndex((x) => x.id === queryCurrencyId);
137
- return index >= 0 ? index : 0;
138
- });
139
- const handleCurrencyChange = (index) => {
140
- setPaymentCurrencyIndex(index);
141
- const selectedCurrencyId = currencies[index]?.id;
142
- if (selectedCurrencyId) {
143
- saveCurrencyPreference(selectedCurrencyId, session?.user?.did);
144
- }
145
- };
146
132
  const onCheckoutComplete = useMemoizedFn(async ({ response }) => {
147
133
  if (response.id === checkoutSession.id && state.paid === false) {
148
134
  await handleConnected();
149
135
  }
150
136
  });
151
- const onInvoicePaid = useMemoizedFn(async ({ response }) => {
152
- if (response.customer_id === customer?.id && state.customerLimited) {
153
- await onAction();
154
- }
155
- });
156
137
  useEffect(() => {
157
138
  if (subscription) {
158
139
  subscription.on("checkout.session.completed", onCheckoutComplete);
159
- subscription.on("invoice.paid", onInvoicePaid);
160
140
  }
161
141
  }, [subscription]);
162
142
  const mergeUserInfo = (customerInfo, userInfo) => {
@@ -223,10 +203,6 @@ export default function PaymentForm({
223
203
  };
224
204
  initUserInfo();
225
205
  }, [session?.user, checkoutSession.phone_number_collection?.enabled]);
226
- useEffect(() => {
227
- setValue("payment_method", currencies[paymentCurrencyIndex]?.method?.id);
228
- setValue("payment_currency", currencies[paymentCurrencyIndex]?.id);
229
- }, [paymentCurrencyIndex, currencies, setValue]);
230
206
  const paymentMethod = useWatch({ control, name: "payment_method" });
231
207
  const afterUserLoggedIn = useMemoizedFn(() => {
232
208
  if (hasDidWallet(session.user) || skipBindWallet) {
@@ -311,6 +287,7 @@ export default function PaymentForm({
311
287
  action: checkoutSession.mode,
312
288
  prefix: joinURL(getPrefix(), "/api/did"),
313
289
  saveConnect: false,
290
+ useSocket: isCrossOrigin() === false,
314
291
  extraParams: { checkoutSessionId: checkoutSession.id, sessionUserDid: session?.user?.did },
315
292
  onSuccess: async () => {
316
293
  connect.close();
@@ -324,6 +301,11 @@ export default function PaymentForm({
324
301
  console.error(err);
325
302
  setState({ submitting: false, paying: false });
326
303
  onError(err);
304
+ },
305
+ messages: {
306
+ title: "DID Connect",
307
+ scan: "Use following methods to complete this payment",
308
+ confirm: "Confirm"
327
309
  }
328
310
  });
329
311
  }
@@ -371,13 +353,13 @@ export default function PaymentForm({
371
353
  }
372
354
  if (hasDidWallet(session.user)) {
373
355
  handleSubmit(onFormSubmit, onFormError)();
374
- } else {
375
- session.bindWallet(() => {
376
- setTimeout(() => {
377
- handleSubmit(onFormSubmit, onFormError)();
378
- }, 2e3);
379
- });
356
+ return;
380
357
  }
358
+ session.bindWallet(() => {
359
+ setTimeout(() => {
360
+ handleSubmit(onFormSubmit, onFormError)();
361
+ }, 2e3);
362
+ });
381
363
  } else {
382
364
  if (isDonationMode) {
383
365
  handleSubmit(onFormSubmit, onFormError)();
@@ -489,12 +471,16 @@ export default function PaymentForm({
489
471
  {
490
472
  name: "payment_currency",
491
473
  control,
492
- render: () => /* @__PURE__ */ jsx(
474
+ render: ({ field }) => /* @__PURE__ */ jsx(
493
475
  CurrencySelector,
494
476
  {
495
- value: paymentCurrencyIndex,
477
+ value: field.value,
496
478
  currencies,
497
- onChange: handleCurrencyChange
479
+ onChange: (id, methodId) => {
480
+ field.onChange(id);
481
+ setValue("payment_method", methodId);
482
+ saveCurrencyPreference(id, session?.user?.did);
483
+ }
498
484
  }
499
485
  )
500
486
  }
@@ -144,11 +144,13 @@ function StripeCheckoutForm({
144
144
  // eslint-disable-line
145
145
  );
146
146
  return /* @__PURE__ */ jsxs(Content, { onSubmit: handleSubmit, children: [
147
- (!state.paymentMethod || state.paymentMethod === "card") && /* @__PURE__ */ jsx(
147
+ (!state.paymentMethod || ["link", "card"].includes(state.paymentMethod)) && /* @__PURE__ */ jsx(
148
148
  LinkAuthenticationElement,
149
149
  {
150
150
  options: {
151
- defaultEmail: customer.email
151
+ defaultValues: {
152
+ email: customer.email
153
+ }
152
154
  }
153
155
  }
154
156
  ),
@@ -108,6 +108,14 @@ function PaymentInner({
108
108
  )
109
109
  }
110
110
  });
111
+ useEffect(() => {
112
+ if (defaultCurrencyId) {
113
+ methods.setValue("payment_currency", defaultCurrencyId);
114
+ }
115
+ if (defaultMethodId) {
116
+ methods.setValue("payment_method", defaultMethodId);
117
+ }
118
+ }, [defaultCurrencyId, defaultMethodId]);
111
119
  useEffect(() => {
112
120
  if (!isMobileSafari()) {
113
121
  return () => {
@@ -207,7 +215,7 @@ function PaymentInner({
207
215
  // @ts-ignore
208
216
  state.checkoutSession.subscription_data?.min_stake_amount || 0
209
217
  ),
210
- showStaking: method.type === "arcblock",
218
+ showStaking: method.type === "arcblock" && !state.checkoutSession.subscription_data?.no_stake,
211
219
  currency,
212
220
  onUpsell,
213
221
  onDownsell,
@@ -240,6 +248,7 @@ function PaymentInner({
240
248
  action: state.checkoutSession.mode,
241
249
  invoiceId: state.checkoutSession.invoice_id,
242
250
  subscriptionId: state.checkoutSession.subscription_id,
251
+ subscriptions: state.checkoutSession.subscriptions,
243
252
  message: paymentLink?.after_completion?.hosted_confirmation?.custom_message || t(
244
253
  `payment.checkout.completed.${state.checkoutSession.submit_type === "donate" ? "donate" : state.checkoutSession.mode}`
245
254
  )
@@ -85,9 +85,10 @@ export default function ProductDonation({
85
85
  if (hasPresets) {
86
86
  sortedPresets = [...presets].map((p) => parseFloat(p)).sort((a, b) => a - b);
87
87
  }
88
- const minPreset = hasPresets ? sortedPresets[0] : 1;
89
- const middleIndex = Math.floor(sortedPresets.length / 2);
90
- const maxPreset = hasPresets ? sortedPresets[middleIndex] : 10;
88
+ const minPreset = hasPresets ? sortedPresets[sortedPresets.length - 1] : 1;
89
+ let maxPreset = hasPresets ? sortedPresets[sortedPresets.length - 1] * 5 : 100;
90
+ const systemMax = settings.amount.maximum ? parseFloat(settings.amount.maximum) : Infinity;
91
+ maxPreset = Math.min(maxPreset, systemMax);
91
92
  const detectPrecision = () => {
92
93
  let maxPrecision = 2;
93
94
  if (!hasPresets)
@@ -5,12 +5,14 @@ type Props = {
5
5
  payee: string;
6
6
  invoiceId?: string;
7
7
  subscriptionId?: string;
8
+ subscriptions?: any[];
8
9
  };
9
- declare function PaymentSuccess({ mode, message, action, payee, invoiceId, subscriptionId }: Props): import("react").JSX.Element;
10
+ declare function PaymentSuccess({ mode, message, action, payee, invoiceId, subscriptionId, subscriptions, }: Props): import("react").JSX.Element;
10
11
  declare namespace PaymentSuccess {
11
12
  var defaultProps: {
12
13
  invoiceId: string;
13
14
  subscriptionId: string;
15
+ subscriptions: never[];
14
16
  };
15
17
  }
16
18
  export default PaymentSuccess;