@blocklet/payment-react 1.13.133 → 1.13.135

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
1
  /// <reference types="react" />
2
2
  import { CheckoutProps } from '../types';
3
- export default function CheckoutTable({ id, onPaid, onError, mode, extraParams }: CheckoutProps): import("react").JSX.Element;
3
+ export default function CheckoutTable({ id, onPaid, onError, mode, extraParams, goBack }: CheckoutProps): import("react").JSX.Element;
@@ -15,12 +15,13 @@ const fetchData = async (id) => {
15
15
  const { data } = await api.get(`/api/pricing-tables/${id}`);
16
16
  return data;
17
17
  };
18
- export default function CheckoutTable({ id, onPaid, onError, mode, extraParams }) {
18
+ export default function CheckoutTable({ id, onPaid, onError, mode, extraParams, goBack }) {
19
19
  if (!id.startsWith("prctbl_")) {
20
20
  throw new Error("A valid pricing table id is required.");
21
21
  }
22
- const { t } = useLocaleContext();
23
22
  const [sessionId, setSessionId] = useState("");
23
+ const hashSessionId = window.location.hash.slice(1);
24
+ const { t } = useLocaleContext();
24
25
  const { error, loading, data } = useRequest(() => fetchData(id));
25
26
  if (error) {
26
27
  return /* @__PURE__ */ jsx(Alert, { severity: "error", children: error.message });
@@ -49,6 +50,7 @@ export default function CheckoutTable({ id, onPaid, onError, mode, extraParams }
49
50
  if (mode === "standalone") {
50
51
  window.location.replace(res.data.url);
51
52
  } else {
53
+ window.location.hash = res.data.id;
52
54
  setSessionId(res.data.id);
53
55
  }
54
56
  }).catch((err) => {
@@ -56,10 +58,17 @@ export default function CheckoutTable({ id, onPaid, onError, mode, extraParams }
56
58
  Toast.error(err.message);
57
59
  });
58
60
  };
59
- const goBack = () => {
60
- setSessionId("");
61
- };
62
- if (!sessionId) {
61
+ const prop = {};
62
+ if (goBack) {
63
+ prop.goBack = () => {
64
+ window.location.hash = "";
65
+ if (typeof goBack !== "undefined") {
66
+ goBack();
67
+ }
68
+ setSessionId("");
69
+ };
70
+ }
71
+ if (!sessionId && !hashSessionId) {
63
72
  if (mode === "standalone") {
64
73
  return /* @__PURE__ */ jsxs(Stack, { direction: "column", alignItems: "center", spacing: 4, children: [
65
74
  /* @__PURE__ */ jsxs(Typography, { variant: "h4", color: "text.primary", fontWeight: 600, children: [
@@ -71,5 +80,5 @@ export default function CheckoutTable({ id, onPaid, onError, mode, extraParams }
71
80
  }
72
81
  return /* @__PURE__ */ jsx(PricingTable, { mode: "select", table: data, onSelect: handleSelect });
73
82
  }
74
- return /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(CheckoutForm, { id: sessionId, onPaid, onError, mode, goBack }) });
83
+ return /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(CheckoutForm, { id: hashSessionId || sessionId, onPaid, onError, mode, ...prop }) });
75
84
  }
@@ -41,7 +41,7 @@ PricingTable.defaultProps = {
41
41
  };
42
42
  export default function PricingTable({ table, alignItems, interval, mode, onSelect }) {
43
43
  const { t, locale } = useLocaleContext();
44
- const [state, setState] = useSetState({ interval, loading: "" });
44
+ const [state, setState] = useSetState({ interval, loading: "", loaded: false });
45
45
  const { recurring, grouped } = groupItemsByRecurring(table.items);
46
46
  useEffect(() => {
47
47
  if (table) {
@@ -55,7 +55,7 @@ export default function PricingTable({ table, alignItems, interval, mode, onSele
55
55
  }, [table]);
56
56
  const handleSelect = async (priceId) => {
57
57
  try {
58
- setState({ loading: priceId });
58
+ setState({ loading: priceId, loaded: true });
59
59
  await onSelect(priceId);
60
60
  } catch (err) {
61
61
  console.error(err);
@@ -68,6 +68,17 @@ export default function PricingTable({ table, alignItems, interval, mode, onSele
68
68
  width: 90% !important;
69
69
  }
70
70
  }
71
+ @media (min-width: ${({ theme }) => theme.breakpoints.values.lg}px) {
72
+ .price-table-wrap:has(> div:nth-child(2)) {
73
+ width: 300px !important;
74
+ }
75
+ .price-table-wrap:has(> div:nth-child(2)) {
76
+ width: 600px !important;
77
+ }
78
+ .price-table-wrap:has(> div:nth-child(3)) {
79
+ width: 900px !important;
80
+ }
81
+ }
71
82
  `;
72
83
  return /* @__PURE__ */ jsx(Root, { children: /* @__PURE__ */ jsxs(
73
84
  Stack,
@@ -159,9 +170,10 @@ export default function PricingTable({ table, alignItems, interval, mode, onSele
159
170
  variant: x.is_highlight || x.is_selected ? "contained" : "outlined",
160
171
  color: x.is_highlight || x.is_selected ? "primary" : "info",
161
172
  sx: { fontSize: "1.2rem" },
162
- loading: state.loading === x.price_id,
173
+ loading: state.loading === x.price_id && !state.loaded,
163
174
  disabled: x.is_disabled,
164
175
  onClick: () => handleSelect(x.price_id),
176
+ loadingPosition: "end",
165
177
  children: action
166
178
  }
167
179
  ),
@@ -3,10 +3,11 @@ import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
3
3
  import { Box, Button, CircularProgress, Stack, Typography } from "@mui/material";
4
4
  import { fromUnitToToken } from "@ocap/util";
5
5
  import { useInfiniteScroll } from "ahooks";
6
+ import { joinURL } from "ufo";
6
7
  import api from "../../api.js";
7
8
  import TxLink from "../../components/blockchain/tx.js";
8
9
  import Status from "../../components/status.js";
9
- import { formatToDate, getPaymentIntentStatusColor } from "../../util.js";
10
+ import { formatToDate, getPaymentIntentStatusColor, getPrefix } from "../../util.js";
10
11
  const groupByDate = (items) => {
11
12
  const grouped = {};
12
13
  items.forEach((item) => {
@@ -63,6 +64,7 @@ export default function CustomerPaymentList({ customer_id }) {
63
64
  },
64
65
  flexWrap: "nowrap",
65
66
  children: [
67
+ /* @__PURE__ */ jsx(Box, { flex: 3, children: /* @__PURE__ */ jsx("a", { href: joinURL(window.location.origin, getPrefix(), `/customer/payment/${item.id}`), children: /* @__PURE__ */ jsx(Typography, { children: item.id }) }) }),
66
68
  /* @__PURE__ */ jsx(Box, { flex: 3, children: /* @__PURE__ */ jsx(Typography, { children: formatToDate(item.created_at) }) }),
67
69
  /* @__PURE__ */ jsx(Box, { flex: 2, children: /* @__PURE__ */ jsxs(Typography, { textAlign: "right", children: [
68
70
  fromUnitToToken(item.amount, item.paymentCurrency.decimal),
@@ -177,14 +177,14 @@ export function PaymentInner({
177
177
  }
178
178
  };
179
179
  return /* @__PURE__ */ jsx(FormProvider, { ...methods, children: /* @__PURE__ */ jsxs(Root, { mode, children: [
180
- mode !== "standalone" ? /* @__PURE__ */ jsx(
180
+ goBack && /* @__PURE__ */ jsx(
181
181
  ArrowBackOutlined,
182
182
  {
183
183
  sx: { mr: 0.5, color: "text.secondary", alignSelf: "flex-start", margin: "16px 0", cursor: "pointer" },
184
184
  onClick: goBack,
185
185
  fontSize: "medium"
186
186
  }
187
- ) : null,
187
+ ),
188
188
  /* @__PURE__ */ jsxs(Stack, { className: "cko-container", sx: { gap: { sm: mode === "standalone" ? 0 : 8 } }, children: [
189
189
  /* @__PURE__ */ jsx(Fade, { in: true, children: /* @__PURE__ */ jsxs(Stack, { className: "cko-overview", direction: "column", children: [
190
190
  mode === "standalone" ? /* @__PURE__ */ jsx(PaymentHeader, { checkoutSession: state.checkoutSession }) : null,
@@ -1,3 +1,3 @@
1
1
  /// <reference types="react" />
2
2
  import { CheckoutProps } from '../types';
3
- export default function CheckoutTable({ id, onPaid, onError, mode, extraParams }: CheckoutProps): import("react").JSX.Element;
3
+ export default function CheckoutTable({ id, onPaid, onError, mode, extraParams, goBack }: CheckoutProps): import("react").JSX.Element;
@@ -29,15 +29,17 @@ function CheckoutTable({
29
29
  onPaid,
30
30
  onError,
31
31
  mode,
32
- extraParams
32
+ extraParams,
33
+ goBack
33
34
  }) {
34
35
  if (!id.startsWith("prctbl_")) {
35
36
  throw new Error("A valid pricing table id is required.");
36
37
  }
38
+ const [sessionId, setSessionId] = (0, _react.useState)("");
39
+ const hashSessionId = window.location.hash.slice(1);
37
40
  const {
38
41
  t
39
42
  } = (0, _context.useLocaleContext)();
40
- const [sessionId, setSessionId] = (0, _react.useState)("");
41
43
  const {
42
44
  error,
43
45
  loading,
@@ -79,6 +81,7 @@ function CheckoutTable({
79
81
  if (mode === "standalone") {
80
82
  window.location.replace(res.data.url);
81
83
  } else {
84
+ window.location.hash = res.data.id;
82
85
  setSessionId(res.data.id);
83
86
  }
84
87
  }).catch(err => {
@@ -86,10 +89,17 @@ function CheckoutTable({
86
89
  _Toast.default.error(err.message);
87
90
  });
88
91
  };
89
- const goBack = () => {
90
- setSessionId("");
91
- };
92
- if (!sessionId) {
92
+ const prop = {};
93
+ if (goBack) {
94
+ prop.goBack = () => {
95
+ window.location.hash = "";
96
+ if (typeof goBack !== "undefined") {
97
+ goBack();
98
+ }
99
+ setSessionId("");
100
+ };
101
+ }
102
+ if (!sessionId && !hashSessionId) {
93
103
  if (mode === "standalone") {
94
104
  return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
95
105
  direction: "column",
@@ -114,11 +124,11 @@ function CheckoutTable({
114
124
  }
115
125
  return /* @__PURE__ */(0, _jsxRuntime.jsx)(_system.Box, {
116
126
  children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_form.default, {
117
- id: sessionId,
127
+ id: hashSessionId || sessionId,
118
128
  onPaid,
119
129
  onError,
120
130
  mode,
121
- goBack
131
+ ...prop
122
132
  })
123
133
  });
124
134
  }
@@ -50,7 +50,8 @@ function PricingTable({
50
50
  } = (0, _context.useLocaleContext)();
51
51
  const [state, setState] = (0, _ahooks.useSetState)({
52
52
  interval,
53
- loading: ""
53
+ loading: "",
54
+ loaded: false
54
55
  });
55
56
  const {
56
57
  recurring,
@@ -71,7 +72,8 @@ function PricingTable({
71
72
  const handleSelect = async priceId => {
72
73
  try {
73
74
  setState({
74
- loading: priceId
75
+ loading: priceId,
76
+ loaded: true
75
77
  });
76
78
  await onSelect(priceId);
77
79
  } catch (err) {
@@ -87,6 +89,19 @@ function PricingTable({
87
89
  width: 90% !important;
88
90
  }
89
91
  }
92
+ @media (min-width: ${({
93
+ theme
94
+ }) => theme.breakpoints.values.lg}px) {
95
+ .price-table-wrap:has(> div:nth-child(2)) {
96
+ width: 300px !important;
97
+ }
98
+ .price-table-wrap:has(> div:nth-child(2)) {
99
+ width: 600px !important;
100
+ }
101
+ .price-table-wrap:has(> div:nth-child(3)) {
102
+ width: 900px !important;
103
+ }
104
+ }
90
105
  `;
91
106
  return /* @__PURE__ */(0, _jsxRuntime.jsx)(Root, {
92
107
  children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
@@ -203,9 +218,10 @@ function PricingTable({
203
218
  sx: {
204
219
  fontSize: "1.2rem"
205
220
  },
206
- loading: state.loading === x.price_id,
221
+ loading: state.loading === x.price_id && !state.loaded,
207
222
  disabled: x.is_disabled,
208
223
  onClick: () => handleSelect(x.price_id),
224
+ loadingPosition: "end",
209
225
  children: action
210
226
  }), x.product.features.length > 0 && /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
211
227
  children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
@@ -9,6 +9,7 @@ var _context = require("@arcblock/ux/lib/Locale/context");
9
9
  var _material = require("@mui/material");
10
10
  var _util = require("@ocap/util");
11
11
  var _ahooks = require("ahooks");
12
+ var _ufo = require("ufo");
12
13
  var _api = _interopRequireDefault(require("../../api"));
13
14
  var _tx = _interopRequireDefault(require("../../components/blockchain/tx"));
14
15
  var _status = _interopRequireDefault(require("../../components/status"));
@@ -95,6 +96,14 @@ function CustomerPaymentList({
95
96
  },
96
97
  flexWrap: "nowrap",
97
98
  children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
99
+ flex: 3,
100
+ children: /* @__PURE__ */(0, _jsxRuntime.jsx)("a", {
101
+ href: (0, _ufo.joinURL)(window.location.origin, (0, _util2.getPrefix)(), `/customer/payment/${item.id}`),
102
+ children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
103
+ children: item.id
104
+ })
105
+ })
106
+ }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
98
107
  flex: 3,
99
108
  children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
100
109
  children: (0, _util2.formatToDate)(item.created_at)
@@ -227,7 +227,7 @@ function PaymentInner({
227
227
  ...methods,
228
228
  children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(Root, {
229
229
  mode,
230
- children: [mode !== "standalone" ? /* @__PURE__ */(0, _jsxRuntime.jsx)(_iconsMaterial.ArrowBackOutlined, {
230
+ children: [goBack && /* @__PURE__ */(0, _jsxRuntime.jsx)(_iconsMaterial.ArrowBackOutlined, {
231
231
  sx: {
232
232
  mr: 0.5,
233
233
  color: "text.secondary",
@@ -237,7 +237,7 @@ function PaymentInner({
237
237
  },
238
238
  onClick: goBack,
239
239
  fontSize: "medium"
240
- }) : null, /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
240
+ }), /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
241
241
  className: "cko-container",
242
242
  sx: {
243
243
  gap: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/payment-react",
3
- "version": "1.13.133",
3
+ "version": "1.13.135",
4
4
  "description": "Reusable react components for payment kit v2",
5
5
  "keywords": [
6
6
  "react",
@@ -89,7 +89,7 @@
89
89
  "@babel/core": "^7.19.3",
90
90
  "@babel/preset-env": "^7.19.3",
91
91
  "@babel/preset-react": "^7.18.6",
92
- "@blocklet/payment-types": "1.13.133",
92
+ "@blocklet/payment-types": "1.13.135",
93
93
  "@storybook/addon-essentials": "^7.6.10",
94
94
  "@storybook/addon-interactions": "^7.6.10",
95
95
  "@storybook/addon-links": "^7.6.10",
@@ -118,5 +118,5 @@
118
118
  "vite-plugin-babel": "^1.2.0",
119
119
  "vite-plugin-node-polyfills": "^0.19.0"
120
120
  },
121
- "gitHead": "44fb37dff90e613692afb8b4afd982f27558811f"
121
+ "gitHead": "938ddc52dccee653caa0917a65212dd5df8cadd8"
122
122
  }
@@ -19,13 +19,15 @@ const fetchData = async (id: string): Promise<TPricingTableExpanded> => {
19
19
  return data;
20
20
  };
21
21
 
22
- export default function CheckoutTable({ id, onPaid, onError, mode, extraParams }: CheckoutProps) {
22
+ export default function CheckoutTable({ id, onPaid, onError, mode, extraParams, goBack }: CheckoutProps) {
23
23
  if (!id.startsWith('prctbl_')) {
24
24
  throw new Error('A valid pricing table id is required.');
25
25
  }
26
26
 
27
- const { t } = useLocaleContext();
28
27
  const [sessionId, setSessionId] = useState('');
28
+ const hashSessionId = window.location.hash.slice(1);
29
+
30
+ const { t } = useLocaleContext();
29
31
  const { error, loading, data } = useRequest(() => fetchData(id));
30
32
 
31
33
  if (error) {
@@ -57,6 +59,7 @@ export default function CheckoutTable({ id, onPaid, onError, mode, extraParams }
57
59
  if (mode === 'standalone') {
58
60
  window.location.replace(res.data.url);
59
61
  } else {
62
+ window.location.hash = res.data.id;
60
63
  setSessionId(res.data.id);
61
64
  }
62
65
  })
@@ -66,11 +69,19 @@ export default function CheckoutTable({ id, onPaid, onError, mode, extraParams }
66
69
  });
67
70
  };
68
71
 
69
- const goBack = () => {
70
- setSessionId('');
71
- };
72
+ const prop: any = {};
73
+
74
+ if (goBack) {
75
+ prop.goBack = () => {
76
+ window.location.hash = '';
77
+ if (typeof goBack !== 'undefined') {
78
+ goBack();
79
+ }
80
+ setSessionId('');
81
+ };
82
+ }
72
83
 
73
- if (!sessionId) {
84
+ if (!sessionId && !hashSessionId) {
74
85
  if (mode === 'standalone') {
75
86
  return (
76
87
  <Stack direction="column" alignItems="center" spacing={4}>
@@ -88,7 +99,7 @@ export default function CheckoutTable({ id, onPaid, onError, mode, extraParams }
88
99
 
89
100
  return (
90
101
  <Box>
91
- <CheckoutForm id={sessionId} onPaid={onPaid} onError={onError} mode={mode} goBack={goBack} />
102
+ <CheckoutForm id={hashSessionId || sessionId} onPaid={onPaid} onError={onError} mode={mode} {...prop} />
92
103
  </Box>
93
104
  );
94
105
  }
@@ -59,7 +59,7 @@ PricingTable.defaultProps = {
59
59
 
60
60
  export default function PricingTable({ table, alignItems, interval, mode, onSelect }: Props) {
61
61
  const { t, locale } = useLocaleContext();
62
- const [state, setState] = useSetState({ interval, loading: '' });
62
+ const [state, setState] = useSetState({ interval, loading: '', loaded: false });
63
63
  const { recurring, grouped } = groupItemsByRecurring(table.items);
64
64
 
65
65
  useEffect(() => {
@@ -76,7 +76,7 @@ export default function PricingTable({ table, alignItems, interval, mode, onSele
76
76
 
77
77
  const handleSelect = async (priceId: string) => {
78
78
  try {
79
- setState({ loading: priceId });
79
+ setState({ loading: priceId, loaded: true });
80
80
  await onSelect(priceId);
81
81
  } catch (err) {
82
82
  console.error(err);
@@ -90,6 +90,17 @@ export default function PricingTable({ table, alignItems, interval, mode, onSele
90
90
  width: 90% !important;
91
91
  }
92
92
  }
93
+ @media (min-width: ${({ theme }) => theme.breakpoints.values.lg}px) {
94
+ .price-table-wrap:has(> div:nth-child(2)) {
95
+ width: 300px !important;
96
+ }
97
+ .price-table-wrap:has(> div:nth-child(2)) {
98
+ width: 600px !important;
99
+ }
100
+ .price-table-wrap:has(> div:nth-child(3)) {
101
+ width: 900px !important;
102
+ }
103
+ }
93
104
  `;
94
105
  return (
95
106
  <Root>
@@ -187,9 +198,10 @@ export default function PricingTable({ table, alignItems, interval, mode, onSele
187
198
  variant={x.is_highlight || x.is_selected ? 'contained' : 'outlined'}
188
199
  color={x.is_highlight || x.is_selected ? 'primary' : 'info'}
189
200
  sx={{ fontSize: '1.2rem' }}
190
- loading={state.loading === x.price_id}
201
+ loading={state.loading === x.price_id && !state.loaded}
191
202
  disabled={x.is_disabled}
192
- onClick={() => handleSelect(x.price_id)}>
203
+ onClick={() => handleSelect(x.price_id)}
204
+ loadingPosition="end">
193
205
  {action}
194
206
  </LoadingButton>
195
207
  {x.product.features.length > 0 && (
@@ -4,11 +4,12 @@ import type { Paginated, TPaymentIntentExpanded } from '@blocklet/payment-types'
4
4
  import { Box, Button, CircularProgress, Stack, Typography } from '@mui/material';
5
5
  import { fromUnitToToken } from '@ocap/util';
6
6
  import { useInfiniteScroll } from 'ahooks';
7
+ import { joinURL } from 'ufo';
7
8
 
8
9
  import api from '../../api';
9
10
  import TxLink from '../../components/blockchain/tx';
10
11
  import Status from '../../components/status';
11
- import { formatToDate, getPaymentIntentStatusColor } from '../../util';
12
+ import { formatToDate, getPaymentIntentStatusColor, getPrefix } from '../../util';
12
13
 
13
14
  const groupByDate = (items: TPaymentIntentExpanded[]) => {
14
15
  const grouped: { [key: string]: TPaymentIntentExpanded[] } = {};
@@ -80,6 +81,11 @@ export default function CustomerPaymentList({ customer_id }: Props) {
80
81
  md: 3,
81
82
  }}
82
83
  flexWrap="nowrap">
84
+ <Box flex={3}>
85
+ <a href={joinURL(window.location.origin, getPrefix(), `/customer/payment/${item.id}`)}>
86
+ <Typography>{item.id}</Typography>
87
+ </a>
88
+ </Box>
83
89
  <Box flex={3}>
84
90
  <Typography>{formatToDate(item.created_at)}</Typography>
85
91
  </Box>
@@ -216,13 +216,13 @@ export function PaymentInner({
216
216
  return (
217
217
  <FormProvider {...methods}>
218
218
  <Root mode={mode}>
219
- {mode !== 'standalone' ? (
219
+ {goBack && (
220
220
  <ArrowBackOutlined
221
221
  sx={{ mr: 0.5, color: 'text.secondary', alignSelf: 'flex-start', margin: '16px 0', cursor: 'pointer' }}
222
222
  onClick={goBack}
223
223
  fontSize="medium"
224
224
  />
225
- ) : null}
225
+ )}
226
226
  <Stack className="cko-container" sx={{ gap: { sm: mode === 'standalone' ? 0 : 8 } }}>
227
227
  <Fade in>
228
228
  <Stack className="cko-overview" direction="column">