@blocklet/payment-react 1.13.179 → 1.13.180
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.
- package/es/history/invoice/list.js +2 -3
- package/es/history/mini-invoice/list.js +2 -2
- package/es/history/payment/list.js +2 -3
- package/es/util.d.ts +2 -0
- package/es/util.js +16 -0
- package/lib/history/invoice/list.js +5 -6
- package/lib/history/mini-invoice/list.js +8 -9
- package/lib/history/payment/list.js +4 -5
- package/lib/util.d.ts +2 -0
- package/lib/util.js +22 -1
- package/package.json +4 -3
- package/src/history/invoice/list.tsx +2 -3
- package/src/history/mini-invoice/list.tsx +2 -2
- package/src/history/payment/list.tsx +2 -3
- package/src/util.ts +18 -0
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
|
|
3
3
|
import { Box, Button, CircularProgress, Stack, Typography } from "@mui/material";
|
|
4
|
-
import { fromUnitToToken } from "@ocap/util";
|
|
5
4
|
import { useInfiniteScroll } from "ahooks";
|
|
6
5
|
import { joinURL } from "ufo";
|
|
7
6
|
import api from "../../api.js";
|
|
8
7
|
import Status from "../../components/status.js";
|
|
9
|
-
import { formatToDate, getInvoiceStatusColor, getPrefix } from "../../util.js";
|
|
8
|
+
import { formatBNStr, formatToDate, getInvoiceStatusColor, getPrefix } from "../../util.js";
|
|
10
9
|
const groupByDate = (items) => {
|
|
11
10
|
const grouped = {};
|
|
12
11
|
items.forEach((item) => {
|
|
@@ -87,7 +86,7 @@ export default function CustomerInvoiceList({
|
|
|
87
86
|
) }),
|
|
88
87
|
/* @__PURE__ */ jsx(Box, { flex: 3, children: /* @__PURE__ */ jsx(Typography, { children: formatToDate(invoice.created_at) }) }),
|
|
89
88
|
/* @__PURE__ */ jsx(Box, { flex: 2, children: /* @__PURE__ */ jsxs(Typography, { textAlign: "right", children: [
|
|
90
|
-
|
|
89
|
+
formatBNStr(invoice.total, invoice.paymentCurrency.decimal),
|
|
91
90
|
"\xA0",
|
|
92
91
|
invoice.paymentCurrency.symbol
|
|
93
92
|
] }) }),
|
|
@@ -12,12 +12,12 @@ import {
|
|
|
12
12
|
Stack,
|
|
13
13
|
Typography
|
|
14
14
|
} from "@mui/material";
|
|
15
|
-
import { fromUnitToToken } from "@ocap/util";
|
|
16
15
|
import { useRequest } from "ahooks";
|
|
17
16
|
import { joinURL } from "ufo";
|
|
18
17
|
import api from "../../api.js";
|
|
19
18
|
import Status from "../../components/status.js";
|
|
20
19
|
import {
|
|
20
|
+
formatBNStr,
|
|
21
21
|
formatSubscriptionProduct,
|
|
22
22
|
formatTime,
|
|
23
23
|
formatToDate,
|
|
@@ -102,7 +102,7 @@ export default function MiniInvoiceList() {
|
|
|
102
102
|
return /* @__PURE__ */ jsxs(ListItem, { disableGutters: true, sx: { display: "flex", justifyContent: "space-between" }, children: [
|
|
103
103
|
/* @__PURE__ */ jsx(Typography, { component: "span", sx: { flex: 3 }, children: formatToDate(item.created_at) }),
|
|
104
104
|
/* @__PURE__ */ jsxs(Typography, { component: "span", sx: { flex: 1, textAlign: "right" }, children: [
|
|
105
|
-
|
|
105
|
+
formatBNStr(item.total, item.paymentCurrency.decimal),
|
|
106
106
|
"\xA0",
|
|
107
107
|
item.paymentCurrency.symbol
|
|
108
108
|
] }),
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
|
|
3
3
|
import { Box, Button, CircularProgress, Stack, Typography } from "@mui/material";
|
|
4
|
-
import { fromUnitToToken } from "@ocap/util";
|
|
5
4
|
import { useInfiniteScroll } from "ahooks";
|
|
6
5
|
import api from "../../api.js";
|
|
7
6
|
import TxLink from "../../components/blockchain/tx.js";
|
|
8
7
|
import Status from "../../components/status.js";
|
|
9
|
-
import { formatToDate, getPaymentIntentStatusColor } from "../../util.js";
|
|
8
|
+
import { formatBNStr, formatToDate, getPaymentIntentStatusColor } from "../../util.js";
|
|
10
9
|
const groupByDate = (items) => {
|
|
11
10
|
const grouped = {};
|
|
12
11
|
items.forEach((item) => {
|
|
@@ -65,7 +64,7 @@ export default function CustomerPaymentList({ customer_id }) {
|
|
|
65
64
|
children: [
|
|
66
65
|
/* @__PURE__ */ jsx(Box, { flex: 3, children: /* @__PURE__ */ jsx(Typography, { children: formatToDate(item.created_at) }) }),
|
|
67
66
|
/* @__PURE__ */ jsx(Box, { flex: 2, children: /* @__PURE__ */ jsxs(Typography, { textAlign: "right", children: [
|
|
68
|
-
|
|
67
|
+
formatBNStr(item.amount_received, item.paymentCurrency.decimal),
|
|
69
68
|
"\xA0",
|
|
70
69
|
item.paymentCurrency.symbol
|
|
71
70
|
] }) }),
|
package/es/util.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ export declare function formatDateTime(date: Date | string | number, locale?: st
|
|
|
9
9
|
export declare const formatLocale: (locale?: string) => string;
|
|
10
10
|
export declare const formatPrettyMsLocale: (locale: string) => "zh_CN" | "en_US";
|
|
11
11
|
export declare const formatError: (err: any) => any;
|
|
12
|
+
export declare function formatBNStr(str?: string, decimals?: number, precision?: number): any;
|
|
13
|
+
export declare function formatNumber(n: number | string, precision?: number): any;
|
|
12
14
|
export declare const formatPrice: (price: TPrice, currency: TPaymentCurrency, unit_label?: string, quantity?: number, bn?: boolean, locale?: string) => string;
|
|
13
15
|
export declare const formatPriceAmount: (price: TPrice, currency: TPaymentCurrency, unit_label?: string, quantity?: number, bn?: boolean) => string;
|
|
14
16
|
export declare function getStatementDescriptor(items: any[]): any;
|
package/es/util.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { BN, fromUnitToToken } from "@ocap/util";
|
|
2
|
+
import trimEnd from "lodash/trimEnd";
|
|
3
|
+
import numbro from "numbro";
|
|
2
4
|
import { defaultCountries } from "react-international-phone";
|
|
3
5
|
import dayjs from "./dayjs.js";
|
|
4
6
|
import { t } from "./locales/index.js";
|
|
@@ -60,6 +62,20 @@ export const formatError = (err) => {
|
|
|
60
62
|
}
|
|
61
63
|
return err.message;
|
|
62
64
|
};
|
|
65
|
+
export function formatBNStr(str = "", decimals = 18, precision = 6) {
|
|
66
|
+
return formatNumber(fromUnitToToken(str, decimals), precision);
|
|
67
|
+
}
|
|
68
|
+
export function formatNumber(n, precision = 6) {
|
|
69
|
+
if (!n || n === "0") {
|
|
70
|
+
return "0";
|
|
71
|
+
}
|
|
72
|
+
const num = numbro(n);
|
|
73
|
+
const options = {
|
|
74
|
+
thousandSeparated: true,
|
|
75
|
+
...(precision || precision === 0) && { mantissa: precision }
|
|
76
|
+
};
|
|
77
|
+
return trimEnd(num.format(options), "0.");
|
|
78
|
+
}
|
|
63
79
|
export const formatPrice = (price, currency, unit_label, quantity = 1, bn = true, locale = "en") => {
|
|
64
80
|
const unit = getPriceUintAmountByCurrency(price, currency);
|
|
65
81
|
const amount = bn ? fromUnitToToken(new BN(unit).mul(new BN(quantity)), currency.decimal).toString() : +unit * quantity;
|
|
@@ -7,12 +7,11 @@ module.exports = CustomerInvoiceList;
|
|
|
7
7
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
8
8
|
var _context = require("@arcblock/ux/lib/Locale/context");
|
|
9
9
|
var _material = require("@mui/material");
|
|
10
|
-
var _util = require("@ocap/util");
|
|
11
10
|
var _ahooks = require("ahooks");
|
|
12
11
|
var _ufo = require("ufo");
|
|
13
12
|
var _api = _interopRequireDefault(require("../../api"));
|
|
14
13
|
var _status = _interopRequireDefault(require("../../components/status"));
|
|
15
|
-
var
|
|
14
|
+
var _util = require("../../util");
|
|
16
15
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
16
|
const groupByDate = items => {
|
|
18
17
|
const grouped = {};
|
|
@@ -108,7 +107,7 @@ function CustomerInvoiceList({
|
|
|
108
107
|
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
|
|
109
108
|
flex: 3,
|
|
110
109
|
children: /* @__PURE__ */(0, _jsxRuntime.jsx)("a", {
|
|
111
|
-
href: (0, _ufo.joinURL)(window.location.origin, (0,
|
|
110
|
+
href: (0, _ufo.joinURL)(window.location.origin, (0, _util.getPrefix)(), `/customer/invoice/${invoice.id}?action=${invoice.status === "uncollectible" ? action : ""}`),
|
|
112
111
|
target,
|
|
113
112
|
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
114
113
|
component: "span",
|
|
@@ -118,19 +117,19 @@ function CustomerInvoiceList({
|
|
|
118
117
|
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
|
|
119
118
|
flex: 3,
|
|
120
119
|
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
121
|
-
children: (0,
|
|
120
|
+
children: (0, _util.formatToDate)(invoice.created_at)
|
|
122
121
|
})
|
|
123
122
|
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
|
|
124
123
|
flex: 2,
|
|
125
124
|
children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Typography, {
|
|
126
125
|
textAlign: "right",
|
|
127
|
-
children: [(0, _util.
|
|
126
|
+
children: [(0, _util.formatBNStr)(invoice.total, invoice.paymentCurrency.decimal), "\xA0", invoice.paymentCurrency.symbol]
|
|
128
127
|
})
|
|
129
128
|
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
|
|
130
129
|
flex: 2,
|
|
131
130
|
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_status.default, {
|
|
132
131
|
label: invoice.status,
|
|
133
|
-
color: (0,
|
|
132
|
+
color: (0, _util.getInvoiceStatusColor)(invoice.status)
|
|
134
133
|
})
|
|
135
134
|
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
|
|
136
135
|
flex: 4,
|
|
@@ -7,12 +7,11 @@ module.exports = MiniInvoiceList;
|
|
|
7
7
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
8
8
|
var _context = require("@arcblock/ux/lib/Locale/context");
|
|
9
9
|
var _material = require("@mui/material");
|
|
10
|
-
var _util = require("@ocap/util");
|
|
11
10
|
var _ahooks = require("ahooks");
|
|
12
11
|
var _ufo = require("ufo");
|
|
13
12
|
var _api = _interopRequireDefault(require("../../api"));
|
|
14
13
|
var _status = _interopRequireDefault(require("../../components/status"));
|
|
15
|
-
var
|
|
14
|
+
var _util = require("../../util");
|
|
16
15
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
16
|
const fetchInvoiceData = (params = {}) => {
|
|
18
17
|
const search = new URLSearchParams();
|
|
@@ -54,13 +53,13 @@ function MiniInvoiceList() {
|
|
|
54
53
|
sx: {
|
|
55
54
|
marginRight: "10px"
|
|
56
55
|
},
|
|
57
|
-
children: (0,
|
|
56
|
+
children: (0, _util.formatSubscriptionProduct)(subscription.items)
|
|
58
57
|
})
|
|
59
58
|
}, {
|
|
60
59
|
name: t("common.status"),
|
|
61
60
|
value: /* @__PURE__ */(0, _jsxRuntime.jsx)(_status.default, {
|
|
62
61
|
label: subscription.status,
|
|
63
|
-
color: (0,
|
|
62
|
+
color: (0, _util.getSubscriptionStatusColor)(subscription.status)
|
|
64
63
|
})
|
|
65
64
|
}];
|
|
66
65
|
if (subscription.status === "active" || subscription.status === "trialing") {
|
|
@@ -72,7 +71,7 @@ function MiniInvoiceList() {
|
|
|
72
71
|
fontWeight: "bold",
|
|
73
72
|
marginRight: "10px"
|
|
74
73
|
},
|
|
75
|
-
children: (0,
|
|
74
|
+
children: (0, _util.formatTime)(subscription.current_period_end * 1e3)
|
|
76
75
|
})
|
|
77
76
|
});
|
|
78
77
|
}
|
|
@@ -159,14 +158,14 @@ function MiniInvoiceList() {
|
|
|
159
158
|
sx: {
|
|
160
159
|
flex: 3
|
|
161
160
|
},
|
|
162
|
-
children: (0,
|
|
161
|
+
children: (0, _util.formatToDate)(item.created_at)
|
|
163
162
|
}), /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Typography, {
|
|
164
163
|
component: "span",
|
|
165
164
|
sx: {
|
|
166
165
|
flex: 1,
|
|
167
166
|
textAlign: "right"
|
|
168
167
|
},
|
|
169
|
-
children: [(0, _util.
|
|
168
|
+
children: [(0, _util.formatBNStr)(item.total, item.paymentCurrency.decimal), "\xA0", item.paymentCurrency.symbol]
|
|
170
169
|
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
171
170
|
component: "span",
|
|
172
171
|
sx: {
|
|
@@ -175,7 +174,7 @@ function MiniInvoiceList() {
|
|
|
175
174
|
},
|
|
176
175
|
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_status.default, {
|
|
177
176
|
label: item.status,
|
|
178
|
-
color: (0,
|
|
177
|
+
color: (0, _util.getInvoiceStatusColor)(item.status),
|
|
179
178
|
sx: {
|
|
180
179
|
flex: 2
|
|
181
180
|
}
|
|
@@ -211,7 +210,7 @@ function MiniInvoiceList() {
|
|
|
211
210
|
color: "#fff!important",
|
|
212
211
|
width: subscription.service_actions?.length ? "auto" : "100%"
|
|
213
212
|
},
|
|
214
|
-
href: (0, _ufo.joinURL)(window.location.origin, (0,
|
|
213
|
+
href: (0, _ufo.joinURL)(window.location.origin, (0, _util.getPrefix)(), `/customer/subscription/${subscription.id}`),
|
|
215
214
|
children: t("payment.customer.subscriptions.title")
|
|
216
215
|
})]
|
|
217
216
|
})]
|
|
@@ -7,12 +7,11 @@ module.exports = CustomerPaymentList;
|
|
|
7
7
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
8
8
|
var _context = require("@arcblock/ux/lib/Locale/context");
|
|
9
9
|
var _material = require("@mui/material");
|
|
10
|
-
var _util = require("@ocap/util");
|
|
11
10
|
var _ahooks = require("ahooks");
|
|
12
11
|
var _api = _interopRequireDefault(require("../../api"));
|
|
13
12
|
var _tx = _interopRequireDefault(require("../../components/blockchain/tx"));
|
|
14
13
|
var _status = _interopRequireDefault(require("../../components/status"));
|
|
15
|
-
var
|
|
14
|
+
var _util = require("../../util");
|
|
16
15
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
16
|
const groupByDate = items => {
|
|
18
17
|
const grouped = {};
|
|
@@ -97,19 +96,19 @@ function CustomerPaymentList({
|
|
|
97
96
|
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
|
|
98
97
|
flex: 3,
|
|
99
98
|
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
100
|
-
children: (0,
|
|
99
|
+
children: (0, _util.formatToDate)(item.created_at)
|
|
101
100
|
})
|
|
102
101
|
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
|
|
103
102
|
flex: 2,
|
|
104
103
|
children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Typography, {
|
|
105
104
|
textAlign: "right",
|
|
106
|
-
children: [(0, _util.
|
|
105
|
+
children: [(0, _util.formatBNStr)(item.amount_received, item.paymentCurrency.decimal), "\xA0", item.paymentCurrency.symbol]
|
|
107
106
|
})
|
|
108
107
|
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
|
|
109
108
|
flex: 3,
|
|
110
109
|
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_status.default, {
|
|
111
110
|
label: item.status,
|
|
112
|
-
color: (0,
|
|
111
|
+
color: (0, _util.getPaymentIntentStatusColor)(item.status)
|
|
113
112
|
})
|
|
114
113
|
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
|
|
115
114
|
flex: 3,
|
package/lib/util.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ export declare function formatDateTime(date: Date | string | number, locale?: st
|
|
|
9
9
|
export declare const formatLocale: (locale?: string) => string;
|
|
10
10
|
export declare const formatPrettyMsLocale: (locale: string) => "zh_CN" | "en_US";
|
|
11
11
|
export declare const formatError: (err: any) => any;
|
|
12
|
+
export declare function formatBNStr(str?: string, decimals?: number, precision?: number): any;
|
|
13
|
+
export declare function formatNumber(n: number | string, precision?: number): any;
|
|
12
14
|
export declare const formatPrice: (price: TPrice, currency: TPaymentCurrency, unit_label?: string, quantity?: number, bn?: boolean, locale?: string) => string;
|
|
13
15
|
export declare const formatPriceAmount: (price: TPrice, currency: TPaymentCurrency, unit_label?: string, quantity?: number, bn?: boolean) => string;
|
|
14
16
|
export declare function getStatementDescriptor(items: any[]): any;
|
package/lib/util.js
CHANGED
|
@@ -7,11 +7,14 @@ exports.PAYMENT_KIT_DID = void 0;
|
|
|
7
7
|
exports.findCurrency = findCurrency;
|
|
8
8
|
exports.flattenPaymentMethods = void 0;
|
|
9
9
|
exports.formatAmount = formatAmount;
|
|
10
|
+
exports.formatBNStr = formatBNStr;
|
|
10
11
|
exports.formatCheckoutHeadlines = formatCheckoutHeadlines;
|
|
11
12
|
exports.formatDateTime = formatDateTime;
|
|
12
13
|
exports.formatError = void 0;
|
|
13
14
|
exports.formatLineItemPricing = formatLineItemPricing;
|
|
14
|
-
exports.
|
|
15
|
+
exports.formatLocale = void 0;
|
|
16
|
+
exports.formatNumber = formatNumber;
|
|
17
|
+
exports.formatPriceAmount = exports.formatPrice = exports.formatPrettyMsLocale = void 0;
|
|
15
18
|
exports.formatRecurring = formatRecurring;
|
|
16
19
|
exports.formatSubscriptionProduct = formatSubscriptionProduct;
|
|
17
20
|
exports.formatTime = formatTime;
|
|
@@ -36,6 +39,8 @@ exports.mergeExtraParams = void 0;
|
|
|
36
39
|
exports.sleep = sleep;
|
|
37
40
|
exports.stopEvent = stopEvent;
|
|
38
41
|
var _util = require("@ocap/util");
|
|
42
|
+
var _trimEnd = _interopRequireDefault(require("lodash/trimEnd"));
|
|
43
|
+
var _numbro = _interopRequireDefault(require("numbro"));
|
|
39
44
|
var _reactInternationalPhone = require("react-international-phone");
|
|
40
45
|
var _dayjs = _interopRequireDefault(require("./dayjs"));
|
|
41
46
|
var _locales = require("./locales");
|
|
@@ -106,6 +111,22 @@ const formatError = err => {
|
|
|
106
111
|
return err.message;
|
|
107
112
|
};
|
|
108
113
|
exports.formatError = formatError;
|
|
114
|
+
function formatBNStr(str = "", decimals = 18, precision = 6) {
|
|
115
|
+
return formatNumber((0, _util.fromUnitToToken)(str, decimals), precision);
|
|
116
|
+
}
|
|
117
|
+
function formatNumber(n, precision = 6) {
|
|
118
|
+
if (!n || n === "0") {
|
|
119
|
+
return "0";
|
|
120
|
+
}
|
|
121
|
+
const num = (0, _numbro.default)(n);
|
|
122
|
+
const options = {
|
|
123
|
+
thousandSeparated: true,
|
|
124
|
+
...((precision || precision === 0) && {
|
|
125
|
+
mantissa: precision
|
|
126
|
+
})
|
|
127
|
+
};
|
|
128
|
+
return (0, _trimEnd.default)(num.format(options), "0.");
|
|
129
|
+
}
|
|
109
130
|
const formatPrice = (price, currency, unit_label, quantity = 1, bn = true, locale = "en") => {
|
|
110
131
|
const unit = getPriceUintAmountByCurrency(price, currency);
|
|
111
132
|
const amount = bn ? (0, _util.fromUnitToToken)(new _util.BN(unit).mul(new _util.BN(quantity)), currency.decimal).toString() : +unit * quantity;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/payment-react",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.180",
|
|
4
4
|
"description": "Reusable react components for payment kit v2",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -69,6 +69,7 @@
|
|
|
69
69
|
"flat": "^5.0.2",
|
|
70
70
|
"google-libphonenumber": "^3.2.34",
|
|
71
71
|
"lodash": "^4.17.21",
|
|
72
|
+
"numbro": "^2.4.0",
|
|
72
73
|
"p-wait-for": "3",
|
|
73
74
|
"react-error-boundary": "^4.0.12",
|
|
74
75
|
"react-hook-form": "^7.50.1",
|
|
@@ -89,7 +90,7 @@
|
|
|
89
90
|
"@babel/core": "^7.23.9",
|
|
90
91
|
"@babel/preset-env": "^7.23.9",
|
|
91
92
|
"@babel/preset-react": "^7.23.3",
|
|
92
|
-
"@blocklet/payment-types": "1.13.
|
|
93
|
+
"@blocklet/payment-types": "1.13.180",
|
|
93
94
|
"@storybook/addon-essentials": "^7.6.13",
|
|
94
95
|
"@storybook/addon-interactions": "^7.6.13",
|
|
95
96
|
"@storybook/addon-links": "^7.6.13",
|
|
@@ -118,5 +119,5 @@
|
|
|
118
119
|
"vite-plugin-babel": "^1.2.0",
|
|
119
120
|
"vite-plugin-node-polyfills": "^0.19.0"
|
|
120
121
|
},
|
|
121
|
-
"gitHead": "
|
|
122
|
+
"gitHead": "515023c9584f424628a3e291cdeb9ad5ff8420aa"
|
|
122
123
|
}
|
|
@@ -2,13 +2,12 @@
|
|
|
2
2
|
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
3
3
|
import type { Paginated, TInvoiceExpanded } from '@blocklet/payment-types';
|
|
4
4
|
import { Box, Button, CircularProgress, Stack, Typography } from '@mui/material';
|
|
5
|
-
import { fromUnitToToken } from '@ocap/util';
|
|
6
5
|
import { useInfiniteScroll } from 'ahooks';
|
|
7
6
|
import { joinURL } from 'ufo';
|
|
8
7
|
|
|
9
8
|
import api from '../../api';
|
|
10
9
|
import Status from '../../components/status';
|
|
11
|
-
import { formatToDate, getInvoiceStatusColor, getPrefix } from '../../util';
|
|
10
|
+
import { formatBNStr, formatToDate, getInvoiceStatusColor, getPrefix } from '../../util';
|
|
12
11
|
|
|
13
12
|
const groupByDate = (items: TInvoiceExpanded[]) => {
|
|
14
13
|
const grouped: { [key: string]: TInvoiceExpanded[] } = {};
|
|
@@ -111,7 +110,7 @@ export default function CustomerInvoiceList({
|
|
|
111
110
|
</Box>
|
|
112
111
|
<Box flex={2}>
|
|
113
112
|
<Typography textAlign="right">
|
|
114
|
-
{
|
|
113
|
+
{formatBNStr(invoice.total, invoice.paymentCurrency.decimal)}
|
|
115
114
|
{invoice.paymentCurrency.symbol}
|
|
116
115
|
</Typography>
|
|
117
116
|
</Box>
|
|
@@ -13,13 +13,13 @@ import {
|
|
|
13
13
|
Stack,
|
|
14
14
|
Typography,
|
|
15
15
|
} from '@mui/material';
|
|
16
|
-
import { fromUnitToToken } from '@ocap/util';
|
|
17
16
|
import { useRequest } from 'ahooks';
|
|
18
17
|
import { joinURL } from 'ufo';
|
|
19
18
|
|
|
20
19
|
import api from '../../api';
|
|
21
20
|
import Status from '../../components/status';
|
|
22
21
|
import {
|
|
22
|
+
formatBNStr,
|
|
23
23
|
formatSubscriptionProduct,
|
|
24
24
|
formatTime,
|
|
25
25
|
formatToDate,
|
|
@@ -138,7 +138,7 @@ export default function MiniInvoiceList() {
|
|
|
138
138
|
{formatToDate(item.created_at)}
|
|
139
139
|
</Typography>
|
|
140
140
|
<Typography component="span" sx={{ flex: 1, textAlign: 'right' }}>
|
|
141
|
-
{
|
|
141
|
+
{formatBNStr(item.total, item.paymentCurrency.decimal)}
|
|
142
142
|
{item.paymentCurrency.symbol}
|
|
143
143
|
</Typography>
|
|
144
144
|
<Typography component="span" sx={{ flex: 2, textAlign: 'right' }}>
|
|
@@ -2,13 +2,12 @@
|
|
|
2
2
|
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
3
3
|
import type { Paginated, TPaymentIntentExpanded } from '@blocklet/payment-types';
|
|
4
4
|
import { Box, Button, CircularProgress, Stack, Typography } from '@mui/material';
|
|
5
|
-
import { fromUnitToToken } from '@ocap/util';
|
|
6
5
|
import { useInfiniteScroll } from 'ahooks';
|
|
7
6
|
|
|
8
7
|
import api from '../../api';
|
|
9
8
|
import TxLink from '../../components/blockchain/tx';
|
|
10
9
|
import Status from '../../components/status';
|
|
11
|
-
import { formatToDate, getPaymentIntentStatusColor } from '../../util';
|
|
10
|
+
import { formatBNStr, formatToDate, getPaymentIntentStatusColor } from '../../util';
|
|
12
11
|
|
|
13
12
|
const groupByDate = (items: TPaymentIntentExpanded[]) => {
|
|
14
13
|
const grouped: { [key: string]: TPaymentIntentExpanded[] } = {};
|
|
@@ -85,7 +84,7 @@ export default function CustomerPaymentList({ customer_id }: Props) {
|
|
|
85
84
|
</Box>
|
|
86
85
|
<Box flex={2}>
|
|
87
86
|
<Typography textAlign="right">
|
|
88
|
-
{
|
|
87
|
+
{formatBNStr(item.amount_received, item.paymentCurrency.decimal)}
|
|
89
88
|
{item.paymentCurrency.symbol}
|
|
90
89
|
</Typography>
|
|
91
90
|
</Box>
|
package/src/util.ts
CHANGED
|
@@ -11,6 +11,8 @@ import type {
|
|
|
11
11
|
TSubscriptionItemExpanded,
|
|
12
12
|
} from '@blocklet/payment-types';
|
|
13
13
|
import { BN, fromUnitToToken } from '@ocap/util';
|
|
14
|
+
import trimEnd from 'lodash/trimEnd';
|
|
15
|
+
import numbro from 'numbro';
|
|
14
16
|
import { defaultCountries } from 'react-international-phone';
|
|
15
17
|
|
|
16
18
|
import dayjs from './dayjs';
|
|
@@ -96,6 +98,22 @@ export const formatError = (err: any) => {
|
|
|
96
98
|
return err.message;
|
|
97
99
|
};
|
|
98
100
|
|
|
101
|
+
export function formatBNStr(str: string = '', decimals: number = 18, precision: number = 6) {
|
|
102
|
+
return formatNumber(fromUnitToToken(str, decimals), precision);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function formatNumber(n: number | string, precision: number = 6) {
|
|
106
|
+
if (!n || n === '0') {
|
|
107
|
+
return '0';
|
|
108
|
+
}
|
|
109
|
+
const num = numbro(n);
|
|
110
|
+
const options = {
|
|
111
|
+
thousandSeparated: true,
|
|
112
|
+
...((precision || precision === 0) && { mantissa: precision }),
|
|
113
|
+
};
|
|
114
|
+
return trimEnd(num.format(options), '0.');
|
|
115
|
+
}
|
|
116
|
+
|
|
99
117
|
export const formatPrice = (
|
|
100
118
|
price: TPrice,
|
|
101
119
|
currency: TPaymentCurrency,
|