@blocklet/payment-react 1.13.212 → 1.13.214

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.
@@ -37,7 +37,7 @@ const createOrUpdateDonation = (settings, livemode = true) => {
37
37
  const supporterCache = {};
38
38
  const fetchSupporters = (target) => {
39
39
  if (!supporterCache[target]) {
40
- supporterCache[target] = api.get(`/api/donations?&target=${target}`).then((res) => res.data).finally(() => {
40
+ supporterCache[target] = api.get("/api/donations", { params: { target } }).then((res) => res.data).finally(() => {
41
41
  setTimeout(() => {
42
42
  delete supporterCache[target];
43
43
  }, 3e3);
@@ -45,7 +45,7 @@ const fetchSupporters = (target) => {
45
45
  }
46
46
  return supporterCache[target];
47
47
  };
48
- function SupporterAvatar({ supporters = [], total, currency, method }) {
48
+ function SupporterAvatar({ supporters = [], total = 0, currency, method }) {
49
49
  const { t } = useLocaleContext();
50
50
  const customers = uniqBy(supporters, "customer_did");
51
51
  return /* @__PURE__ */ jsxs(
@@ -80,7 +80,7 @@ function SupporterAvatar({ supporters = [], total, currency, method }) {
80
80
  }
81
81
  );
82
82
  }
83
- function SupporterTable({ supporters = [], total, currency, method }) {
83
+ function SupporterTable({ supporters = [], total = 0, currency, method }) {
84
84
  const { t } = useLocaleContext();
85
85
  return /* @__PURE__ */ jsxs(Box, { display: "flex", flexDirection: "column", alignItems: "center", sx: { width: "100%" }, gap: { xs: 0.5, sm: 1 }, children: [
86
86
  /* @__PURE__ */ jsx(Typography, { component: "p", color: "text.secondary", children: t("payment.checkout.donation.summary", { total }) }),
@@ -1,4 +1,8 @@
1
- import { isPaymentKitMounted } from "../util.js";
1
+ import { PAYMENT_KIT_DID, isPaymentKitMounted } from "../util.js";
2
2
  export default function SafeGuard({ children }) {
3
- return isPaymentKitMounted() ? children : null;
3
+ const mounted = isPaymentKitMounted();
4
+ if (mounted === false) {
5
+ console.warn(`PaymentKit is required to use this feature: https://store.blocklet.dev/blocklets/${PAYMENT_KIT_DID}`);
6
+ }
7
+ return mounted ? children : null;
4
8
  }
@@ -1,7 +1,8 @@
1
1
  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
- import { Box, Button, CircularProgress, Stack, Typography } from "@mui/material";
4
+ import { Box, Button, CircularProgress, Hidden, Stack, Typography } from "@mui/material";
5
+ import { styled } from "@mui/system";
5
6
  import { useInfiniteScroll } from "ahooks";
6
7
  import { joinURL } from "ufo";
7
8
  import api from "../../api.js";
@@ -74,7 +75,7 @@ export default function CustomerInvoiceList({
74
75
  }
75
76
  const hasMore = data && data.list.length < data.count;
76
77
  const grouped = groupByDate(data.list);
77
- return /* @__PURE__ */ jsxs(Stack, { direction: "column", gap: 1, sx: { mt: 1 }, children: [
78
+ return /* @__PURE__ */ jsxs(Root, { direction: "column", gap: 1, sx: { mt: 1 }, children: [
78
79
  Object.entries(grouped).map(([date, invoices]) => /* @__PURE__ */ jsxs(Box, { children: [
79
80
  /* @__PURE__ */ jsx(Typography, { sx: { fontWeight: "bold", color: "text.secondary", mt: 2, mb: 1 }, children: date }),
80
81
  invoices.map((invoice) => {
@@ -82,10 +83,7 @@ export default function CustomerInvoiceList({
82
83
  return /* @__PURE__ */ jsxs(
83
84
  Stack,
84
85
  {
85
- direction: {
86
- xs: "column",
87
- sm: "row"
88
- },
86
+ direction: "row",
89
87
  sx: { my: 1 },
90
88
  gap: {
91
89
  xs: 0.5,
@@ -94,18 +92,18 @@ export default function CustomerInvoiceList({
94
92
  },
95
93
  flexWrap: "nowrap",
96
94
  children: [
97
- /* @__PURE__ */ jsx(Box, { flex: 3, children: /* @__PURE__ */ jsx("a", { href: link.url, target: link.external ? "_blank" : target, rel: "noreferrer", children: /* @__PURE__ */ jsxs(Stack, { direction: "row", alignItems: "center", spacing: 0.5, children: [
95
+ /* @__PURE__ */ jsx(Box, { flex: 2, children: /* @__PURE__ */ jsx("a", { href: link.url, target: link.external ? "_blank" : target, rel: "noreferrer", children: /* @__PURE__ */ jsxs(Stack, { direction: "row", alignItems: "center", spacing: 0.5, children: [
98
96
  /* @__PURE__ */ jsx(Typography, { component: "span", children: invoice.number }),
99
- link.external && /* @__PURE__ */ jsx(OpenInNewOutlined, { fontSize: "small", sx: { color: "text.secondary" } })
97
+ link.external && /* @__PURE__ */ jsx(Hidden, { mdDown: true, children: /* @__PURE__ */ jsx(OpenInNewOutlined, { fontSize: "small", sx: { color: "text.secondary" } }) })
100
98
  ] }) }) }),
101
- /* @__PURE__ */ jsx(Box, { flex: 3, children: /* @__PURE__ */ jsx(Typography, { children: formatToDate(invoice.created_at) }) }),
102
- /* @__PURE__ */ jsx(Box, { flex: 2, children: /* @__PURE__ */ jsxs(Typography, { textAlign: "right", children: [
99
+ /* @__PURE__ */ jsx(Box, { flex: 1, textAlign: "right", children: /* @__PURE__ */ jsx(Typography, { children: formatToDate(invoice.created_at, "en", "HH:mm:ss") }) }),
100
+ /* @__PURE__ */ jsx(Box, { flex: 1, textAlign: "right", children: /* @__PURE__ */ jsxs(Typography, { children: [
103
101
  formatBNStr(invoice.total, invoice.paymentCurrency.decimal),
104
102
  "\xA0",
105
103
  invoice.paymentCurrency.symbol
106
104
  ] }) }),
107
- /* @__PURE__ */ jsx(Box, { flex: 2, children: /* @__PURE__ */ jsx(Status, { label: invoice.status, color: getInvoiceStatusColor(invoice.status) }) }),
108
- /* @__PURE__ */ jsx(Box, { flex: 4, children: /* @__PURE__ */ jsx(Typography, { children: invoice.description || invoice.id }) })
105
+ /* @__PURE__ */ jsx(Box, { flex: 1, textAlign: "right", children: /* @__PURE__ */ jsx(Status, { label: invoice.status, color: getInvoiceStatusColor(invoice.status) }) }),
106
+ /* @__PURE__ */ jsx(Hidden, { mdDown: true, children: /* @__PURE__ */ jsx(Box, { flex: 2, className: "invoice-description", textAlign: "right", children: /* @__PURE__ */ jsx(Typography, { children: invoice.description || invoice.id }) }) })
109
107
  ]
110
108
  },
111
109
  invoice.id
@@ -127,3 +125,13 @@ CustomerInvoiceList.defaultProps = {
127
125
  target: "_self",
128
126
  action: ""
129
127
  };
128
+ const Root = styled(Stack)`
129
+ @media (max-width: 600px) {
130
+ .invoice-description {
131
+ display: none !important;
132
+ }
133
+ svg[data-testid='OpenInNewOutlinedIcon'] {
134
+ display: none !important;
135
+ }
136
+ }
137
+ `;
package/es/util.d.ts CHANGED
@@ -3,15 +3,15 @@ import type { PaymentDetails, PriceCurrency, PriceRecurring, TLineItemExpanded,
3
3
  export declare const PAYMENT_KIT_DID = "z2qaCNvKMv5GjouKdcDWexv6WqtHbpNPQDnAk";
4
4
  export declare const isPaymentKitMounted: () => any;
5
5
  export declare const getPrefix: () => any;
6
- export declare function formatToDate(date: Date | string | number, locale?: string): any;
6
+ export declare function formatToDate(date: Date | string | number, locale?: string, format?: string): any;
7
7
  export declare function formatToDatetime(date: Date | string | number, locale?: string): any;
8
8
  export declare function formatTime(date: Date | string | number, format?: string, locale?: string): any;
9
9
  export declare function formatDateTime(date: Date | string | number, locale?: string): any;
10
10
  export declare const formatLocale: (locale?: string) => string;
11
11
  export declare const formatPrettyMsLocale: (locale: string) => "zh_CN" | "en_US";
12
12
  export declare const formatError: (err: any) => any;
13
- export declare function formatBNStr(str?: string, decimals?: number, precision?: number, trim?: boolean): any;
14
- export declare function formatNumber(n: number | string, precision?: number, trim?: boolean): any;
13
+ export declare function formatBNStr(str?: string, decimals?: number, precision?: number, trim?: boolean): string;
14
+ export declare function formatNumber(n: number | string, precision?: number, trim?: boolean): string;
15
15
  export declare const formatPrice: (price: TPrice, currency: TPaymentCurrency, unit_label?: string, quantity?: number, bn?: boolean, locale?: string) => string;
16
16
  export declare const formatPriceAmount: (price: TPrice, currency: TPaymentCurrency, unit_label?: string, quantity?: number, bn?: boolean) => string;
17
17
  export declare function getStatementDescriptor(items: any[]): any;
package/es/util.js CHANGED
@@ -20,11 +20,11 @@ export const getPrefix = () => {
20
20
  }
21
21
  return window.blocklet?.prefix;
22
22
  };
23
- export function formatToDate(date, locale = "en") {
23
+ export function formatToDate(date, locale = "en", format = "YYYY-MM-DD HH:mm:ss") {
24
24
  if (!date) {
25
25
  return "-";
26
26
  }
27
- return dayjs(date).locale(formatLocale(locale)).format("YYYY-MM-DD HH:mm:ss");
27
+ return dayjs(date).locale(formatLocale(locale)).format(format);
28
28
  }
29
29
  export function formatToDatetime(date, locale = "en") {
30
30
  if (!date) {
@@ -78,7 +78,12 @@ export function formatNumber(n, precision = 6, trim = true) {
78
78
  thousandSeparated: true,
79
79
  ...(precision || precision === 0) && { mantissa: precision }
80
80
  };
81
- return trim ? trimEnd(num.format(options), "0.") : num.format(options);
81
+ const result = num.format(options);
82
+ if (!trim) {
83
+ return result;
84
+ }
85
+ const [left, right] = result.split(".");
86
+ return right ? [left, trimEnd(right, "0")].filter(Boolean).join(".") : left;
82
87
  }
83
88
  export const formatPrice = (price, currency, unit_label, quantity = 1, bn = true, locale = "en") => {
84
89
  if (price.custom_unit_amount) {
@@ -31,7 +31,11 @@ const createOrUpdateDonation = (settings, livemode = true) => {
31
31
  const supporterCache = {};
32
32
  const fetchSupporters = target => {
33
33
  if (!supporterCache[target]) {
34
- supporterCache[target] = _api.default.get(`/api/donations?&target=${target}`).then(res => res.data).finally(() => {
34
+ supporterCache[target] = _api.default.get("/api/donations", {
35
+ params: {
36
+ target
37
+ }
38
+ }).then(res => res.data).finally(() => {
35
39
  setTimeout(() => {
36
40
  delete supporterCache[target];
37
41
  }, 3e3);
@@ -41,7 +45,7 @@ const fetchSupporters = target => {
41
45
  };
42
46
  function SupporterAvatar({
43
47
  supporters = [],
44
- total,
48
+ total = 0,
45
49
  currency,
46
50
  method
47
51
  }) {
@@ -86,7 +90,7 @@ function SupporterAvatar({
86
90
  }
87
91
  function SupporterTable({
88
92
  supporters = [],
89
- total,
93
+ total = 0,
90
94
  currency,
91
95
  method
92
96
  }) {
@@ -8,5 +8,9 @@ var _util = require("../util");
8
8
  function SafeGuard({
9
9
  children
10
10
  }) {
11
- return (0, _util.isPaymentKitMounted)() ? children : null;
11
+ const mounted = (0, _util.isPaymentKitMounted)();
12
+ if (mounted === false) {
13
+ console.warn(`PaymentKit is required to use this feature: https://store.blocklet.dev/blocklets/${_util.PAYMENT_KIT_DID}`);
14
+ }
15
+ return mounted ? children : null;
12
16
  }
@@ -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 _ahooks = require("ahooks");
12
13
  var _ufo = require("ufo");
13
14
  var _api = _interopRequireDefault(require("../../api"));
@@ -103,7 +104,7 @@ function CustomerInvoiceList({
103
104
  }
104
105
  const hasMore = data && data.list.length < data.count;
105
106
  const grouped = groupByDate(data.list);
106
- return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
107
+ return /* @__PURE__ */(0, _jsxRuntime.jsxs)(Root, {
107
108
  direction: "column",
108
109
  gap: 1,
109
110
  sx: {
@@ -121,10 +122,7 @@ function CustomerInvoiceList({
121
122
  }), invoices.map(invoice => {
122
123
  const link = getInvoiceLink(invoice, action);
123
124
  return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
124
- direction: {
125
- xs: "column",
126
- sm: "row"
127
- },
125
+ direction: "row",
128
126
  sx: {
129
127
  my: 1
130
128
  },
@@ -135,7 +133,7 @@ function CustomerInvoiceList({
135
133
  },
136
134
  flexWrap: "nowrap",
137
135
  children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
138
- flex: 3,
136
+ flex: 2,
139
137
  children: /* @__PURE__ */(0, _jsxRuntime.jsx)("a", {
140
138
  href: link.url,
141
139
  target: link.external ? "_blank" : target,
@@ -147,35 +145,45 @@ function CustomerInvoiceList({
147
145
  children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
148
146
  component: "span",
149
147
  children: invoice.number
150
- }), link.external && /* @__PURE__ */(0, _jsxRuntime.jsx)(_iconsMaterial.OpenInNewOutlined, {
151
- fontSize: "small",
152
- sx: {
153
- color: "text.secondary"
154
- }
148
+ }), link.external && /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Hidden, {
149
+ mdDown: true,
150
+ children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_iconsMaterial.OpenInNewOutlined, {
151
+ fontSize: "small",
152
+ sx: {
153
+ color: "text.secondary"
154
+ }
155
+ })
155
156
  })]
156
157
  })
157
158
  })
158
159
  }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
159
- flex: 3,
160
+ flex: 1,
161
+ textAlign: "right",
160
162
  children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
161
- children: (0, _util.formatToDate)(invoice.created_at)
163
+ children: (0, _util.formatToDate)(invoice.created_at, "en", "HH:mm:ss")
162
164
  })
163
165
  }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
164
- flex: 2,
166
+ flex: 1,
167
+ textAlign: "right",
165
168
  children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Typography, {
166
- textAlign: "right",
167
169
  children: [(0, _util.formatBNStr)(invoice.total, invoice.paymentCurrency.decimal), "\xA0", invoice.paymentCurrency.symbol]
168
170
  })
169
171
  }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
170
- flex: 2,
172
+ flex: 1,
173
+ textAlign: "right",
171
174
  children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_status.default, {
172
175
  label: invoice.status,
173
176
  color: (0, _util.getInvoiceStatusColor)(invoice.status)
174
177
  })
175
- }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
176
- flex: 4,
177
- children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
178
- children: invoice.description || invoice.id
178
+ }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Hidden, {
179
+ mdDown: true,
180
+ children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
181
+ flex: 2,
182
+ className: "invoice-description",
183
+ textAlign: "right",
184
+ children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
185
+ children: invoice.description || invoice.id
186
+ })
179
187
  })
180
188
  })]
181
189
  }, invoice.id);
@@ -209,4 +217,14 @@ CustomerInvoiceList.defaultProps = {
209
217
  pageSize: 10,
210
218
  target: "_self",
211
219
  action: ""
212
- };
220
+ };
221
+ const Root = (0, _system.styled)(_material.Stack)`
222
+ @media (max-width: 600px) {
223
+ .invoice-description {
224
+ display: none !important;
225
+ }
226
+ svg[data-testid='OpenInNewOutlinedIcon'] {
227
+ display: none !important;
228
+ }
229
+ }
230
+ `;
package/lib/util.d.ts CHANGED
@@ -3,15 +3,15 @@ import type { PaymentDetails, PriceCurrency, PriceRecurring, TLineItemExpanded,
3
3
  export declare const PAYMENT_KIT_DID = "z2qaCNvKMv5GjouKdcDWexv6WqtHbpNPQDnAk";
4
4
  export declare const isPaymentKitMounted: () => any;
5
5
  export declare const getPrefix: () => any;
6
- export declare function formatToDate(date: Date | string | number, locale?: string): any;
6
+ export declare function formatToDate(date: Date | string | number, locale?: string, format?: string): any;
7
7
  export declare function formatToDatetime(date: Date | string | number, locale?: string): any;
8
8
  export declare function formatTime(date: Date | string | number, format?: string, locale?: string): any;
9
9
  export declare function formatDateTime(date: Date | string | number, locale?: string): any;
10
10
  export declare const formatLocale: (locale?: string) => string;
11
11
  export declare const formatPrettyMsLocale: (locale: string) => "zh_CN" | "en_US";
12
12
  export declare const formatError: (err: any) => any;
13
- export declare function formatBNStr(str?: string, decimals?: number, precision?: number, trim?: boolean): any;
14
- export declare function formatNumber(n: number | string, precision?: number, trim?: boolean): any;
13
+ export declare function formatBNStr(str?: string, decimals?: number, precision?: number, trim?: boolean): string;
14
+ export declare function formatNumber(n: number | string, precision?: number, trim?: boolean): string;
15
15
  export declare const formatPrice: (price: TPrice, currency: TPaymentCurrency, unit_label?: string, quantity?: number, bn?: boolean, locale?: string) => string;
16
16
  export declare const formatPriceAmount: (price: TPrice, currency: TPaymentCurrency, unit_label?: string, quantity?: number, bn?: boolean) => string;
17
17
  export declare function getStatementDescriptor(items: any[]): any;
package/lib/util.js CHANGED
@@ -65,11 +65,11 @@ const getPrefix = () => {
65
65
  return window.blocklet?.prefix;
66
66
  };
67
67
  exports.getPrefix = getPrefix;
68
- function formatToDate(date, locale = "en") {
68
+ function formatToDate(date, locale = "en", format = "YYYY-MM-DD HH:mm:ss") {
69
69
  if (!date) {
70
70
  return "-";
71
71
  }
72
- return (0, _dayjs.default)(date).locale(formatLocale(locale)).format("YYYY-MM-DD HH:mm:ss");
72
+ return (0, _dayjs.default)(date).locale(formatLocale(locale)).format(format);
73
73
  }
74
74
  function formatToDatetime(date, locale = "en") {
75
75
  if (!date) {
@@ -132,7 +132,12 @@ function formatNumber(n, precision = 6, trim = true) {
132
132
  mantissa: precision
133
133
  })
134
134
  };
135
- return trim ? (0, _trimEnd.default)(num.format(options), "0.") : num.format(options);
135
+ const result = num.format(options);
136
+ if (!trim) {
137
+ return result;
138
+ }
139
+ const [left, right] = result.split(".");
140
+ return right ? [left, (0, _trimEnd.default)(right, "0")].filter(Boolean).join(".") : left;
136
141
  }
137
142
  const formatPrice = (price, currency, unit_label, quantity = 1, bn = true, locale = "en") => {
138
143
  if (price.custom_unit_amount) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/payment-react",
3
- "version": "1.13.212",
3
+ "version": "1.13.214",
4
4
  "description": "Reusable react components for payment kit v2",
5
5
  "keywords": [
6
6
  "react",
@@ -90,7 +90,7 @@
90
90
  "@babel/core": "^7.23.9",
91
91
  "@babel/preset-env": "^7.23.9",
92
92
  "@babel/preset-react": "^7.23.3",
93
- "@blocklet/payment-types": "1.13.212",
93
+ "@blocklet/payment-types": "1.13.214",
94
94
  "@storybook/addon-essentials": "^7.6.13",
95
95
  "@storybook/addon-interactions": "^7.6.13",
96
96
  "@storybook/addon-links": "^7.6.13",
@@ -119,5 +119,5 @@
119
119
  "vite-plugin-babel": "^1.2.0",
120
120
  "vite-plugin-node-polyfills": "^0.21.0"
121
121
  },
122
- "gitHead": "942de3b017723af85a6c271a7e4ddd35443bc84d"
122
+ "gitHead": "430206bb27ea5749a12717d5bd3caf00a04b610a"
123
123
  }
@@ -64,7 +64,7 @@ const supporterCache: { [key: string]: Promise<DonateHistory> } = {};
64
64
  const fetchSupporters = (target: string): Promise<DonateHistory> => {
65
65
  if (!supporterCache[target]) {
66
66
  supporterCache[target] = api
67
- .get(`/api/donations?&target=${target}`)
67
+ .get('/api/donations', { params: { target } })
68
68
  .then((res) => res.data)
69
69
  .finally(() => {
70
70
  setTimeout(() => {
@@ -77,7 +77,7 @@ const fetchSupporters = (target: string): Promise<DonateHistory> => {
77
77
  };
78
78
 
79
79
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
80
- function SupporterAvatar({ supporters = [], total, currency, method }: DonateHistory) {
80
+ function SupporterAvatar({ supporters = [], total = 0, currency, method }: DonateHistory) {
81
81
  const { t } = useLocaleContext();
82
82
  const customers = uniqBy(supporters, 'customer_did');
83
83
  return (
@@ -114,7 +114,7 @@ function SupporterAvatar({ supporters = [], total, currency, method }: DonateHis
114
114
  }
115
115
 
116
116
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
117
- function SupporterTable({ supporters = [], total, currency, method }: DonateHistory) {
117
+ function SupporterTable({ supporters = [], total = 0, currency, method }: DonateHistory) {
118
118
  const { t } = useLocaleContext();
119
119
  return (
120
120
  <Box display="flex" flexDirection="column" alignItems="center" sx={{ width: '100%' }} gap={{ xs: 0.5, sm: 1 }}>
@@ -1,5 +1,9 @@
1
- import { isPaymentKitMounted } from '../util';
1
+ import { PAYMENT_KIT_DID, isPaymentKitMounted } from '../util';
2
2
 
3
3
  export default function SafeGuard({ children }: { children: any }) {
4
- return isPaymentKitMounted() ? children : null;
4
+ const mounted = isPaymentKitMounted();
5
+ if (mounted === false) {
6
+ console.warn(`PaymentKit is required to use this feature: https://store.blocklet.dev/blocklets/${PAYMENT_KIT_DID}`);
7
+ }
8
+ return mounted ? children : null;
5
9
  }
@@ -2,7 +2,8 @@
2
2
  import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
3
3
  import type { Paginated, TInvoiceExpanded, TSubscription } from '@blocklet/payment-types';
4
4
  import { OpenInNewOutlined } from '@mui/icons-material';
5
- import { Box, Button, CircularProgress, Stack, Typography } from '@mui/material';
5
+ import { Box, Button, CircularProgress, Hidden, Stack, Typography } from '@mui/material';
6
+ import { styled } from '@mui/system';
6
7
  import { useInfiniteScroll } from 'ahooks';
7
8
  import { joinURL } from 'ufo';
8
9
 
@@ -109,7 +110,7 @@ export default function CustomerInvoiceList({
109
110
  const grouped = groupByDate(data.list as any);
110
111
 
111
112
  return (
112
- <Stack direction="column" gap={1} sx={{ mt: 1 }}>
113
+ <Root direction="column" gap={1} sx={{ mt: 1 }}>
113
114
  {Object.entries(grouped).map(([date, invoices]) => (
114
115
  <Box key={date}>
115
116
  <Typography sx={{ fontWeight: 'bold', color: 'text.secondary', mt: 2, mb: 1 }}>{date}</Typography>
@@ -118,10 +119,7 @@ export default function CustomerInvoiceList({
118
119
  return (
119
120
  <Stack
120
121
  key={invoice.id}
121
- direction={{
122
- xs: 'column',
123
- sm: 'row',
124
- }}
122
+ direction="row"
125
123
  sx={{ my: 1 }}
126
124
  gap={{
127
125
  xs: 0.5,
@@ -129,29 +127,35 @@ export default function CustomerInvoiceList({
129
127
  md: 3,
130
128
  }}
131
129
  flexWrap="nowrap">
132
- <Box flex={3}>
130
+ <Box flex={2}>
133
131
  <a href={link.url} target={link.external ? '_blank' : target} rel="noreferrer">
134
132
  <Stack direction="row" alignItems="center" spacing={0.5}>
135
133
  <Typography component="span">{invoice.number}</Typography>
136
- {link.external && <OpenInNewOutlined fontSize="small" sx={{ color: 'text.secondary' }} />}
134
+ {link.external && (
135
+ <Hidden mdDown>
136
+ <OpenInNewOutlined fontSize="small" sx={{ color: 'text.secondary' }} />
137
+ </Hidden>
138
+ )}
137
139
  </Stack>
138
140
  </a>
139
141
  </Box>
140
- <Box flex={3}>
141
- <Typography>{formatToDate(invoice.created_at)}</Typography>
142
+ <Box flex={1} textAlign="right">
143
+ <Typography>{formatToDate(invoice.created_at, 'en', 'HH:mm:ss')}</Typography>
142
144
  </Box>
143
- <Box flex={2}>
144
- <Typography textAlign="right">
145
+ <Box flex={1} textAlign="right">
146
+ <Typography>
145
147
  {formatBNStr(invoice.total, invoice.paymentCurrency.decimal)}&nbsp;
146
148
  {invoice.paymentCurrency.symbol}
147
149
  </Typography>
148
150
  </Box>
149
- <Box flex={2}>
151
+ <Box flex={1} textAlign="right">
150
152
  <Status label={invoice.status} color={getInvoiceStatusColor(invoice.status)} />
151
153
  </Box>
152
- <Box flex={4}>
153
- <Typography>{invoice.description || invoice.id}</Typography>
154
- </Box>
154
+ <Hidden mdDown>
155
+ <Box flex={2} className="invoice-description" textAlign="right">
156
+ <Typography>{invoice.description || invoice.id}</Typography>
157
+ </Box>
158
+ </Hidden>
155
159
  </Stack>
156
160
  );
157
161
  })}
@@ -171,7 +175,7 @@ export default function CustomerInvoiceList({
171
175
  </Typography>
172
176
  )}
173
177
  </Box>
174
- </Stack>
178
+ </Root>
175
179
  );
176
180
  }
177
181
 
@@ -184,3 +188,14 @@ CustomerInvoiceList.defaultProps = {
184
188
  target: '_self',
185
189
  action: '',
186
190
  };
191
+
192
+ const Root = styled(Stack)`
193
+ @media (max-width: 600px) {
194
+ .invoice-description {
195
+ display: none !important;
196
+ }
197
+ svg[data-testid='OpenInNewOutlinedIcon'] {
198
+ display: none !important;
199
+ }
200
+ }
201
+ `;
package/src/util.ts CHANGED
@@ -40,12 +40,12 @@ export const getPrefix = () => {
40
40
  return window.blocklet?.prefix;
41
41
  };
42
42
 
43
- export function formatToDate(date: Date | string | number, locale = 'en') {
43
+ export function formatToDate(date: Date | string | number, locale = 'en', format = 'YYYY-MM-DD HH:mm:ss') {
44
44
  if (!date) {
45
45
  return '-';
46
46
  }
47
47
 
48
- return dayjs(date).locale(formatLocale(locale)).format('YYYY-MM-DD HH:mm:ss');
48
+ return dayjs(date).locale(formatLocale(locale)).format(format);
49
49
  }
50
50
 
51
51
  export function formatToDatetime(date: Date | string | number, locale = 'en') {
@@ -118,7 +118,12 @@ export function formatNumber(n: number | string, precision: number = 6, trim: bo
118
118
  thousandSeparated: true,
119
119
  ...((precision || precision === 0) && { mantissa: precision }),
120
120
  };
121
- return trim ? trimEnd(num.format(options), '0.') : num.format(options);
121
+ const result = num.format(options);
122
+ if (!trim) {
123
+ return result;
124
+ }
125
+ const [left, right] = result.split('.');
126
+ return right ? [left, trimEnd(right, '0')].filter(Boolean).join('.') : left;
122
127
  }
123
128
 
124
129
  export const formatPrice = (