@blocklet/payment-react 1.18.29 → 1.18.30

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.
@@ -9,7 +9,7 @@ import { Dialog } from "@arcblock/ux";
9
9
  import { CheckCircle as CheckCircleIcon } from "@mui/icons-material";
10
10
  import debounce from "lodash/debounce";
11
11
  import { usePaymentContext } from "../contexts/payment.js";
12
- import { formatAmount, formatError, getPrefix } from "../libs/util.js";
12
+ import { formatAmount, formatError, getPrefix, isCrossOrigin } from "../libs/util.js";
13
13
  import { useSubscription } from "../hooks/subscription.js";
14
14
  import api from "../libs/api.js";
15
15
  import LoadingButton from "./loading-button.js";
@@ -137,6 +137,7 @@ function OverdueInvoicePayment({
137
137
  saveConnect: false,
138
138
  action: "collect-batch",
139
139
  prefix: joinURL(getPrefix(), "/api/did"),
140
+ useSocket: isCrossOrigin() === false,
140
141
  extraParams,
141
142
  onSuccess: () => {
142
143
  connect.close();
@@ -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;
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 "-";
@@ -21,7 +21,8 @@ import {
21
21
  formatQuantityInventory,
22
22
  getPrefix,
23
23
  getQueryParams,
24
- getStatementDescriptor
24
+ getStatementDescriptor,
25
+ isCrossOrigin
25
26
  } from "../../libs/util.js";
26
27
  import AddressForm from "./address.js";
27
28
  import CurrencySelector from "./currency.js";
@@ -311,6 +312,7 @@ export default function PaymentForm({
311
312
  action: checkoutSession.mode,
312
313
  prefix: joinURL(getPrefix(), "/api/did"),
313
314
  saveConnect: false,
315
+ useSocket: isCrossOrigin() === false,
314
316
  extraParams: { checkoutSessionId: checkoutSession.id, sessionUserDid: session?.user?.did },
315
317
  onSuccess: async () => {
316
318
  connect.close();
@@ -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)
@@ -160,6 +160,7 @@ function OverdueInvoicePayment({
160
160
  saveConnect: false,
161
161
  action: "collect-batch",
162
162
  prefix: (0, _ufo.joinURL)((0, _util.getPrefix)(), "/api/did"),
163
+ useSocket: (0, _util.isCrossOrigin)() === false,
163
164
  extraParams,
164
165
  onSuccess: () => {
165
166
  connect.close();
@@ -627,6 +627,7 @@ function CustomerInvoiceList(props) {
627
627
  connect.open({
628
628
  action: "collect",
629
629
  saveConnect: false,
630
+ useSocket: (0, _util.isCrossOrigin)() === false,
630
631
  messages: {
631
632
  scan: "",
632
633
  title: t(`payment.customer.invoice.${action || "pay"}`),
@@ -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;
package/lib/libs/util.js CHANGED
@@ -49,6 +49,7 @@ exports.getUserProfileLink = getUserProfileLink;
49
49
  exports.getWebhookStatusColor = getWebhookStatusColor;
50
50
  exports.getWordBreakStyle = getWordBreakStyle;
51
51
  exports.hasDelegateTxHash = hasDelegateTxHash;
52
+ exports.isCrossOrigin = isCrossOrigin;
52
53
  exports.isMobileSafari = isMobileSafari;
53
54
  exports.isPaymentKitMounted = void 0;
54
55
  exports.isValidCountry = isValidCountry;
@@ -100,6 +101,16 @@ const getPrefix = () => {
100
101
  return (0, _ufo.joinURL)(baseUrl, prefix);
101
102
  };
102
103
  exports.getPrefix = getPrefix;
104
+ function isCrossOrigin() {
105
+ try {
106
+ const prefix = getPrefix();
107
+ const prefixOrigin = new URL(prefix).origin;
108
+ const currentOrigin = window.location.origin;
109
+ return prefixOrigin !== currentOrigin;
110
+ } catch (error) {
111
+ return false;
112
+ }
113
+ }
103
114
  function formatToDate(date, locale = "en", format = "YYYY-MM-DD HH:mm:ss") {
104
115
  if (!date) {
105
116
  return "-";
@@ -355,6 +355,7 @@ function PaymentForm({
355
355
  action: checkoutSession.mode,
356
356
  prefix: (0, _ufo.joinURL)((0, _util.getPrefix)(), "/api/did"),
357
357
  saveConnect: false,
358
+ useSocket: (0, _util.isCrossOrigin)() === false,
358
359
  extraParams: {
359
360
  checkoutSessionId: checkoutSession.id,
360
361
  sessionUserDid: session?.user?.did
@@ -105,9 +105,10 @@ function ProductDonation({
105
105
  if (hasPresets) {
106
106
  sortedPresets = [...presets].map(p => parseFloat(p)).sort((a, b) => a - b);
107
107
  }
108
- const minPreset = hasPresets ? sortedPresets[0] : 1;
109
- const middleIndex = Math.floor(sortedPresets.length / 2);
110
- const maxPreset = hasPresets ? sortedPresets[middleIndex] : 10;
108
+ const minPreset = hasPresets ? sortedPresets[sortedPresets.length - 1] : 1;
109
+ let maxPreset = hasPresets ? sortedPresets[sortedPresets.length - 1] * 5 : 100;
110
+ const systemMax = settings.amount.maximum ? parseFloat(settings.amount.maximum) : Infinity;
111
+ maxPreset = Math.min(maxPreset, systemMax);
111
112
  const detectPrecision = () => {
112
113
  let maxPrecision = 2;
113
114
  if (!hasPresets) return 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/payment-react",
3
- "version": "1.18.29",
3
+ "version": "1.18.30",
4
4
  "description": "Reusable react components for payment kit v2",
5
5
  "keywords": [
6
6
  "react",
@@ -54,15 +54,15 @@
54
54
  }
55
55
  },
56
56
  "dependencies": {
57
- "@arcblock/did-connect": "^2.12.70",
58
- "@arcblock/ux": "^2.12.70",
59
- "@arcblock/ws": "^1.19.19",
60
- "@blocklet/ui-react": "^2.12.70",
57
+ "@arcblock/did-connect": "^2.13.1",
58
+ "@arcblock/ux": "^2.13.1",
59
+ "@arcblock/ws": "^1.20.0",
60
+ "@blocklet/ui-react": "^2.13.1",
61
61
  "@mui/icons-material": "^5.16.6",
62
62
  "@mui/lab": "^5.0.0-alpha.173",
63
63
  "@mui/material": "^5.16.6",
64
64
  "@mui/system": "^5.16.6",
65
- "@ocap/util": "^1.19.19",
65
+ "@ocap/util": "^1.20.0",
66
66
  "@stripe/react-stripe-js": "^2.7.3",
67
67
  "@stripe/stripe-js": "^2.4.0",
68
68
  "@vitejs/plugin-legacy": "^5.4.1",
@@ -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.29",
96
+ "@blocklet/payment-types": "1.18.30",
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": "bb8d03a1da62822cbc2ae57d7c5f2912aaebc0da"
127
+ "gitHead": "ed1753c48ee405a104cd2a0cab87cccb21e70ba8"
128
128
  }
@@ -17,7 +17,7 @@ import { Dialog } from '@arcblock/ux';
17
17
  import { CheckCircle as CheckCircleIcon } from '@mui/icons-material';
18
18
  import debounce from 'lodash/debounce';
19
19
  import { usePaymentContext } from '../contexts/payment';
20
- import { formatAmount, formatError, getPrefix } from '../libs/util';
20
+ import { formatAmount, formatError, getPrefix, isCrossOrigin } from '../libs/util';
21
21
  import { useSubscription } from '../hooks/subscription';
22
22
  import api from '../libs/api';
23
23
  import LoadingButton from './loading-button';
@@ -214,6 +214,7 @@ function OverdueInvoicePayment({
214
214
  saveConnect: false,
215
215
  action: 'collect-batch',
216
216
  prefix: joinURL(getPrefix(), '/api/did'),
217
+ useSocket: isCrossOrigin() === false,
217
218
  extraParams,
218
219
  onSuccess: () => {
219
220
  connect.close();
@@ -28,6 +28,7 @@ import {
28
28
  getInvoiceDescriptionAndReason,
29
29
  getInvoiceStatusColor,
30
30
  getTxLink,
31
+ isCrossOrigin,
31
32
  } from '../../libs/util';
32
33
  import Table from '../../components/table';
33
34
  import { createLink, handleNavigation, LinkInfo } from '../../libs/navigation';
@@ -617,6 +618,7 @@ export default function CustomerInvoiceList(props: Props) {
617
618
  connect.open({
618
619
  action: 'collect',
619
620
  saveConnect: false,
621
+ useSocket: isCrossOrigin() === false,
620
622
  messages: {
621
623
  scan: '',
622
624
  title: t(`payment.customer.invoice.${action || 'pay'}`),
package/src/libs/util.ts CHANGED
@@ -61,6 +61,17 @@ export const getPrefix = (): string => {
61
61
  return joinURL(baseUrl, prefix);
62
62
  };
63
63
 
64
+ export function isCrossOrigin() {
65
+ try {
66
+ const prefix = getPrefix();
67
+ const prefixOrigin = new URL(prefix).origin;
68
+ const currentOrigin = window.location.origin;
69
+ return prefixOrigin !== currentOrigin;
70
+ } catch (error) {
71
+ return false;
72
+ }
73
+ }
74
+
64
75
  export function formatToDate(date: Date | string | number, locale = 'en', format = 'YYYY-MM-DD HH:mm:ss') {
65
76
  if (!date) {
66
77
  return '-';
@@ -32,6 +32,7 @@ import {
32
32
  getPrefix,
33
33
  getQueryParams,
34
34
  getStatementDescriptor,
35
+ isCrossOrigin,
35
36
  } from '../../libs/util';
36
37
  import type { CheckoutCallbacks, CheckoutContext } from '../../types';
37
38
  import AddressForm from './address';
@@ -426,6 +427,7 @@ export default function PaymentForm({
426
427
  action: checkoutSession.mode,
427
428
  prefix: joinURL(getPrefix(), '/api/did'),
428
429
  saveConnect: false,
430
+ useSocket: isCrossOrigin() === false,
429
431
  extraParams: { checkoutSessionId: checkoutSession.id, sessionUserDid: session?.user?.did },
430
432
  onSuccess: async () => {
431
433
  connect.close();
@@ -108,9 +108,10 @@ export default function ProductDonation({
108
108
  }
109
109
 
110
110
  // Get min and max values for random amount
111
- const minPreset = hasPresets ? sortedPresets[0] : 1;
112
- const middleIndex = Math.floor(sortedPresets.length / 2);
113
- const maxPreset = hasPresets ? sortedPresets[middleIndex] : 10;
111
+ const minPreset = hasPresets ? sortedPresets[sortedPresets.length - 1] : 1;
112
+ let maxPreset = hasPresets ? sortedPresets[sortedPresets.length - 1] * 5 : 100;
113
+ const systemMax = settings.amount.maximum ? parseFloat(settings.amount.maximum) : Infinity;
114
+ maxPreset = Math.min(maxPreset, systemMax);
114
115
 
115
116
  // Detect precision from existing presets
116
117
  const detectPrecision = () => {