@blocklet/payment-react 1.13.239 → 1.13.241
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/checkout/donate.js +7 -5
- package/es/checkout/form.js +2 -2
- package/es/checkout/table.js +2 -2
- package/es/components/blockchain/gas.js +1 -1
- package/es/components/blockchain/tx.js +1 -1
- package/es/components/confirm.d.ts +4 -2
- package/es/components/confirm.js +5 -2
- package/es/components/pricing-table.js +1 -1
- package/es/components/safe-guard.js +1 -1
- package/es/contexts/payment.js +2 -2
- package/es/history/invoice/list.js +62 -10
- package/es/history/mini-invoice/list.js +16 -8
- package/es/history/payment/list.js +2 -2
- package/es/hooks/subscription.d.ts +7 -0
- package/es/hooks/subscription.js +55 -0
- package/es/index.d.ts +4 -3
- package/es/index.js +4 -3
- package/es/{api.js → libs/api.js} +6 -2
- package/es/libs/did-connect.d.ts +10 -0
- package/es/libs/did-connect.js +11 -0
- package/es/{util.d.ts → libs/util.d.ts} +1 -1
- package/es/{util.js → libs/util.js} +1 -1
- package/es/locales/en.js +1 -0
- package/es/locales/zh.js +1 -0
- package/es/payment/form/index.js +28 -6
- package/es/payment/form/phone.js +1 -1
- package/es/payment/header.js +1 -1
- package/es/payment/index.js +9 -2
- package/es/payment/product-card.js +34 -14
- package/es/payment/product-item.js +26 -16
- package/es/payment/summary.js +12 -3
- package/es/types/shims.d.ts +1 -3
- package/lib/checkout/donate.js +6 -5
- package/lib/checkout/form.js +2 -2
- package/lib/checkout/table.js +2 -2
- package/lib/components/blockchain/gas.js +1 -1
- package/lib/components/blockchain/tx.js +1 -1
- package/lib/components/confirm.d.ts +4 -2
- package/lib/components/confirm.js +5 -2
- package/lib/components/pricing-table.js +1 -1
- package/lib/components/safe-guard.js +1 -1
- package/lib/contexts/payment.js +2 -2
- package/lib/history/invoice/list.js +77 -9
- package/lib/history/mini-invoice/list.js +17 -3
- package/lib/history/payment/list.js +2 -2
- package/lib/hooks/subscription.d.ts +7 -0
- package/lib/hooks/subscription.js +62 -0
- package/lib/index.d.ts +4 -3
- package/lib/index.js +17 -5
- package/lib/{api.js → libs/api.js} +5 -2
- package/lib/libs/did-connect.d.ts +10 -0
- package/lib/libs/did-connect.js +16 -0
- package/lib/{util.d.ts → libs/util.d.ts} +1 -1
- package/lib/{util.js → libs/util.js} +1 -1
- package/lib/locales/en.js +1 -0
- package/lib/locales/zh.js +1 -0
- package/lib/payment/form/index.js +35 -9
- package/lib/payment/form/phone.js +1 -1
- package/lib/payment/header.js +1 -1
- package/lib/payment/index.js +9 -2
- package/lib/payment/product-card.js +10 -0
- package/lib/payment/product-item.js +3 -2
- package/lib/payment/summary.js +4 -2
- package/lib/types/shims.d.ts +1 -3
- package/package.json +31 -30
- package/src/checkout/donate.tsx +7 -5
- package/src/checkout/form.tsx +2 -2
- package/src/checkout/table.tsx +2 -2
- package/src/components/blockchain/gas.tsx +1 -1
- package/src/components/blockchain/tx.tsx +1 -1
- package/src/components/confirm.tsx +7 -3
- package/src/components/pricing-table.tsx +1 -1
- package/src/components/safe-guard.tsx +1 -1
- package/src/contexts/payment.tsx +2 -2
- package/src/history/invoice/list.tsx +83 -19
- package/src/history/mini-invoice/list.tsx +19 -8
- package/src/history/payment/list.tsx +2 -2
- package/src/hooks/subscription.ts +68 -0
- package/src/index.ts +4 -3
- package/src/{api.ts → libs/api.ts} +7 -2
- package/src/libs/did-connect.ts +20 -0
- package/src/{util.ts → libs/util.ts} +4 -3
- package/src/locales/en.tsx +1 -0
- package/src/locales/zh.tsx +1 -0
- package/src/payment/form/index.tsx +36 -5
- package/src/payment/form/phone.tsx +1 -1
- package/src/payment/header.tsx +1 -1
- package/src/payment/index.tsx +9 -2
- package/src/payment/product-card.tsx +13 -3
- package/src/payment/product-item.tsx +7 -2
- package/src/payment/summary.tsx +7 -3
- package/src/types/shims.d.ts +1 -3
- /package/es/{api.d.ts → libs/api.d.ts} +0 -0
- /package/es/{dayjs.d.ts → libs/dayjs.d.ts} +0 -0
- /package/es/{dayjs.js → libs/dayjs.js} +0 -0
- /package/es/{theme.d.ts → libs/theme.d.ts} +0 -0
- /package/es/{theme.js → libs/theme.js} +0 -0
- /package/lib/{api.d.ts → libs/api.d.ts} +0 -0
- /package/lib/{dayjs.d.ts → libs/dayjs.d.ts} +0 -0
- /package/lib/{dayjs.js → libs/dayjs.js} +0 -0
- /package/lib/{theme.d.ts → libs/theme.d.ts} +0 -0
- /package/lib/{theme.js → libs/theme.js} +0 -0
- /package/src/{dayjs.ts → libs/dayjs.ts} +0 -0
- /package/src/{theme.ts → libs/theme.ts} +0 -0
package/es/payment/header.js
CHANGED
|
@@ -3,7 +3,7 @@ import { useTheme } from "@arcblock/ux/lib/Theme";
|
|
|
3
3
|
import { Avatar, Stack, Typography } from "@mui/material";
|
|
4
4
|
import { useCreation, useLocalStorageState, useSize } from "ahooks";
|
|
5
5
|
import Livemode from "../components/livemode.js";
|
|
6
|
-
import { getStatementDescriptor } from "../util.js";
|
|
6
|
+
import { getStatementDescriptor } from "../libs/util.js";
|
|
7
7
|
import UserButtons from "./form/addon.js";
|
|
8
8
|
export default function PaymentHeader({ checkoutSession }) {
|
|
9
9
|
const [livemode] = useLocalStorageState("livemode", { defaultValue: true });
|
package/es/payment/index.js
CHANGED
|
@@ -8,9 +8,9 @@ import { fromTokenToUnit } from "@ocap/util";
|
|
|
8
8
|
import { useSetState } from "ahooks";
|
|
9
9
|
import { useEffect, useState } from "react";
|
|
10
10
|
import { FormProvider, useForm, useWatch } from "react-hook-form";
|
|
11
|
-
import api from "../api.js";
|
|
12
11
|
import { usePaymentContext } from "../contexts/payment.js";
|
|
13
|
-
import
|
|
12
|
+
import api from "../libs/api.js";
|
|
13
|
+
import { findCurrency, formatError, getStatementDescriptor, isValidCountry } from "../libs/util.js";
|
|
14
14
|
import PaymentError from "./error.js";
|
|
15
15
|
import CheckoutFooter from "./footer.js";
|
|
16
16
|
import PaymentForm from "./form/index.js";
|
|
@@ -332,6 +332,13 @@ export const Root = styled(Box)`
|
|
|
332
332
|
margin-top: ${(props) => props.mode === "standalone" ? "64px" : "0"};
|
|
333
333
|
}
|
|
334
334
|
.cko-product-summary {
|
|
335
|
+
width: 100%;
|
|
336
|
+
}
|
|
337
|
+
.cko-ellipsis {
|
|
338
|
+
width: 100%;
|
|
339
|
+
white-space: nowrap;
|
|
340
|
+
overflow: hidden;
|
|
341
|
+
text-overflow: ellipsis;
|
|
335
342
|
}
|
|
336
343
|
|
|
337
344
|
.cko-payment {
|
|
@@ -2,7 +2,7 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { Avatar, Stack, Typography } from "@mui/material";
|
|
3
3
|
export default function ProductCard({ size, variant, name, logo, description, extra }) {
|
|
4
4
|
const s = { width: size, height: size };
|
|
5
|
-
return /* @__PURE__ */ jsxs(Stack, { direction: "row", alignItems: "flex-start", spacing: 1, flex: 2, children: [
|
|
5
|
+
return /* @__PURE__ */ jsxs(Stack, { direction: "row", alignItems: "flex-start", spacing: 1, flex: 2, sx: { width: "100%" }, children: [
|
|
6
6
|
logo ? (
|
|
7
7
|
// @ts-ignore
|
|
8
8
|
/* @__PURE__ */ jsx(Avatar, { src: logo, alt: name, variant, sx: s })
|
|
@@ -10,19 +10,39 @@ export default function ProductCard({ size, variant, name, logo, description, ex
|
|
|
10
10
|
// @ts-ignore
|
|
11
11
|
/* @__PURE__ */ jsx(Avatar, { variant, sx: s, children: name.slice(0, 1) })
|
|
12
12
|
),
|
|
13
|
-
/* @__PURE__ */ jsxs(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
13
|
+
/* @__PURE__ */ jsxs(
|
|
14
|
+
Stack,
|
|
15
|
+
{
|
|
16
|
+
direction: "column",
|
|
17
|
+
alignItems: "flex-start",
|
|
18
|
+
justifyContent: "space-around",
|
|
19
|
+
sx: { flexShrink: 1, overflow: "hidden" },
|
|
20
|
+
children: [
|
|
21
|
+
/* @__PURE__ */ jsx(
|
|
22
|
+
Typography,
|
|
23
|
+
{
|
|
24
|
+
className: "cko-ellipsis",
|
|
25
|
+
variant: "body1",
|
|
26
|
+
title: name,
|
|
27
|
+
sx: { fontWeight: 500, mb: 0.5, lineHeight: 1 },
|
|
28
|
+
color: "text.primary",
|
|
29
|
+
children: name
|
|
30
|
+
}
|
|
31
|
+
),
|
|
32
|
+
description && /* @__PURE__ */ jsx(
|
|
33
|
+
Typography,
|
|
34
|
+
{
|
|
35
|
+
variant: "body1",
|
|
36
|
+
title: description,
|
|
37
|
+
sx: { fontSize: "0.85rem", mb: 0.5, lineHeight: 1, textAlign: "left" },
|
|
38
|
+
color: "text.secondary",
|
|
39
|
+
children: description
|
|
40
|
+
}
|
|
41
|
+
),
|
|
42
|
+
extra && /* @__PURE__ */ jsx(Typography, { variant: "body1", sx: { fontSize: "0.85rem" }, color: "text.secondary", children: extra })
|
|
43
|
+
]
|
|
44
|
+
}
|
|
45
|
+
)
|
|
26
46
|
] });
|
|
27
47
|
}
|
|
28
48
|
ProductCard.defaultProps = {
|
|
@@ -3,7 +3,7 @@ import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
|
|
|
3
3
|
import { Stack, Typography } from "@mui/material";
|
|
4
4
|
import Status from "../components/status.js";
|
|
5
5
|
import Switch from "../components/switch-button.js";
|
|
6
|
-
import { formatLineItemPricing, formatPrice, formatRecurring, formatUpsellSaving } from "../util.js";
|
|
6
|
+
import { formatLineItemPricing, formatPrice, formatRecurring, formatUpsellSaving } from "../libs/util.js";
|
|
7
7
|
import ProductCard from "./product-card.js";
|
|
8
8
|
ProductItem.defaultProps = {
|
|
9
9
|
mode: "normal",
|
|
@@ -26,21 +26,31 @@ export default function ProductItem({
|
|
|
26
26
|
const canUpsell = mode === "normal" && items.length === 1;
|
|
27
27
|
return /* @__PURE__ */ jsxs(Stack, { direction: "column", alignItems: "flex-start", spacing: 1, sx: { width: "100%" }, children: [
|
|
28
28
|
/* @__PURE__ */ jsxs(Stack, { direction: "column", alignItems: "flex-end", sx: { width: "100%" }, children: [
|
|
29
|
-
/* @__PURE__ */ jsxs(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
29
|
+
/* @__PURE__ */ jsxs(
|
|
30
|
+
Stack,
|
|
31
|
+
{
|
|
32
|
+
direction: "row",
|
|
33
|
+
alignItems: "flex-start",
|
|
34
|
+
spacing: 0.5,
|
|
35
|
+
justifyContent: "space-between",
|
|
36
|
+
sx: { width: "100%" },
|
|
37
|
+
children: [
|
|
38
|
+
/* @__PURE__ */ jsx(
|
|
39
|
+
ProductCard,
|
|
40
|
+
{
|
|
41
|
+
logo: item.price.product?.images[0],
|
|
42
|
+
name: item.price.product?.name,
|
|
43
|
+
description: item.price.product?.description,
|
|
44
|
+
extra: item.price.type === "recurring" && item.price.recurring ? [pricing.quantity, t("common.billed", { rule: `${formatRecurring(item.upsell_price?.recurring || item.price.recurring, true, "per", locale)} ${metered}` })].filter(Boolean).join(", ") : pricing.quantity
|
|
45
|
+
}
|
|
46
|
+
),
|
|
47
|
+
/* @__PURE__ */ jsxs(Stack, { direction: "column", alignItems: "flex-end", flex: 1, children: [
|
|
48
|
+
/* @__PURE__ */ jsx(Typography, { sx: { color: "text.primary", fontWeight: 500 }, gutterBottom: true, children: pricing.primary }),
|
|
49
|
+
pricing.secondary && /* @__PURE__ */ jsx(Typography, { sx: { fontSize: "0.85rem", color: "text.secondary" }, children: pricing.secondary })
|
|
50
|
+
] })
|
|
51
|
+
]
|
|
52
|
+
}
|
|
53
|
+
),
|
|
44
54
|
children
|
|
45
55
|
] }),
|
|
46
56
|
canUpsell && !item.upsell_price_id && item.price.upsell?.upsells_to && /* @__PURE__ */ jsxs(Stack, { direction: "row", alignItems: "center", justifyContent: "space-between", sx: { width: "100%" }, children: [
|
package/es/payment/summary.js
CHANGED
|
@@ -7,9 +7,9 @@ import { BN, fromTokenToUnit } from "@ocap/util";
|
|
|
7
7
|
import { useRequest, useSetState } from "ahooks";
|
|
8
8
|
import noop from "lodash/noop";
|
|
9
9
|
import useBus from "use-bus";
|
|
10
|
-
import api from "../api.js";
|
|
11
10
|
import Status from "../components/status.js";
|
|
12
|
-
import
|
|
11
|
+
import api from "../libs/api.js";
|
|
12
|
+
import { formatAmount, formatCheckoutHeadlines, getPriceUintAmountByCurrency } from "../libs/util.js";
|
|
13
13
|
import PaymentAmount from "./amount.js";
|
|
14
14
|
import ProductDonation from "./product-donation.js";
|
|
15
15
|
import ProductItem from "./product-item.js";
|
|
@@ -143,7 +143,16 @@ export default function PaymentSummary({
|
|
|
143
143
|
};
|
|
144
144
|
return /* @__PURE__ */ jsx(Fade, { in: true, children: /* @__PURE__ */ jsxs(Stack, { className: "cko-product", direction: "column", ...rest, children: [
|
|
145
145
|
/* @__PURE__ */ jsxs(Stack, { className: "cko-product-summary", direction: "column", alignItems: "flex-start", sx: { mb: { xs: 1, sm: 3 } }, children: [
|
|
146
|
-
/* @__PURE__ */ jsx(
|
|
146
|
+
/* @__PURE__ */ jsx(
|
|
147
|
+
Typography,
|
|
148
|
+
{
|
|
149
|
+
className: "cko-ellipsis",
|
|
150
|
+
component: "div",
|
|
151
|
+
title: action || headlines.action,
|
|
152
|
+
sx: { fontWeight: 500, fontSize: "1.15rem", color: "text.secondary" },
|
|
153
|
+
children: action || headlines.action
|
|
154
|
+
}
|
|
155
|
+
),
|
|
147
156
|
/* @__PURE__ */ jsx(PaymentAmount, { amount: headlines.amount }),
|
|
148
157
|
headlines.then && /* @__PURE__ */ jsx(Typography, { component: "div", sx: { fontSize: "0.9rem", color: "text.secondary" }, children: headlines.then })
|
|
149
158
|
] }),
|
package/es/types/shims.d.ts
CHANGED
package/lib/checkout/donate.js
CHANGED
|
@@ -12,9 +12,9 @@ var _ahooks = require("ahooks");
|
|
|
12
12
|
var _omit = _interopRequireDefault(require("lodash/omit"));
|
|
13
13
|
var _unionBy = _interopRequireDefault(require("lodash/unionBy"));
|
|
14
14
|
var _react = require("react");
|
|
15
|
-
var _api = _interopRequireDefault(require("../api"));
|
|
16
15
|
var _tx = _interopRequireDefault(require("../components/blockchain/tx"));
|
|
17
|
-
var
|
|
16
|
+
var _api = _interopRequireDefault(require("../libs/api"));
|
|
17
|
+
var _util = require("../libs/util");
|
|
18
18
|
var _form = _interopRequireDefault(require("./form"));
|
|
19
19
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
20
|
const donationCache = {};
|
|
@@ -29,11 +29,12 @@ const createOrUpdateDonation = (settings, livemode = true) => {
|
|
|
29
29
|
return donationCache[settings.target];
|
|
30
30
|
};
|
|
31
31
|
const supporterCache = {};
|
|
32
|
-
const fetchSupporters = target => {
|
|
32
|
+
const fetchSupporters = (target, livemode = true) => {
|
|
33
33
|
if (!supporterCache[target]) {
|
|
34
34
|
supporterCache[target] = _api.default.get("/api/donations", {
|
|
35
35
|
params: {
|
|
36
|
-
target
|
|
36
|
+
target,
|
|
37
|
+
livemode
|
|
37
38
|
}
|
|
38
39
|
}).then(res => res.data).finally(() => {
|
|
39
40
|
setTimeout(() => {
|
|
@@ -198,7 +199,7 @@ function CheckoutDonate({
|
|
|
198
199
|
exist: false
|
|
199
200
|
});
|
|
200
201
|
const donation = (0, _ahooks.useRequest)(() => createOrUpdateDonation(settings, livemode));
|
|
201
|
-
const supporters = (0, _ahooks.useRequest)(() => donation.data ? fetchSupporters(donation.data.id) : Promise.resolve({}));
|
|
202
|
+
const supporters = (0, _ahooks.useRequest)(() => donation.data ? fetchSupporters(donation.data.id, livemode) : Promise.resolve({}));
|
|
202
203
|
(0, _react.useEffect)(() => {
|
|
203
204
|
if (donation.data && state.supporterLoaded === false) {
|
|
204
205
|
setState({
|
package/lib/checkout/form.js
CHANGED
|
@@ -9,9 +9,9 @@ var _ahooks = require("ahooks");
|
|
|
9
9
|
var _noop = _interopRequireDefault(require("lodash/noop"));
|
|
10
10
|
var _react = require("react");
|
|
11
11
|
var _ufo = require("ufo");
|
|
12
|
-
var _api = _interopRequireDefault(require("../api"));
|
|
12
|
+
var _api = _interopRequireDefault(require("../libs/api"));
|
|
13
|
+
var _util = require("../libs/util");
|
|
13
14
|
var _payment = _interopRequireDefault(require("../payment"));
|
|
14
|
-
var _util = require("../util");
|
|
15
15
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
16
|
const promises = {};
|
|
17
17
|
const startFromPaymentLink = (id, params) => {
|
package/lib/checkout/table.js
CHANGED
|
@@ -11,10 +11,10 @@ var _material = require("@mui/material");
|
|
|
11
11
|
var _system = require("@mui/system");
|
|
12
12
|
var _ahooks = require("ahooks");
|
|
13
13
|
var _react = require("react");
|
|
14
|
-
var _api = _interopRequireDefault(require("../api"));
|
|
15
14
|
var _livemode = _interopRequireDefault(require("../components/livemode"));
|
|
16
15
|
var _pricingTable = _interopRequireDefault(require("../components/pricing-table"));
|
|
17
|
-
var
|
|
16
|
+
var _api = _interopRequireDefault(require("../libs/api"));
|
|
17
|
+
var _util = require("../libs/util");
|
|
18
18
|
var _form = _interopRequireDefault(require("./form"));
|
|
19
19
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
20
|
const fetchData = async id => {
|
|
@@ -9,7 +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 _payment = require("../../contexts/payment");
|
|
12
|
-
var _util2 = require("../../util");
|
|
12
|
+
var _util2 = require("../../libs/util");
|
|
13
13
|
TxGas.defaultProps = {};
|
|
14
14
|
function TxGas(props) {
|
|
15
15
|
const {
|
|
@@ -8,7 +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 _util = require("../../util");
|
|
11
|
+
var _util = require("../../libs/util");
|
|
12
12
|
TxLink.defaultProps = {
|
|
13
13
|
mode: "dashboard",
|
|
14
14
|
align: "left"
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { EventHandler } from 'react';
|
|
2
|
-
declare function ConfirmDialog({ onConfirm, onCancel, title, message, confirm, cancel, loading, }: {
|
|
2
|
+
declare function ConfirmDialog({ onConfirm, onCancel, title, message, confirm, color, cancel, loading, }: {
|
|
3
3
|
onConfirm: EventHandler<any>;
|
|
4
4
|
onCancel: EventHandler<any>;
|
|
5
5
|
title: string | React.ReactNode;
|
|
6
6
|
message: string | React.ReactNode;
|
|
7
7
|
confirm?: string | React.ReactNode;
|
|
8
|
-
|
|
8
|
+
color?: string;
|
|
9
|
+
cancel?: boolean | string | React.ReactNode;
|
|
9
10
|
loading?: boolean;
|
|
10
11
|
}): import("react").JSX.Element;
|
|
11
12
|
declare namespace ConfirmDialog {
|
|
@@ -13,6 +14,7 @@ declare namespace ConfirmDialog {
|
|
|
13
14
|
loading: boolean;
|
|
14
15
|
confirm: string;
|
|
15
16
|
cancel: string;
|
|
17
|
+
color: string;
|
|
16
18
|
};
|
|
17
19
|
}
|
|
18
20
|
export default ConfirmDialog;
|
|
@@ -14,6 +14,7 @@ function ConfirmDialog({
|
|
|
14
14
|
title,
|
|
15
15
|
message,
|
|
16
16
|
confirm,
|
|
17
|
+
color,
|
|
17
18
|
cancel,
|
|
18
19
|
loading
|
|
19
20
|
}) {
|
|
@@ -28,7 +29,7 @@ function ConfirmDialog({
|
|
|
28
29
|
confirmButton: {
|
|
29
30
|
text: confirm || t("common.confirm"),
|
|
30
31
|
props: {
|
|
31
|
-
color
|
|
32
|
+
color,
|
|
32
33
|
size: "small",
|
|
33
34
|
variant: "contained",
|
|
34
35
|
disabled: !!loading
|
|
@@ -41,6 +42,7 @@ function ConfirmDialog({
|
|
|
41
42
|
size: "small"
|
|
42
43
|
}
|
|
43
44
|
},
|
|
45
|
+
showCancelButton: typeof cancel !== "boolean" || !!cancel,
|
|
44
46
|
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
45
47
|
children: message
|
|
46
48
|
})
|
|
@@ -49,5 +51,6 @@ function ConfirmDialog({
|
|
|
49
51
|
ConfirmDialog.defaultProps = {
|
|
50
52
|
loading: false,
|
|
51
53
|
confirm: "",
|
|
52
|
-
cancel: ""
|
|
54
|
+
cancel: "",
|
|
55
|
+
color: "error"
|
|
53
56
|
};
|
|
@@ -13,8 +13,8 @@ var _material = require("@mui/material");
|
|
|
13
13
|
var _system = require("@mui/system");
|
|
14
14
|
var _ahooks = require("ahooks");
|
|
15
15
|
var _react = require("react");
|
|
16
|
+
var _util = require("../libs/util");
|
|
16
17
|
var _amount = _interopRequireDefault(require("../payment/amount"));
|
|
17
|
-
var _util = require("../util");
|
|
18
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
19
|
const groupItemsByRecurring = items => {
|
|
20
20
|
const grouped = {};
|
package/lib/contexts/payment.js
CHANGED
|
@@ -11,8 +11,8 @@ var _jsxRuntime = require("react/jsx-runtime");
|
|
|
11
11
|
var _material = require("@mui/material");
|
|
12
12
|
var _ahooks = require("ahooks");
|
|
13
13
|
var _react = require("react");
|
|
14
|
-
var _api = _interopRequireDefault(require("../api"));
|
|
15
|
-
var _util = require("../util");
|
|
14
|
+
var _api = _interopRequireDefault(require("../libs/api"));
|
|
15
|
+
var _util = require("../libs/util");
|
|
16
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
17
|
const prefix = (0, _util.getPrefix)();
|
|
18
18
|
const PaymentContext = exports.PaymentContext = (0, _react.createContext)({
|
|
@@ -6,14 +6,18 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
module.exports = CustomerInvoiceList;
|
|
7
7
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
8
8
|
var _context = require("@arcblock/ux/lib/Locale/context");
|
|
9
|
+
var _Toast = _interopRequireDefault(require("@arcblock/ux/lib/Toast"));
|
|
9
10
|
var _iconsMaterial = require("@mui/icons-material");
|
|
10
11
|
var _material = require("@mui/material");
|
|
11
12
|
var _system = require("@mui/system");
|
|
12
13
|
var _ahooks = require("ahooks");
|
|
14
|
+
var _react = require("react");
|
|
13
15
|
var _ufo = require("ufo");
|
|
14
|
-
var _api = _interopRequireDefault(require("../../api"));
|
|
15
16
|
var _status = _interopRequireDefault(require("../../components/status"));
|
|
16
|
-
var
|
|
17
|
+
var _payment = require("../../contexts/payment");
|
|
18
|
+
var _subscription = require("../../hooks/subscription");
|
|
19
|
+
var _api = _interopRequireDefault(require("../../libs/api"));
|
|
20
|
+
var _util = require("../../libs/util");
|
|
17
21
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
22
|
const groupByDate = items => {
|
|
19
23
|
const grouped = {};
|
|
@@ -39,11 +43,13 @@ const getInvoiceLink = (invoice, action) => {
|
|
|
39
43
|
if (invoice.id.startsWith("in_")) {
|
|
40
44
|
return {
|
|
41
45
|
external: false,
|
|
46
|
+
connect: invoice.status === "uncollectible",
|
|
42
47
|
url: (0, _ufo.joinURL)(window.location.origin, (0, _util.getPrefix)(), `/customer/invoice/${invoice.id}?action=${invoice.status === "uncollectible" ? action : ""}`)
|
|
43
48
|
};
|
|
44
49
|
}
|
|
45
50
|
return {
|
|
46
51
|
external: true,
|
|
52
|
+
connect: false,
|
|
47
53
|
url: (0, _util.getTxLink)(invoice.paymentMethod, invoice.metadata?.payment_details).link
|
|
48
54
|
};
|
|
49
55
|
};
|
|
@@ -57,16 +63,24 @@ function CustomerInvoiceList({
|
|
|
57
63
|
target,
|
|
58
64
|
action
|
|
59
65
|
}) {
|
|
66
|
+
const size = pageSize || 10;
|
|
67
|
+
const subscription = (0, _subscription.useSubscription)("events");
|
|
60
68
|
const {
|
|
61
69
|
t,
|
|
62
70
|
locale
|
|
63
71
|
} = (0, _context.useLocaleContext)();
|
|
64
|
-
const
|
|
72
|
+
const {
|
|
73
|
+
connect
|
|
74
|
+
} = (0, _payment.usePaymentContext)();
|
|
75
|
+
const [state, setState] = (0, _ahooks.useSetState)({
|
|
76
|
+
paying: ""
|
|
77
|
+
});
|
|
65
78
|
const {
|
|
66
79
|
data,
|
|
67
80
|
loadMore,
|
|
68
81
|
loadingMore,
|
|
69
|
-
loading
|
|
82
|
+
loading,
|
|
83
|
+
reloadAsync
|
|
70
84
|
} = (0, _ahooks.useInfiniteScroll)(d => {
|
|
71
85
|
const page = d ? Math.ceil(d.list.length / size) + 1 : 1;
|
|
72
86
|
return fetchData({
|
|
@@ -80,8 +94,59 @@ function CustomerInvoiceList({
|
|
|
80
94
|
ignore_zero: true
|
|
81
95
|
});
|
|
82
96
|
}, {
|
|
83
|
-
reloadDeps: [customer_id, subscription_id, status]
|
|
97
|
+
reloadDeps: [customer_id, subscription_id, status, include_staking]
|
|
84
98
|
});
|
|
99
|
+
(0, _react.useEffect)(() => {
|
|
100
|
+
if (subscription && customer_id) {
|
|
101
|
+
subscription.on("invoice.paid", async ({
|
|
102
|
+
response
|
|
103
|
+
}) => {
|
|
104
|
+
if (response.customer_id === customer_id) {
|
|
105
|
+
await reloadAsync();
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}, [subscription]);
|
|
110
|
+
const onPay = invoiceId => {
|
|
111
|
+
if (state.paying) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
setState({
|
|
115
|
+
paying: invoiceId
|
|
116
|
+
});
|
|
117
|
+
connect.open({
|
|
118
|
+
action: "collect",
|
|
119
|
+
messages: {
|
|
120
|
+
scan: "",
|
|
121
|
+
title: t(`payment.customer.invoice.${action || "pay"}`),
|
|
122
|
+
success: t(`payment.customer.invoice.${action || "pay"}Success`),
|
|
123
|
+
error: t(`payment.customer.invoice.${action || "pay"}Error`),
|
|
124
|
+
confirm: ""
|
|
125
|
+
},
|
|
126
|
+
extraParams: {
|
|
127
|
+
invoiceId,
|
|
128
|
+
action
|
|
129
|
+
},
|
|
130
|
+
onSuccess: () => {
|
|
131
|
+
connect.close();
|
|
132
|
+
setState({
|
|
133
|
+
paying: ""
|
|
134
|
+
});
|
|
135
|
+
},
|
|
136
|
+
onClose: () => {
|
|
137
|
+
connect.close();
|
|
138
|
+
setState({
|
|
139
|
+
paying: ""
|
|
140
|
+
});
|
|
141
|
+
},
|
|
142
|
+
onError: err => {
|
|
143
|
+
setState({
|
|
144
|
+
paying: ""
|
|
145
|
+
});
|
|
146
|
+
_Toast.default.error((0, _util.formatError)(err));
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
};
|
|
85
150
|
if (loading || !data) {
|
|
86
151
|
return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.CircularProgress, {});
|
|
87
152
|
}
|
|
@@ -185,7 +250,13 @@ function CustomerInvoiceList({
|
|
|
185
250
|
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
|
|
186
251
|
flex: 1,
|
|
187
252
|
textAlign: "right",
|
|
188
|
-
children: action ? /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Button, {
|
|
253
|
+
children: action ? link.connect ? /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Button, {
|
|
254
|
+
variant: "contained",
|
|
255
|
+
color: "primary",
|
|
256
|
+
size: "small",
|
|
257
|
+
onClick: () => onPay(invoice.id),
|
|
258
|
+
children: t("payment.customer.invoice.pay")
|
|
259
|
+
}) : /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Button, {
|
|
189
260
|
component: "a",
|
|
190
261
|
variant: "contained",
|
|
191
262
|
color: "primary",
|
|
@@ -237,9 +308,6 @@ const Root = (0, _system.styled)(_material.Stack)`
|
|
|
237
308
|
.invoice-description {
|
|
238
309
|
display: none !important;
|
|
239
310
|
}
|
|
240
|
-
svg[data-testid='OpenInNewOutlinedIcon'] {
|
|
241
|
-
display: none !important;
|
|
242
|
-
}
|
|
243
311
|
}
|
|
244
312
|
|
|
245
313
|
a.MuiButton-root {
|
|
@@ -8,10 +8,12 @@ var _jsxRuntime = require("react/jsx-runtime");
|
|
|
8
8
|
var _context = require("@arcblock/ux/lib/Locale/context");
|
|
9
9
|
var _material = require("@mui/material");
|
|
10
10
|
var _ahooks = require("ahooks");
|
|
11
|
+
var _react = require("react");
|
|
11
12
|
var _ufo = require("ufo");
|
|
12
|
-
var _api = _interopRequireDefault(require("../../api"));
|
|
13
13
|
var _status = _interopRequireDefault(require("../../components/status"));
|
|
14
|
-
var
|
|
14
|
+
var _api = _interopRequireDefault(require("../../libs/api"));
|
|
15
|
+
var _didConnect = require("../../libs/did-connect");
|
|
16
|
+
var _util = require("../../libs/util");
|
|
15
17
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
18
|
const fetchInvoiceData = (params = {}) => {
|
|
17
19
|
const search = new URLSearchParams();
|
|
@@ -50,6 +52,18 @@ function MiniInvoiceList() {
|
|
|
50
52
|
ignore_zero: true,
|
|
51
53
|
include_staking: true
|
|
52
54
|
}));
|
|
55
|
+
const subscriptionPageUrl = (0, _react.useMemo)(() => {
|
|
56
|
+
if (!subscription) {
|
|
57
|
+
return "#";
|
|
58
|
+
}
|
|
59
|
+
const pageUrl = (0, _ufo.joinURL)(window.location.origin, (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]);
|
|
53
67
|
if (error) {
|
|
54
68
|
return /* @__PURE__ */(0, _jsxRuntime.jsx)(Position, {
|
|
55
69
|
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Alert, {
|
|
@@ -226,7 +240,7 @@ function MiniInvoiceList() {
|
|
|
226
240
|
width: subscription.service_actions?.length ? "auto" : "100%"
|
|
227
241
|
},
|
|
228
242
|
target: "_blank",
|
|
229
|
-
href:
|
|
243
|
+
href: subscriptionPageUrl,
|
|
230
244
|
children: t("payment.customer.subscriptions.view")
|
|
231
245
|
})]
|
|
232
246
|
})]
|
|
@@ -8,10 +8,10 @@ var _jsxRuntime = require("react/jsx-runtime");
|
|
|
8
8
|
var _context = require("@arcblock/ux/lib/Locale/context");
|
|
9
9
|
var _material = require("@mui/material");
|
|
10
10
|
var _ahooks = require("ahooks");
|
|
11
|
-
var _api = _interopRequireDefault(require("../../api"));
|
|
12
11
|
var _tx = _interopRequireDefault(require("../../components/blockchain/tx"));
|
|
13
12
|
var _status = _interopRequireDefault(require("../../components/status"));
|
|
14
|
-
var
|
|
13
|
+
var _api = _interopRequireDefault(require("../../libs/api"));
|
|
14
|
+
var _util = require("../../libs/util");
|
|
15
15
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
16
|
const groupByDate = items => {
|
|
17
17
|
const grouped = {};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useSubscription = useSubscription;
|
|
7
|
+
var _ws = require("@arcblock/ws");
|
|
8
|
+
var _get = _interopRequireDefault(require("lodash/get"));
|
|
9
|
+
var _react = require("react");
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
const RELAY_SOCKET_PREFIX = "/.well-known/service/relay";
|
|
12
|
+
const getAppId = () => (0, _get.default)(window, "blocklet.appPid") || (0, _get.default)(window, "blocklet.appId") || "";
|
|
13
|
+
const getRelayChannel = token => `relay:${getAppId()}:${token}`;
|
|
14
|
+
const getRelayProtocol = () => window.location.protocol === "https:" ? "wss:" : "ws:";
|
|
15
|
+
const getSocketHost = () => new URL(window.location.href).host;
|
|
16
|
+
function useSubscription(channel) {
|
|
17
|
+
const socket = (0, _react.useRef)(null);
|
|
18
|
+
const subscription = (0, _react.useRef)(null);
|
|
19
|
+
(0, _react.useEffect)(() => {
|
|
20
|
+
if (getAppId()) {
|
|
21
|
+
const needReconnect = !socket.current || socket.current.isConnected() === false;
|
|
22
|
+
if (needReconnect) {
|
|
23
|
+
socket.current = new _ws.WsClient(`${getRelayProtocol()}//${getSocketHost()}${RELAY_SOCKET_PREFIX}`, {
|
|
24
|
+
longpollerTimeout: 5e3,
|
|
25
|
+
// connection timeout
|
|
26
|
+
heartbeatIntervalMs: 30 * 1e3
|
|
27
|
+
});
|
|
28
|
+
socket.current.connect();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return () => {
|
|
32
|
+
if (socket.current) {
|
|
33
|
+
socket.current.disconnect();
|
|
34
|
+
socket.current = null;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}, []);
|
|
38
|
+
(0, _react.useEffect)(() => {
|
|
39
|
+
if (channel) {
|
|
40
|
+
let needSubscription = false;
|
|
41
|
+
if (subscription.current) {
|
|
42
|
+
if (subscription.current.channel !== channel) {
|
|
43
|
+
socket.current?.unsubscribe(getRelayChannel(subscription.current.channel));
|
|
44
|
+
needSubscription = true;
|
|
45
|
+
}
|
|
46
|
+
} else {
|
|
47
|
+
needSubscription = true;
|
|
48
|
+
}
|
|
49
|
+
if (needSubscription) {
|
|
50
|
+
subscription.current = socket.current.subscribe(getRelayChannel(channel));
|
|
51
|
+
subscription.current.channel = channel;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return () => {
|
|
55
|
+
if (subscription.current) {
|
|
56
|
+
socket.current?.unsubscribe(getRelayChannel(subscription.current.channel));
|
|
57
|
+
subscription.current = null;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}, [channel]);
|
|
61
|
+
return subscription.current;
|
|
62
|
+
}
|