@blocklet/payment-react 1.13.255 → 1.13.257

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.
@@ -82,7 +82,7 @@ function SupporterAvatar({ supporters = [], total = 0, currency, method }) {
82
82
  }
83
83
  function SupporterTable({ supporters = [], total = 0, currency, method }) {
84
84
  const { t } = useLocaleContext();
85
- return /* @__PURE__ */ jsxs(Box, { display: "flex", flexDirection: "column", alignItems: "center", sx: { width: "100%" }, gap: { xs: 0.5, sm: 1 }, children: [
85
+ return /* @__PURE__ */ jsxs(Box, { display: "flex", flexDirection: "column", alignItems: "center", gap: { xs: 0.5, sm: 1 }, children: [
86
86
  /* @__PURE__ */ jsx(Typography, { component: "p", color: "text.secondary", children: t("payment.checkout.donation.summary", { total }) }),
87
87
  /* @__PURE__ */ jsx(Table, { size: "small", sx: { width: "100%", overflow: "hidden" }, children: /* @__PURE__ */ jsx(TableBody, { children: supporters.map((x) => /* @__PURE__ */ jsxs(
88
88
  TableRow,
@@ -92,6 +92,9 @@ function SupporterTable({ supporters = [], total = 0, currency, method }) {
92
92
  padding: "8px 16px 8px 0",
93
93
  borderTop: "1px solid #e0e0e0",
94
94
  borderBottom: "1px solid #e0e0e0"
95
+ },
96
+ "> td:last-of-type": {
97
+ paddingRight: "0"
95
98
  }
96
99
  },
97
100
  children: [
@@ -2,6 +2,7 @@ import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
3
3
  import { OpenInNewOutlined } from "@mui/icons-material";
4
4
  import { Link, Stack, Typography } from "@mui/material";
5
+ import { styled } from "@mui/system";
5
6
  import { getTxLink } from "../../libs/util.js";
6
7
  TxLink.defaultProps = {
7
8
  mode: "dashboard",
@@ -15,15 +16,14 @@ export default function TxLink(props) {
15
16
  const { text, link } = getTxLink(props.method, props.details);
16
17
  if (link) {
17
18
  return /* @__PURE__ */ jsx(Link, { href: link, target: "_blank", rel: "noopener noreferrer", children: /* @__PURE__ */ jsxs(
18
- Stack,
19
+ Root,
19
20
  {
20
- component: "span",
21
21
  direction: "row",
22
22
  alignItems: "center",
23
23
  justifyContent: props.align === "left" ? "flex-start" : "flex-end",
24
24
  spacing: 1,
25
25
  children: [
26
- /* @__PURE__ */ jsx(Typography, { component: "span", color: "primary", children: text.length > 40 ? [text.slice(0, 8), text.slice(-8)].join("...") : text }),
26
+ /* @__PURE__ */ jsx(Typography, { component: "span", color: "primary", children: text.length > 40 ? [text.slice(0, 6), text.slice(-6)].join("...") : text }),
27
27
  /* @__PURE__ */ jsx(OpenInNewOutlined, { fontSize: "small" })
28
28
  ]
29
29
  }
@@ -31,3 +31,10 @@ export default function TxLink(props) {
31
31
  }
32
32
  return /* @__PURE__ */ jsx(Typography, { component: "small", color: "text.secondary", children: t("common.none") });
33
33
  }
34
+ const Root = styled(Stack)`
35
+ @media (max-width: 600px) {
36
+ svg.MuiSvgIcon-root {
37
+ display: none !important;
38
+ }
39
+ }
40
+ `;
@@ -209,6 +209,9 @@ const Root = styled(Stack)`
209
209
  .invoice-description {
210
210
  display: none !important;
211
211
  }
212
+ svg.MuiSvgIcon-root {
213
+ display: none !important;
214
+ }
212
215
  }
213
216
 
214
217
  a.MuiButton-root {
@@ -39,7 +39,7 @@ export function useSubscription(channel) {
39
39
  } else {
40
40
  needSubscription = true;
41
41
  }
42
- if (needSubscription) {
42
+ if (needSubscription && socket.current) {
43
43
  subscription.current = socket.current.subscribe(getRelayChannel(channel));
44
44
  subscription.current.channel = channel;
45
45
  }
package/es/index.d.ts CHANGED
@@ -11,7 +11,6 @@ import SafeGuard from './components/safe-guard';
11
11
  import Status from './components/status';
12
12
  import Switch from './components/switch-button';
13
13
  import CustomerInvoiceList from './history/invoice/list';
14
- import MiniInvoiceList from './history/mini-invoice/list';
15
14
  import CustomerPaymentList from './history/payment/list';
16
15
  import api from './libs/api';
17
16
  import dayjs from './libs/dayjs';
@@ -24,7 +23,8 @@ import Payment from './payment/index';
24
23
  import ProductSkeleton from './payment/product-skeleton';
25
24
  import PaymentSummary from './payment/summary';
26
25
  export * from './libs/util';
26
+ export * from './libs/connect';
27
27
  export * from './contexts/payment';
28
28
  export * from './hooks/subscription';
29
29
  export { translations, createTranslator } from './locales';
30
- export { api, dayjs, FormInput, PhoneInput, AddressForm, StripeForm, Status, Livemode, Switch, ConfirmDialog, CheckoutForm, CheckoutTable, CheckoutDonate, CurrencySelector, Payment, PaymentSummary, PricingTable, ProductSkeleton, Amount, CustomerInvoiceList, CustomerPaymentList, MiniInvoiceList, TxLink, TxGas, SafeGuard, };
30
+ export { api, dayjs, FormInput, PhoneInput, AddressForm, StripeForm, Status, Livemode, Switch, ConfirmDialog, CheckoutForm, CheckoutTable, CheckoutDonate, CurrencySelector, Payment, PaymentSummary, PricingTable, ProductSkeleton, Amount, CustomerInvoiceList, CustomerPaymentList, TxLink, TxGas, SafeGuard, };
package/es/index.js CHANGED
@@ -11,7 +11,6 @@ import SafeGuard from "./components/safe-guard.js";
11
11
  import Status from "./components/status.js";
12
12
  import Switch from "./components/switch-button.js";
13
13
  import CustomerInvoiceList from "./history/invoice/list.js";
14
- import MiniInvoiceList from "./history/mini-invoice/list.js";
15
14
  import CustomerPaymentList from "./history/payment/list.js";
16
15
  import api from "./libs/api.js";
17
16
  import dayjs from "./libs/dayjs.js";
@@ -24,6 +23,7 @@ import Payment from "./payment/index.js";
24
23
  import ProductSkeleton from "./payment/product-skeleton.js";
25
24
  import PaymentSummary from "./payment/summary.js";
26
25
  export * from "./libs/util.js";
26
+ export * from "./libs/connect.js";
27
27
  export * from "./contexts/payment.js";
28
28
  export * from "./hooks/subscription.js";
29
29
  export { translations, createTranslator } from "./locales/index.js";
@@ -49,7 +49,6 @@ export {
49
49
  Amount,
50
50
  CustomerInvoiceList,
51
51
  CustomerPaymentList,
52
- MiniInvoiceList,
53
52
  TxLink,
54
53
  TxGas,
55
54
  SafeGuard
@@ -102,9 +102,6 @@ function SupporterTable({
102
102
  display: "flex",
103
103
  flexDirection: "column",
104
104
  alignItems: "center",
105
- sx: {
106
- width: "100%"
107
- },
108
105
  gap: {
109
106
  xs: 0.5,
110
107
  sm: 1
@@ -128,6 +125,9 @@ function SupporterTable({
128
125
  padding: "8px 16px 8px 0",
129
126
  borderTop: "1px solid #e0e0e0",
130
127
  borderBottom: "1px solid #e0e0e0"
128
+ },
129
+ "> td:last-of-type": {
130
+ paddingRight: "0"
131
131
  }
132
132
  },
133
133
  children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.TableCell, {
@@ -8,6 +8,7 @@ var _jsxRuntime = require("react/jsx-runtime");
8
8
  var _context = require("@arcblock/ux/lib/Locale/context");
9
9
  var _iconsMaterial = require("@mui/icons-material");
10
10
  var _material = require("@mui/material");
11
+ var _system = require("@mui/system");
11
12
  var _util = require("../../libs/util");
12
13
  TxLink.defaultProps = {
13
14
  mode: "dashboard",
@@ -33,8 +34,7 @@ function TxLink(props) {
33
34
  href: link,
34
35
  target: "_blank",
35
36
  rel: "noopener noreferrer",
36
- children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
37
- component: "span",
37
+ children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(Root, {
38
38
  direction: "row",
39
39
  alignItems: "center",
40
40
  justifyContent: props.align === "left" ? "flex-start" : "flex-end",
@@ -42,7 +42,7 @@ function TxLink(props) {
42
42
  children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
43
43
  component: "span",
44
44
  color: "primary",
45
- children: text.length > 40 ? [text.slice(0, 8), text.slice(-8)].join("...") : text
45
+ children: text.length > 40 ? [text.slice(0, 6), text.slice(-6)].join("...") : text
46
46
  }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_iconsMaterial.OpenInNewOutlined, {
47
47
  fontSize: "small"
48
48
  })]
@@ -54,4 +54,11 @@ function TxLink(props) {
54
54
  color: "text.secondary",
55
55
  children: t("common.none")
56
56
  });
57
- }
57
+ }
58
+ const Root = (0, _system.styled)(_material.Stack)`
59
+ @media (max-width: 600px) {
60
+ svg.MuiSvgIcon-root {
61
+ display: none !important;
62
+ }
63
+ }
64
+ `;
@@ -309,6 +309,9 @@ const Root = (0, _system.styled)(_material.Stack)`
309
309
  .invoice-description {
310
310
  display: none !important;
311
311
  }
312
+ svg.MuiSvgIcon-root {
313
+ display: none !important;
314
+ }
312
315
  }
313
316
 
314
317
  a.MuiButton-root {
@@ -46,7 +46,7 @@ function useSubscription(channel) {
46
46
  } else {
47
47
  needSubscription = true;
48
48
  }
49
- if (needSubscription) {
49
+ if (needSubscription && socket.current) {
50
50
  subscription.current = socket.current.subscribe(getRelayChannel(channel));
51
51
  subscription.current.channel = channel;
52
52
  }
package/lib/index.d.ts CHANGED
@@ -11,7 +11,6 @@ import SafeGuard from './components/safe-guard';
11
11
  import Status from './components/status';
12
12
  import Switch from './components/switch-button';
13
13
  import CustomerInvoiceList from './history/invoice/list';
14
- import MiniInvoiceList from './history/mini-invoice/list';
15
14
  import CustomerPaymentList from './history/payment/list';
16
15
  import api from './libs/api';
17
16
  import dayjs from './libs/dayjs';
@@ -24,7 +23,8 @@ import Payment from './payment/index';
24
23
  import ProductSkeleton from './payment/product-skeleton';
25
24
  import PaymentSummary from './payment/summary';
26
25
  export * from './libs/util';
26
+ export * from './libs/connect';
27
27
  export * from './contexts/payment';
28
28
  export * from './hooks/subscription';
29
29
  export { translations, createTranslator } from './locales';
30
- export { api, dayjs, FormInput, PhoneInput, AddressForm, StripeForm, Status, Livemode, Switch, ConfirmDialog, CheckoutForm, CheckoutTable, CheckoutDonate, CurrencySelector, Payment, PaymentSummary, PricingTable, ProductSkeleton, Amount, CustomerInvoiceList, CustomerPaymentList, MiniInvoiceList, TxLink, TxGas, SafeGuard, };
30
+ export { api, dayjs, FormInput, PhoneInput, AddressForm, StripeForm, Status, Livemode, Switch, ConfirmDialog, CheckoutForm, CheckoutTable, CheckoutDonate, CurrencySelector, Payment, PaymentSummary, PricingTable, ProductSkeleton, Amount, CustomerInvoiceList, CustomerPaymentList, TxLink, TxGas, SafeGuard, };
package/lib/index.js CHANGED
@@ -17,7 +17,6 @@ var _exportNames = {
17
17
  Status: true,
18
18
  Switch: true,
19
19
  CustomerInvoiceList: true,
20
- MiniInvoiceList: true,
21
20
  CustomerPaymentList: true,
22
21
  api: true,
23
22
  dayjs: true,
@@ -83,7 +82,7 @@ Object.defineProperty(exports, "CustomerInvoiceList", {
83
82
  Object.defineProperty(exports, "CustomerPaymentList", {
84
83
  enumerable: true,
85
84
  get: function () {
86
- return _list3.default;
85
+ return _list2.default;
87
86
  }
88
87
  });
89
88
  Object.defineProperty(exports, "FormInput", {
@@ -98,12 +97,6 @@ Object.defineProperty(exports, "Livemode", {
98
97
  return _livemode.default;
99
98
  }
100
99
  });
101
- Object.defineProperty(exports, "MiniInvoiceList", {
102
- enumerable: true,
103
- get: function () {
104
- return _list2.default;
105
- }
106
- });
107
100
  Object.defineProperty(exports, "Payment", {
108
101
  enumerable: true,
109
102
  get: function () {
@@ -207,8 +200,7 @@ var _safeGuard = _interopRequireDefault(require("./components/safe-guard"));
207
200
  var _status = _interopRequireDefault(require("./components/status"));
208
201
  var _switchButton = _interopRequireDefault(require("./components/switch-button"));
209
202
  var _list = _interopRequireDefault(require("./history/invoice/list"));
210
- var _list2 = _interopRequireDefault(require("./history/mini-invoice/list"));
211
- var _list3 = _interopRequireDefault(require("./history/payment/list"));
203
+ var _list2 = _interopRequireDefault(require("./history/payment/list"));
212
204
  var _api = _interopRequireDefault(require("./libs/api"));
213
205
  var _dayjs = _interopRequireDefault(require("./libs/dayjs"));
214
206
  var _amount = _interopRequireDefault(require("./payment/amount"));
@@ -231,6 +223,18 @@ Object.keys(_util).forEach(function (key) {
231
223
  }
232
224
  });
233
225
  });
226
+ var _connect = require("./libs/connect");
227
+ Object.keys(_connect).forEach(function (key) {
228
+ if (key === "default" || key === "__esModule") return;
229
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
230
+ if (key in exports && exports[key] === _connect[key]) return;
231
+ Object.defineProperty(exports, key, {
232
+ enumerable: true,
233
+ get: function () {
234
+ return _connect[key];
235
+ }
236
+ });
237
+ });
234
238
  var _payment = require("./contexts/payment");
235
239
  Object.keys(_payment).forEach(function (key) {
236
240
  if (key === "default" || key === "__esModule") return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/payment-react",
3
- "version": "1.13.255",
3
+ "version": "1.13.257",
4
4
  "description": "Reusable react components for payment kit v2",
5
5
  "keywords": [
6
6
  "react",
@@ -91,7 +91,7 @@
91
91
  "@babel/core": "^7.24.5",
92
92
  "@babel/preset-env": "^7.24.5",
93
93
  "@babel/preset-react": "^7.24.1",
94
- "@blocklet/payment-types": "1.13.255",
94
+ "@blocklet/payment-types": "1.13.257",
95
95
  "@storybook/addon-essentials": "^7.6.19",
96
96
  "@storybook/addon-interactions": "^7.6.19",
97
97
  "@storybook/addon-links": "^7.6.19",
@@ -120,5 +120,5 @@
120
120
  "vite-plugin-babel": "^1.2.0",
121
121
  "vite-plugin-node-polyfills": "^0.21.0"
122
122
  },
123
- "gitHead": "79416ada68496df6d233a59244a0cec245414813"
123
+ "gitHead": "29d4263d26ecb8a99805aaef35a89be0820dab92"
124
124
  }
@@ -117,7 +117,7 @@ function SupporterAvatar({ supporters = [], total = 0, currency, method }: Donat
117
117
  function SupporterTable({ supporters = [], total = 0, currency, method }: DonateHistory) {
118
118
  const { t } = useLocaleContext();
119
119
  return (
120
- <Box display="flex" flexDirection="column" alignItems="center" sx={{ width: '100%' }} gap={{ xs: 0.5, sm: 1 }}>
120
+ <Box display="flex" flexDirection="column" alignItems="center" gap={{ xs: 0.5, sm: 1 }}>
121
121
  <Typography component="p" color="text.secondary">
122
122
  {t('payment.checkout.donation.summary', { total })}
123
123
  </Typography>
@@ -132,6 +132,9 @@ function SupporterTable({ supporters = [], total = 0, currency, method }: Donate
132
132
  borderTop: '1px solid #e0e0e0',
133
133
  borderBottom: '1px solid #e0e0e0',
134
134
  },
135
+ '> td:last-of-type': {
136
+ paddingRight: '0',
137
+ },
135
138
  }}>
136
139
  <TableCell>
137
140
  <Stack direction="row" alignItems="center" spacing={0.5}>
@@ -2,6 +2,7 @@ import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
2
2
  import type { PaymentDetails, TPaymentMethod } from '@blocklet/payment-types';
3
3
  import { OpenInNewOutlined } from '@mui/icons-material';
4
4
  import { Link, Stack, Typography } from '@mui/material';
5
+ import { styled } from '@mui/system';
5
6
 
6
7
  import { getTxLink } from '../../libs/util';
7
8
 
@@ -31,17 +32,16 @@ export default function TxLink(props: {
31
32
  if (link) {
32
33
  return (
33
34
  <Link href={link} target="_blank" rel="noopener noreferrer">
34
- <Stack
35
- component="span"
35
+ <Root
36
36
  direction="row"
37
37
  alignItems="center"
38
38
  justifyContent={props.align === 'left' ? 'flex-start' : 'flex-end'}
39
39
  spacing={1}>
40
40
  <Typography component="span" color="primary">
41
- {text.length > 40 ? [text.slice(0, 8), text.slice(-8)].join('...') : text}
41
+ {text.length > 40 ? [text.slice(0, 6), text.slice(-6)].join('...') : text}
42
42
  </Typography>
43
43
  <OpenInNewOutlined fontSize="small" />
44
- </Stack>
44
+ </Root>
45
45
  </Link>
46
46
  );
47
47
  }
@@ -52,3 +52,11 @@ export default function TxLink(props: {
52
52
  </Typography>
53
53
  );
54
54
  }
55
+
56
+ const Root = styled(Stack)`
57
+ @media (max-width: 600px) {
58
+ svg.MuiSvgIcon-root {
59
+ display: none !important;
60
+ }
61
+ }
62
+ `;
@@ -289,6 +289,9 @@ const Root = styled(Stack)`
289
289
  .invoice-description {
290
290
  display: none !important;
291
291
  }
292
+ svg.MuiSvgIcon-root {
293
+ display: none !important;
294
+ }
292
295
  }
293
296
 
294
297
  a.MuiButton-root {
@@ -50,7 +50,7 @@ export function useSubscription(channel: string) {
50
50
  needSubscription = true;
51
51
  }
52
52
 
53
- if (needSubscription) {
53
+ if (needSubscription && socket.current) {
54
54
  subscription.current = socket.current.subscribe(getRelayChannel(channel));
55
55
  subscription.current.channel = channel;
56
56
  }
package/src/index.ts CHANGED
@@ -11,7 +11,6 @@ import SafeGuard from './components/safe-guard';
11
11
  import Status from './components/status';
12
12
  import Switch from './components/switch-button';
13
13
  import CustomerInvoiceList from './history/invoice/list';
14
- import MiniInvoiceList from './history/mini-invoice/list';
15
14
  import CustomerPaymentList from './history/payment/list';
16
15
  import api from './libs/api';
17
16
  import dayjs from './libs/dayjs';
@@ -25,6 +24,7 @@ import ProductSkeleton from './payment/product-skeleton';
25
24
  import PaymentSummary from './payment/summary';
26
25
 
27
26
  export * from './libs/util';
27
+ export * from './libs/connect';
28
28
  export * from './contexts/payment';
29
29
  export * from './hooks/subscription';
30
30
 
@@ -52,7 +52,6 @@ export {
52
52
  Amount,
53
53
  CustomerInvoiceList,
54
54
  CustomerPaymentList,
55
- MiniInvoiceList,
56
55
  TxLink,
57
56
  TxGas,
58
57
  SafeGuard,
@@ -1,2 +0,0 @@
1
- /// <reference types="react" />
2
- export default function MiniInvoiceList(): import("react").JSX.Element;
@@ -1,192 +0,0 @@
1
- import { jsx, jsxs } from "react/jsx-runtime";
2
- import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
3
- import {
4
- Alert,
5
- Box,
6
- Button,
7
- CircularProgress,
8
- Divider,
9
- Link,
10
- List,
11
- ListItem,
12
- ListSubheader,
13
- Stack,
14
- Typography
15
- } from "@mui/material";
16
- import { useRequest } from "ahooks";
17
- import { useMemo } from "react";
18
- import { joinURL, withQuery } from "ufo";
19
- import Status from "../../components/status.js";
20
- import api from "../../libs/api.js";
21
- import { getDidConnectQueryParams } from "../../libs/did-connect.js";
22
- import {
23
- formatBNStr,
24
- formatError,
25
- formatSubscriptionProduct,
26
- formatTime,
27
- formatToDate,
28
- getInvoiceStatusColor,
29
- getPrefix,
30
- getSubscriptionStatusColor
31
- } from "../../libs/util.js";
32
- const fetchInvoiceData = (params = {}) => {
33
- const search = new URLSearchParams();
34
- Object.keys(params).forEach((key) => {
35
- search.set(key, String(params[key]));
36
- });
37
- return api.get(`/api/invoices?${search.toString()}`).then((res) => res.data);
38
- };
39
- const fetchSubscriptionData = (id, authToken) => {
40
- if (!id) {
41
- throw new Error("Subscription ID is missing");
42
- }
43
- return api.get(`/api/subscriptions/${id}?authToken=${authToken}`).then((res) => res.data);
44
- };
45
- export default function MiniInvoiceList() {
46
- const { t, locale } = useLocaleContext();
47
- const params = new URL(window.location.href).searchParams;
48
- const subscriptionId = params.get("id") || "";
49
- const authToken = params.get("authToken") || "";
50
- const { data: subscription, error, loading } = useRequest(() => fetchSubscriptionData(subscriptionId, authToken));
51
- const { data } = useRequest(
52
- () => fetchInvoiceData({
53
- page: 1,
54
- pageSize: 20,
55
- status: "open,paid,uncollectible",
56
- subscription_id: subscriptionId,
57
- authToken,
58
- ignore_zero: true,
59
- include_staking: true
60
- })
61
- );
62
- const subscriptionPageUrl = useMemo(() => {
63
- if (!subscription) {
64
- return "#";
65
- }
66
- const pageUrl = joinURL(getPrefix(), `/customer/subscription/${subscription.id}`);
67
- return withQuery(pageUrl, {
68
- source: "embed",
69
- ...getDidConnectQueryParams({ forceConnected: subscription.customer.did })
70
- });
71
- }, [subscription]);
72
- if (error) {
73
- return /* @__PURE__ */ jsx(Position, { children: /* @__PURE__ */ jsx(Alert, { severity: "error", children: formatError(error) }) });
74
- }
75
- if (!subscription || loading) {
76
- return /* @__PURE__ */ jsx(Position, { children: /* @__PURE__ */ jsx(CircularProgress, {}) });
77
- }
78
- const invoices = data?.list || [];
79
- const infoList = [
80
- {
81
- name: t("payment.customer.subscriptions.plan"),
82
- value: /* @__PURE__ */ jsx(Typography, { fontWeight: 600, sx: { marginRight: "10px" }, children: formatSubscriptionProduct(subscription.items) })
83
- },
84
- {
85
- name: t("common.status"),
86
- value: /* @__PURE__ */ jsx(Status, { label: subscription.status, color: getSubscriptionStatusColor(subscription.status) })
87
- }
88
- ];
89
- if (subscription.status === "active" || subscription.status === "trialing") {
90
- infoList.push({
91
- name: t("payment.customer.subscriptions.nextInvoice"),
92
- value: /* @__PURE__ */ jsx(
93
- Typography,
94
- {
95
- sx: {
96
- color: "success.main",
97
- fontWeight: "bold",
98
- marginRight: "10px"
99
- },
100
- children: formatTime(subscription.current_period_end * 1e3)
101
- }
102
- )
103
- });
104
- }
105
- return /* @__PURE__ */ jsxs(Position, { children: [
106
- /* @__PURE__ */ jsx(Typography, { title: t("payment.checkout.subscription") }),
107
- /* @__PURE__ */ jsxs(
108
- Box,
109
- {
110
- className: "mini-invoice-wrap",
111
- sx: {
112
- display: "flex",
113
- flexDirection: "column",
114
- alignItem: "center",
115
- justifyContent: "flex-start",
116
- padding: "16px",
117
- width: "100%",
118
- height: "100%"
119
- },
120
- children: [
121
- /* @__PURE__ */ jsx(Typography, { component: "h3", sx: { textAlign: "center" }, variant: "h5", gutterBottom: true, children: t("payment.customer.subscriptions.current") }),
122
- /* @__PURE__ */ jsx(Box, { sx: { marginTop: "12px" }, children: /* @__PURE__ */ jsx(List, { children: infoList.map(({ name, value }) => {
123
- return /* @__PURE__ */ jsxs(ListItem, { disableGutters: true, sx: { display: "flex", justifyContent: "space-between" }, children: [
124
- /* @__PURE__ */ jsx(Typography, { component: "span", children: name }),
125
- /* @__PURE__ */ jsx(Typography, { component: "span", children: value })
126
- ] }, name);
127
- }) }) }),
128
- /* @__PURE__ */ jsx(Divider, {}),
129
- /* @__PURE__ */ jsx(Box, { sx: { marginTop: "12px", flex: 1 }, children: /* @__PURE__ */ jsxs(List, { sx: { overflow: "auto" }, className: "mini-invoice-list", children: [
130
- /* @__PURE__ */ jsx(ListSubheader, { disableGutters: true, sx: { padding: 0 }, children: /* @__PURE__ */ jsx(Typography, { component: "h2", variant: "h6", fontSize: "16px", children: t("payment.customer.invoices") }) }),
131
- invoices.length === 0 ? /* @__PURE__ */ jsx(Typography, { color: "text.secondary", children: t("payment.customer.invoice.empty") }) : invoices.map((item) => {
132
- return /* @__PURE__ */ jsxs(ListItem, { disableGutters: true, sx: { display: "flex", justifyContent: "space-between" }, children: [
133
- /* @__PURE__ */ jsx(Typography, { component: "span", sx: { flex: 3 }, children: formatToDate(item.created_at, locale, "YYYY-MM-DD") }),
134
- /* @__PURE__ */ jsxs(Typography, { component: "span", sx: { flex: 1, textAlign: "right" }, children: [
135
- formatBNStr(item.total, item.paymentCurrency.decimal),
136
- "\xA0",
137
- item.paymentCurrency.symbol
138
- ] }),
139
- /* @__PURE__ */ jsx(Typography, { component: "span", sx: { flex: 2, textAlign: "right" }, children: /* @__PURE__ */ jsx(Status, { label: item.status, color: getInvoiceStatusColor(item.status) }) })
140
- ] }, item.id);
141
- })
142
- ] }) }),
143
- /* @__PURE__ */ jsxs(Stack, { direction: "row", justifyContent: "center", spacing: 2, sx: { mt: 2 }, children: [
144
- subscription.service_actions?.map((x) => (
145
- // @ts-ignore
146
- /* @__PURE__ */ jsx(
147
- Button,
148
- {
149
- component: Link,
150
- variant: x.variant,
151
- color: x.color,
152
- href: x.link,
153
- size: "small",
154
- target: "_blank",
155
- sx: { textDecoration: "none !important" },
156
- children: x.text[locale] || x.text.en || x.name
157
- },
158
- x.name
159
- )
160
- )),
161
- /* @__PURE__ */ jsx(
162
- Button,
163
- {
164
- variant: "contained",
165
- sx: { color: "#fff!important", width: subscription.service_actions?.length ? "auto" : "100%" },
166
- target: "_blank",
167
- href: subscriptionPageUrl,
168
- children: t("payment.customer.subscriptions.view")
169
- }
170
- )
171
- ] })
172
- ]
173
- }
174
- )
175
- ] });
176
- }
177
- function Position({ children }) {
178
- return /* @__PURE__ */ jsx(
179
- Box,
180
- {
181
- className: "mini-invoice-box",
182
- sx: {
183
- padding: "8px",
184
- width: "100%",
185
- maxWidth: "500px",
186
- background: "#fff",
187
- margin: "0 auto"
188
- },
189
- children
190
- }
191
- );
192
- }
@@ -1,2 +0,0 @@
1
- /// <reference types="react" />
2
- export default function MiniInvoiceList(): import("react").JSX.Element;
@@ -1,264 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- module.exports = MiniInvoiceList;
7
- var _jsxRuntime = require("react/jsx-runtime");
8
- var _context = require("@arcblock/ux/lib/Locale/context");
9
- var _material = require("@mui/material");
10
- var _ahooks = require("ahooks");
11
- var _react = require("react");
12
- var _ufo = require("ufo");
13
- var _status = _interopRequireDefault(require("../../components/status"));
14
- var _api = _interopRequireDefault(require("../../libs/api"));
15
- var _didConnect = require("../../libs/did-connect");
16
- var _util = require("../../libs/util");
17
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
- const fetchInvoiceData = (params = {}) => {
19
- const search = new URLSearchParams();
20
- Object.keys(params).forEach(key => {
21
- search.set(key, String(params[key]));
22
- });
23
- return _api.default.get(`/api/invoices?${search.toString()}`).then(res => res.data);
24
- };
25
- const fetchSubscriptionData = (id, authToken) => {
26
- if (!id) {
27
- throw new Error("Subscription ID is missing");
28
- }
29
- return _api.default.get(`/api/subscriptions/${id}?authToken=${authToken}`).then(res => res.data);
30
- };
31
- function MiniInvoiceList() {
32
- const {
33
- t,
34
- locale
35
- } = (0, _context.useLocaleContext)();
36
- const params = new URL(window.location.href).searchParams;
37
- const subscriptionId = params.get("id") || "";
38
- const authToken = params.get("authToken") || "";
39
- const {
40
- data: subscription,
41
- error,
42
- loading
43
- } = (0, _ahooks.useRequest)(() => fetchSubscriptionData(subscriptionId, authToken));
44
- const {
45
- data
46
- } = (0, _ahooks.useRequest)(() => fetchInvoiceData({
47
- page: 1,
48
- pageSize: 20,
49
- status: "open,paid,uncollectible",
50
- subscription_id: subscriptionId,
51
- authToken,
52
- ignore_zero: true,
53
- include_staking: true
54
- }));
55
- const subscriptionPageUrl = (0, _react.useMemo)(() => {
56
- if (!subscription) {
57
- return "#";
58
- }
59
- const pageUrl = (0, _ufo.joinURL)((0, _util.getPrefix)(), `/customer/subscription/${subscription.id}`);
60
- return (0, _ufo.withQuery)(pageUrl, {
61
- source: "embed",
62
- ...(0, _didConnect.getDidConnectQueryParams)({
63
- forceConnected: subscription.customer.did
64
- })
65
- });
66
- }, [subscription]);
67
- if (error) {
68
- return /* @__PURE__ */(0, _jsxRuntime.jsx)(Position, {
69
- children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Alert, {
70
- severity: "error",
71
- children: (0, _util.formatError)(error)
72
- })
73
- });
74
- }
75
- if (!subscription || loading) {
76
- return /* @__PURE__ */(0, _jsxRuntime.jsx)(Position, {
77
- children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.CircularProgress, {})
78
- });
79
- }
80
- const invoices = data?.list || [];
81
- const infoList = [{
82
- name: t("payment.customer.subscriptions.plan"),
83
- value: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
84
- fontWeight: 600,
85
- sx: {
86
- marginRight: "10px"
87
- },
88
- children: (0, _util.formatSubscriptionProduct)(subscription.items)
89
- })
90
- }, {
91
- name: t("common.status"),
92
- value: /* @__PURE__ */(0, _jsxRuntime.jsx)(_status.default, {
93
- label: subscription.status,
94
- color: (0, _util.getSubscriptionStatusColor)(subscription.status)
95
- })
96
- }];
97
- if (subscription.status === "active" || subscription.status === "trialing") {
98
- infoList.push({
99
- name: t("payment.customer.subscriptions.nextInvoice"),
100
- value: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
101
- sx: {
102
- color: "success.main",
103
- fontWeight: "bold",
104
- marginRight: "10px"
105
- },
106
- children: (0, _util.formatTime)(subscription.current_period_end * 1e3)
107
- })
108
- });
109
- }
110
- return /* @__PURE__ */(0, _jsxRuntime.jsxs)(Position, {
111
- children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
112
- title: t("payment.checkout.subscription")
113
- }), /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
114
- className: "mini-invoice-wrap",
115
- sx: {
116
- display: "flex",
117
- flexDirection: "column",
118
- alignItem: "center",
119
- justifyContent: "flex-start",
120
- padding: "16px",
121
- width: "100%",
122
- height: "100%"
123
- },
124
- children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
125
- component: "h3",
126
- sx: {
127
- textAlign: "center"
128
- },
129
- variant: "h5",
130
- gutterBottom: true,
131
- children: t("payment.customer.subscriptions.current")
132
- }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
133
- sx: {
134
- marginTop: "12px"
135
- },
136
- children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.List, {
137
- children: infoList.map(({
138
- name,
139
- value
140
- }) => {
141
- return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.ListItem, {
142
- disableGutters: true,
143
- sx: {
144
- display: "flex",
145
- justifyContent: "space-between"
146
- },
147
- children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
148
- component: "span",
149
- children: name
150
- }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
151
- component: "span",
152
- children: value
153
- })]
154
- }, name);
155
- })
156
- })
157
- }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Divider, {}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
158
- sx: {
159
- marginTop: "12px",
160
- flex: 1
161
- },
162
- children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.List, {
163
- sx: {
164
- overflow: "auto"
165
- },
166
- className: "mini-invoice-list",
167
- children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.ListSubheader, {
168
- disableGutters: true,
169
- sx: {
170
- padding: 0
171
- },
172
- children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
173
- component: "h2",
174
- variant: "h6",
175
- fontSize: "16px",
176
- children: t("payment.customer.invoices")
177
- })
178
- }), invoices.length === 0 ? /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
179
- color: "text.secondary",
180
- children: t("payment.customer.invoice.empty")
181
- }) : invoices.map(item => {
182
- return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.ListItem, {
183
- disableGutters: true,
184
- sx: {
185
- display: "flex",
186
- justifyContent: "space-between"
187
- },
188
- children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
189
- component: "span",
190
- sx: {
191
- flex: 3
192
- },
193
- children: (0, _util.formatToDate)(item.created_at, locale, "YYYY-MM-DD")
194
- }), /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Typography, {
195
- component: "span",
196
- sx: {
197
- flex: 1,
198
- textAlign: "right"
199
- },
200
- children: [(0, _util.formatBNStr)(item.total, item.paymentCurrency.decimal), "\xA0", item.paymentCurrency.symbol]
201
- }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
202
- component: "span",
203
- sx: {
204
- flex: 2,
205
- textAlign: "right"
206
- },
207
- children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_status.default, {
208
- label: item.status,
209
- color: (0, _util.getInvoiceStatusColor)(item.status)
210
- })
211
- })]
212
- }, item.id);
213
- })]
214
- })
215
- }), /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
216
- direction: "row",
217
- justifyContent: "center",
218
- spacing: 2,
219
- sx: {
220
- mt: 2
221
- },
222
- children: [subscription.service_actions?.map(x =>
223
- // @ts-ignore
224
- /* @__PURE__ */
225
- (0, _jsxRuntime.jsx)(_material.Button, {
226
- component: _material.Link,
227
- variant: x.variant,
228
- color: x.color,
229
- href: x.link,
230
- size: "small",
231
- target: "_blank",
232
- sx: {
233
- textDecoration: "none !important"
234
- },
235
- children: x.text[locale] || x.text.en || x.name
236
- }, x.name)), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Button, {
237
- variant: "contained",
238
- sx: {
239
- color: "#fff!important",
240
- width: subscription.service_actions?.length ? "auto" : "100%"
241
- },
242
- target: "_blank",
243
- href: subscriptionPageUrl,
244
- children: t("payment.customer.subscriptions.view")
245
- })]
246
- })]
247
- })]
248
- });
249
- }
250
- function Position({
251
- children
252
- }) {
253
- return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
254
- className: "mini-invoice-box",
255
- sx: {
256
- padding: "8px",
257
- width: "100%",
258
- maxWidth: "500px",
259
- background: "#fff",
260
- margin: "0 auto"
261
- },
262
- children
263
- });
264
- }
@@ -1,233 +0,0 @@
1
- /* eslint-disable react/no-unstable-nested-components */
2
- import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
3
- import type { Paginated, TInvoiceExpanded, TSubscriptionExpanded } from '@blocklet/payment-types';
4
- import {
5
- Alert,
6
- Box,
7
- Button,
8
- CircularProgress,
9
- Divider,
10
- Link,
11
- List,
12
- ListItem,
13
- ListSubheader,
14
- Stack,
15
- Typography,
16
- } from '@mui/material';
17
- import { useRequest } from 'ahooks';
18
- import { useMemo } from 'react';
19
- import { joinURL, withQuery } from 'ufo';
20
-
21
- import Status from '../../components/status';
22
- import api from '../../libs/api';
23
- import { getDidConnectQueryParams } from '../../libs/did-connect';
24
- import {
25
- formatBNStr,
26
- formatError,
27
- formatSubscriptionProduct,
28
- formatTime,
29
- formatToDate,
30
- getInvoiceStatusColor,
31
- getPrefix,
32
- getSubscriptionStatusColor,
33
- } from '../../libs/util';
34
-
35
- const fetchInvoiceData = (params: Record<string, any> = {}): Promise<Paginated<TInvoiceExpanded>> => {
36
- const search = new URLSearchParams();
37
- Object.keys(params).forEach((key) => {
38
- search.set(key, String(params[key]));
39
- });
40
- return api.get(`/api/invoices?${search.toString()}`).then((res: any) => res.data);
41
- };
42
-
43
- const fetchSubscriptionData = (id: string, authToken: string): Promise<TSubscriptionExpanded> => {
44
- if (!id) {
45
- throw new Error('Subscription ID is missing');
46
- }
47
-
48
- return api.get(`/api/subscriptions/${id}?authToken=${authToken}`).then((res) => res.data);
49
- };
50
-
51
- export default function MiniInvoiceList() {
52
- const { t, locale } = useLocaleContext();
53
- const params = new URL(window.location.href).searchParams;
54
-
55
- const subscriptionId = params.get('id') || '';
56
- const authToken = params.get('authToken') || '';
57
-
58
- const { data: subscription, error, loading } = useRequest(() => fetchSubscriptionData(subscriptionId, authToken));
59
- const { data } = useRequest(() =>
60
- fetchInvoiceData({
61
- page: 1,
62
- pageSize: 20,
63
- status: 'open,paid,uncollectible',
64
- subscription_id: subscriptionId,
65
- authToken,
66
- ignore_zero: true,
67
- include_staking: true,
68
- })
69
- );
70
-
71
- const subscriptionPageUrl: string = useMemo(() => {
72
- if (!subscription) {
73
- return '#';
74
- }
75
-
76
- const pageUrl: string = joinURL(getPrefix(), `/customer/subscription/${subscription.id}`);
77
-
78
- return withQuery(pageUrl, {
79
- source: 'embed',
80
- ...getDidConnectQueryParams({ forceConnected: subscription.customer.did }),
81
- });
82
- }, [subscription]);
83
-
84
- if (error) {
85
- return (
86
- <Position>
87
- <Alert severity="error">{formatError(error)}</Alert>
88
- </Position>
89
- );
90
- }
91
- if (!subscription || loading) {
92
- return (
93
- <Position>
94
- <CircularProgress />
95
- </Position>
96
- );
97
- }
98
-
99
- const invoices = data?.list || [];
100
-
101
- const infoList = [
102
- {
103
- name: t('payment.customer.subscriptions.plan'),
104
- value: (
105
- <Typography fontWeight={600} sx={{ marginRight: '10px' }}>
106
- {formatSubscriptionProduct(subscription.items)}
107
- </Typography>
108
- ),
109
- },
110
- {
111
- name: t('common.status'),
112
- value: <Status label={subscription.status} color={getSubscriptionStatusColor(subscription.status)} />,
113
- },
114
- ];
115
-
116
- if (subscription.status === 'active' || subscription.status === 'trialing') {
117
- infoList.push({
118
- name: t('payment.customer.subscriptions.nextInvoice'),
119
- value: (
120
- <Typography
121
- sx={{
122
- color: 'success.main',
123
- fontWeight: 'bold',
124
- marginRight: '10px',
125
- }}>
126
- {formatTime(subscription.current_period_end * 1000)}
127
- </Typography>
128
- ),
129
- });
130
- }
131
-
132
- return (
133
- <Position>
134
- <Typography title={t('payment.checkout.subscription')} />
135
- <Box
136
- className="mini-invoice-wrap"
137
- sx={{
138
- display: 'flex',
139
- flexDirection: 'column',
140
- alignItem: 'center',
141
- justifyContent: 'flex-start',
142
- padding: '16px',
143
- width: '100%',
144
- height: '100%',
145
- }}>
146
- <Typography component="h3" sx={{ textAlign: 'center' }} variant="h5" gutterBottom>
147
- {t('payment.customer.subscriptions.current')}
148
- </Typography>
149
- <Box sx={{ marginTop: '12px' }}>
150
- <List>
151
- {infoList.map(({ name, value }) => {
152
- return (
153
- <ListItem key={name} disableGutters sx={{ display: 'flex', justifyContent: 'space-between' }}>
154
- <Typography component="span">{name}</Typography>
155
- <Typography component="span">{value}</Typography>
156
- </ListItem>
157
- );
158
- })}
159
- </List>
160
- </Box>
161
- <Divider />
162
- <Box sx={{ marginTop: '12px', flex: 1 }}>
163
- <List sx={{ overflow: 'auto' }} className="mini-invoice-list">
164
- <ListSubheader disableGutters sx={{ padding: 0 }}>
165
- <Typography component="h2" variant="h6" fontSize="16px">
166
- {t('payment.customer.invoices')}
167
- </Typography>
168
- </ListSubheader>
169
- {(invoices as any).length === 0 ? (
170
- <Typography color="text.secondary">{t('payment.customer.invoice.empty')}</Typography>
171
- ) : (
172
- (invoices as any).map((item: any) => {
173
- return (
174
- <ListItem key={item.id} disableGutters sx={{ display: 'flex', justifyContent: 'space-between' }}>
175
- <Typography component="span" sx={{ flex: 3 }}>
176
- {formatToDate(item.created_at, locale, 'YYYY-MM-DD')}
177
- </Typography>
178
- <Typography component="span" sx={{ flex: 1, textAlign: 'right' }}>
179
- {formatBNStr(item.total, item.paymentCurrency.decimal)}&nbsp;
180
- {item.paymentCurrency.symbol}
181
- </Typography>
182
- <Typography component="span" sx={{ flex: 2, textAlign: 'right' }}>
183
- <Status label={item.status} color={getInvoiceStatusColor(item.status)} />
184
- </Typography>
185
- </ListItem>
186
- );
187
- })
188
- )}
189
- </List>
190
- </Box>
191
- <Stack direction="row" justifyContent="center" spacing={2} sx={{ mt: 2 }}>
192
- {subscription.service_actions?.map((x) => (
193
- // @ts-ignore
194
- <Button
195
- component={Link}
196
- key={x.name}
197
- variant={x.variant}
198
- color={x.color}
199
- href={x.link}
200
- size="small"
201
- target="_blank"
202
- sx={{ textDecoration: 'none !important' }}>
203
- {x.text[locale] || x.text.en || x.name}
204
- </Button>
205
- ))}
206
- <Button
207
- variant="contained"
208
- sx={{ color: '#fff!important', width: subscription.service_actions?.length ? 'auto' : '100%' }}
209
- target="_blank"
210
- href={subscriptionPageUrl}>
211
- {t('payment.customer.subscriptions.view')}
212
- </Button>
213
- </Stack>
214
- </Box>
215
- </Position>
216
- );
217
- }
218
-
219
- function Position({ children }: any) {
220
- return (
221
- <Box
222
- className="mini-invoice-box" // 预留 class 用于设置定位
223
- sx={{
224
- padding: '8px',
225
- width: '100%',
226
- maxWidth: '500px',
227
- background: '#fff',
228
- margin: '0 auto',
229
- }}>
230
- {children}
231
- </Box>
232
- );
233
- }
File without changes
File without changes
File without changes
File without changes
File without changes