@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.
Files changed (104) hide show
  1. package/es/checkout/donate.js +7 -5
  2. package/es/checkout/form.js +2 -2
  3. package/es/checkout/table.js +2 -2
  4. package/es/components/blockchain/gas.js +1 -1
  5. package/es/components/blockchain/tx.js +1 -1
  6. package/es/components/confirm.d.ts +4 -2
  7. package/es/components/confirm.js +5 -2
  8. package/es/components/pricing-table.js +1 -1
  9. package/es/components/safe-guard.js +1 -1
  10. package/es/contexts/payment.js +2 -2
  11. package/es/history/invoice/list.js +62 -10
  12. package/es/history/mini-invoice/list.js +16 -8
  13. package/es/history/payment/list.js +2 -2
  14. package/es/hooks/subscription.d.ts +7 -0
  15. package/es/hooks/subscription.js +55 -0
  16. package/es/index.d.ts +4 -3
  17. package/es/index.js +4 -3
  18. package/es/{api.js → libs/api.js} +6 -2
  19. package/es/libs/did-connect.d.ts +10 -0
  20. package/es/libs/did-connect.js +11 -0
  21. package/es/{util.d.ts → libs/util.d.ts} +1 -1
  22. package/es/{util.js → libs/util.js} +1 -1
  23. package/es/locales/en.js +1 -0
  24. package/es/locales/zh.js +1 -0
  25. package/es/payment/form/index.js +28 -6
  26. package/es/payment/form/phone.js +1 -1
  27. package/es/payment/header.js +1 -1
  28. package/es/payment/index.js +9 -2
  29. package/es/payment/product-card.js +34 -14
  30. package/es/payment/product-item.js +26 -16
  31. package/es/payment/summary.js +12 -3
  32. package/es/types/shims.d.ts +1 -3
  33. package/lib/checkout/donate.js +6 -5
  34. package/lib/checkout/form.js +2 -2
  35. package/lib/checkout/table.js +2 -2
  36. package/lib/components/blockchain/gas.js +1 -1
  37. package/lib/components/blockchain/tx.js +1 -1
  38. package/lib/components/confirm.d.ts +4 -2
  39. package/lib/components/confirm.js +5 -2
  40. package/lib/components/pricing-table.js +1 -1
  41. package/lib/components/safe-guard.js +1 -1
  42. package/lib/contexts/payment.js +2 -2
  43. package/lib/history/invoice/list.js +77 -9
  44. package/lib/history/mini-invoice/list.js +17 -3
  45. package/lib/history/payment/list.js +2 -2
  46. package/lib/hooks/subscription.d.ts +7 -0
  47. package/lib/hooks/subscription.js +62 -0
  48. package/lib/index.d.ts +4 -3
  49. package/lib/index.js +17 -5
  50. package/lib/{api.js → libs/api.js} +5 -2
  51. package/lib/libs/did-connect.d.ts +10 -0
  52. package/lib/libs/did-connect.js +16 -0
  53. package/lib/{util.d.ts → libs/util.d.ts} +1 -1
  54. package/lib/{util.js → libs/util.js} +1 -1
  55. package/lib/locales/en.js +1 -0
  56. package/lib/locales/zh.js +1 -0
  57. package/lib/payment/form/index.js +35 -9
  58. package/lib/payment/form/phone.js +1 -1
  59. package/lib/payment/header.js +1 -1
  60. package/lib/payment/index.js +9 -2
  61. package/lib/payment/product-card.js +10 -0
  62. package/lib/payment/product-item.js +3 -2
  63. package/lib/payment/summary.js +4 -2
  64. package/lib/types/shims.d.ts +1 -3
  65. package/package.json +31 -30
  66. package/src/checkout/donate.tsx +7 -5
  67. package/src/checkout/form.tsx +2 -2
  68. package/src/checkout/table.tsx +2 -2
  69. package/src/components/blockchain/gas.tsx +1 -1
  70. package/src/components/blockchain/tx.tsx +1 -1
  71. package/src/components/confirm.tsx +7 -3
  72. package/src/components/pricing-table.tsx +1 -1
  73. package/src/components/safe-guard.tsx +1 -1
  74. package/src/contexts/payment.tsx +2 -2
  75. package/src/history/invoice/list.tsx +83 -19
  76. package/src/history/mini-invoice/list.tsx +19 -8
  77. package/src/history/payment/list.tsx +2 -2
  78. package/src/hooks/subscription.ts +68 -0
  79. package/src/index.ts +4 -3
  80. package/src/{api.ts → libs/api.ts} +7 -2
  81. package/src/libs/did-connect.ts +20 -0
  82. package/src/{util.ts → libs/util.ts} +4 -3
  83. package/src/locales/en.tsx +1 -0
  84. package/src/locales/zh.tsx +1 -0
  85. package/src/payment/form/index.tsx +36 -5
  86. package/src/payment/form/phone.tsx +1 -1
  87. package/src/payment/header.tsx +1 -1
  88. package/src/payment/index.tsx +9 -2
  89. package/src/payment/product-card.tsx +13 -3
  90. package/src/payment/product-item.tsx +7 -2
  91. package/src/payment/summary.tsx +7 -3
  92. package/src/types/shims.d.ts +1 -3
  93. /package/es/{api.d.ts → libs/api.d.ts} +0 -0
  94. /package/es/{dayjs.d.ts → libs/dayjs.d.ts} +0 -0
  95. /package/es/{dayjs.js → libs/dayjs.js} +0 -0
  96. /package/es/{theme.d.ts → libs/theme.d.ts} +0 -0
  97. /package/es/{theme.js → libs/theme.js} +0 -0
  98. /package/lib/{api.d.ts → libs/api.d.ts} +0 -0
  99. /package/lib/{dayjs.d.ts → libs/dayjs.d.ts} +0 -0
  100. /package/lib/{dayjs.js → libs/dayjs.js} +0 -0
  101. /package/lib/{theme.d.ts → libs/theme.d.ts} +0 -0
  102. /package/lib/{theme.js → libs/theme.js} +0 -0
  103. /package/src/{dayjs.ts → libs/dayjs.ts} +0 -0
  104. /package/src/{theme.ts → libs/theme.ts} +0 -0
@@ -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 });
@@ -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 { findCurrency, formatError, getStatementDescriptor, isValidCountry } from "../util.js";
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(Stack, { direction: "column", alignItems: "flex-start", justifyContent: "space-around", children: [
14
- /* @__PURE__ */ jsx(Typography, { variant: "body1", sx: { fontWeight: 500, mb: 0.5, lineHeight: 1 }, color: "text.primary", children: name }),
15
- description && /* @__PURE__ */ jsx(
16
- Typography,
17
- {
18
- variant: "body1",
19
- sx: { fontSize: "0.85rem", mb: 0.5, lineHeight: 1, textAlign: "left" },
20
- color: "text.secondary",
21
- children: description
22
- }
23
- ),
24
- extra && /* @__PURE__ */ jsx(Typography, { variant: "body1", sx: { fontSize: "0.85rem" }, color: "text.secondary", children: extra })
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(Stack, { direction: "row", alignItems: "center", justifyContent: "space-between", sx: { width: "100%" }, children: [
30
- /* @__PURE__ */ jsx(
31
- ProductCard,
32
- {
33
- logo: item.price.product?.images[0],
34
- name: item.price.product?.name,
35
- description: item.price.product?.description,
36
- 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
37
- }
38
- ),
39
- /* @__PURE__ */ jsxs(Stack, { direction: "column", alignItems: "flex-end", flex: 1, children: [
40
- /* @__PURE__ */ jsx(Typography, { sx: { color: "text.primary", fontWeight: 500 }, gutterBottom: true, children: pricing.primary }),
41
- pricing.secondary && /* @__PURE__ */ jsx(Typography, { sx: { fontSize: "0.85rem", color: "text.secondary" }, children: pricing.secondary })
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: [
@@ -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 { formatAmount, formatCheckoutHeadlines, getPriceUintAmountByCurrency } from "../util.js";
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(Typography, { component: "div", sx: { fontWeight: 500, fontSize: "1.15rem", color: "text.secondary" }, children: action || headlines.action }),
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
  ] }),
@@ -13,6 +13,4 @@ declare module '@blocklet/*';
13
13
 
14
14
  declare module 'pretty-ms-i18n';
15
15
 
16
- declare interface Window {
17
- blocklet: any;
18
- }
16
+ declare var blocklet: import('@blocklet/sdk').WindowBlocklet;
@@ -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 _util = require("../util");
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({
@@ -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) => {
@@ -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 _util = require("../util");
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
- cancel?: string | React.ReactNode;
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: "error",
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 = {};
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  module.exports = SafeGuard;
7
- var _util = require("../util");
7
+ var _util = require("../libs/util");
8
8
  function SafeGuard({
9
9
  children
10
10
  }) {
@@ -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 _util = require("../../util");
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 size = pageSize || 10;
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 _util = require("../../util");
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: (0, _ufo.joinURL)(window.location.origin, (0, _util.getPrefix)(), `/customer/subscription/${subscription.id}?source=embed`),
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 _util = require("../../util");
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,7 @@
1
+ /**
2
+ * @description channel 的值不能包含分隔符 / . : 等,否则前端接受不到事件
3
+ * @export
4
+ * @param {string} channel
5
+ * @return {*}
6
+ */
7
+ export declare function useSubscription(channel: string): any;
@@ -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
+ }