@abtnode/ux 1.16.25-beta-85e265d1 → 1.16.25-beta-bc165d9b

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.
@@ -22,14 +22,13 @@ import Alert from '@mui/material/Alert';
22
22
  import Button from '@arcblock/ux/lib/Button';
23
23
  import { getAppMissingConfigs, isDeletableBlocklet, hasRunnableComponent, getDisplayName, isInProgress } from '@blocklet/meta/lib/util';
24
24
  import { LocaleContext } from '@arcblock/ux/lib/Locale/context';
25
- import { BLOCKLET_CONTROLLER_STATUS, BLOCKLET_MODES, SUSPENDED_REASON } from '@blocklet/constant';
25
+ import { BLOCKLET_CONTROLLER_STATUS, BLOCKLET_MODES } from '@blocklet/constant';
26
26
  import Toast from '@arcblock/ux/lib/Toast';
27
27
  import { sleep, formatError, isDownloading } from '../util';
28
28
  import { getServerUrl } from './util';
29
29
  import { useNodeContext } from '../contexts/node';
30
30
  import Confirm from '../confirm';
31
31
  import Icons from './icons';
32
- import { useBlockletContext } from '../contexts/blocklet';
33
32
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
34
33
  export default function BlockletActions({
35
34
  blocklet,
@@ -54,14 +53,14 @@ export default function BlockletActions({
54
53
  loading: recommendedUrlLoading,
55
54
  recommendedUrl
56
55
  } = useBlockletUrlEvaluation(blocklet);
57
- const {
58
- nftState
59
- } = useBlockletContext();
60
56
  const inProgress = isInProgress(blocklet.status);
61
- let disableStart = blocklet?.controller?.status?.value === BLOCKLET_CONTROLLER_STATUS.suspended;
62
- if (!nftState?.expired && blocklet?.controller?.status?.reason === SUSPENDED_REASON.expired) {
63
- disableStart = false;
64
- }
57
+ const disableStart = blocklet?.controller?.status?.value === BLOCKLET_CONTROLLER_STATUS.suspended;
58
+
59
+ // TODO: PaymentKitV2 过期恢复后需要能立即启动
60
+ // if (!nftState?.expired && blocklet?.controller?.status?.reason === SUSPENDED_REASON.expired) {
61
+ // disableStart = false;
62
+ // }
63
+
65
64
  const {
66
65
  inService
67
66
  } = node;
@@ -0,0 +1,175 @@
1
+ import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
2
+ import dayjs from '@abtnode/util/lib/dayjs';
3
+ import Chip from '@mui/material/Chip';
4
+ import CircularProgress from '@mui/material/CircularProgress';
5
+ import Popover from '@mui/material/Popover';
6
+ import useMediaQuery from '@mui/material/useMediaQuery';
7
+ import PropTypes from 'prop-types';
8
+ import prettyMs from 'pretty-ms-i18n';
9
+ import { useRef } from 'react';
10
+ import useAsyncRetry from 'react-use/lib/useAsyncRetry';
11
+ import useSetState from 'react-use/lib/useSetState';
12
+ import { useNodeContext } from '../contexts/node';
13
+ import { formatPrettyMsLocale, getSubscriptionUrlV2 } from '../util';
14
+ import ChipLabel from './chip-label';
15
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
16
+ const DEFAULT_LAUNCHER_URL = 'https://launcher.arcblock.io/'; // 兼容: 旧版本的 blocklet.controller 没有 launcherUrl 字段
17
+
18
+ const ALERT_THRESHOLD_MS = 30 * 24 * 60 * 60 * 1000;
19
+ function SubscriptionBlocklet({
20
+ launcherUrl,
21
+ chainHost,
22
+ nftId,
23
+ launcherSessionId,
24
+ ...props
25
+ }) {
26
+ const {
27
+ t,
28
+ locale
29
+ } = useLocaleContext();
30
+ const node = useNodeContext();
31
+ const [state, setState] = useSetState({
32
+ safeIframeRef: null,
33
+ popoverAnchorEl: null
34
+ });
35
+ const iframeRef = useRef(null);
36
+ const isMobile = useMediaQuery(x => x.breakpoints.down('md'));
37
+ const {
38
+ sx = {},
39
+ ...rest
40
+ } = props;
41
+ const typoKey = isMobile ? 'mobile' : 'desktop';
42
+ const asyncState = useAsyncRetry(async () => {
43
+ const [data, subscriptionURL] = await Promise.all([node.api.getLauncherSession({
44
+ input: {
45
+ launcherSessionId,
46
+ launcherUrl
47
+ }
48
+ }), getSubscriptionUrlV2({
49
+ launcherUrl: launcherUrl || DEFAULT_LAUNCHER_URL,
50
+ nftDid: nftId,
51
+ launcherSessionId,
52
+ locale
53
+ })]);
54
+ if (data?.error) {
55
+ throw new Error(data.error);
56
+ }
57
+ return {
58
+ launcherSession: data.launcherSession,
59
+ subscriptionURL
60
+ };
61
+ }, [locale]);
62
+ if (asyncState.loading) {
63
+ return /*#__PURE__*/_jsx(Chip, {
64
+ label: /*#__PURE__*/_jsxs(ChipLabel, {
65
+ children: [!isMobile && t('expiration.desktop.loading'), /*#__PURE__*/_jsx(CircularProgress, {
66
+ size: 16
67
+ })]
68
+ }),
69
+ variant: "success",
70
+ sx: {
71
+ cursor: 'pointer',
72
+ ...sx
73
+ },
74
+ ...rest
75
+ });
76
+ }
77
+ if (asyncState.error) {
78
+ console.error(asyncState.error);
79
+ return /*#__PURE__*/_jsx(Chip, {
80
+ label: /*#__PURE__*/_jsx(ChipLabel, {
81
+ children: t(`expiration.${typoKey}.loadFailed`)
82
+ }),
83
+ color: "error",
84
+ variant: "success",
85
+ sx: {
86
+ cursor: 'pointer',
87
+ ...sx
88
+ },
89
+ ...rest,
90
+ onClick: () => asyncState.retry()
91
+ });
92
+ }
93
+ const handlePopoverClick = event => {
94
+ setState({
95
+ popoverAnchorEl: event.currentTarget
96
+ });
97
+ };
98
+ const handlePopoverClose = () => {
99
+ setState({
100
+ popoverAnchorEl: null
101
+ });
102
+ };
103
+ const launcherSession = asyncState.value?.launcherSession;
104
+ let status = 'success';
105
+ if (['expired', 'terminated'].includes(asyncState.value?.launcherSession?.statusText)) {
106
+ status = 'error';
107
+ }
108
+ let validity = null;
109
+ if (launcherSession.expirationDate && !launcherSession.subscription) {
110
+ const validityMs = dayjs(launcherSession.expirationDate).diff(dayjs(), 'ms');
111
+ validity = t(`expiration.${typoKey}.tips.${status}`, {
112
+ validity: prettyMs(validityMs, {
113
+ locale: formatPrettyMsLocale(locale),
114
+ compact: true,
115
+ verbose: true
116
+ })
117
+ });
118
+ if (validityMs > 0 && validityMs <= ALERT_THRESHOLD_MS) {
119
+ status = 'warning';
120
+ }
121
+ }
122
+ return /*#__PURE__*/_jsxs(_Fragment, {
123
+ children: [/*#__PURE__*/_jsx(Chip, {
124
+ label: /*#__PURE__*/_jsx(ChipLabel, {
125
+ children: validity || launcherSession?.subscription?.product?.name || t('common.subscription')
126
+ }),
127
+ color: status,
128
+ variant: status !== 'success' ? 'contained' : 'outlined',
129
+ sx: {
130
+ cursor: 'pointer',
131
+ ...sx
132
+ },
133
+ ...rest,
134
+ onClick: handlePopoverClick
135
+ }), /*#__PURE__*/_jsx(Popover, {
136
+ id: "popover-info",
137
+ open: Boolean(state.popoverAnchorEl),
138
+ anchorEl: state.popoverAnchorEl,
139
+ onClose: handlePopoverClose,
140
+ anchorOrigin: {
141
+ vertical: 'bottom',
142
+ horizontal: 'right'
143
+ },
144
+ transformOrigin: {
145
+ vertical: 'top',
146
+ horizontal: 'right'
147
+ },
148
+ children: /*#__PURE__*/_jsx("iframe", {
149
+ ref: iframeRef,
150
+ title: t('common.subscription'),
151
+ width: "360px",
152
+ height: "600px",
153
+ style: {
154
+ border: 0
155
+ },
156
+ src: asyncState.value?.subscriptionURL
157
+ })
158
+ })]
159
+ });
160
+ }
161
+ SubscriptionBlocklet.propTypes = {
162
+ chainHost: PropTypes.string.isRequired,
163
+ nftId: PropTypes.string,
164
+ launcherSessionId: PropTypes.string,
165
+ sx: PropTypes.object,
166
+ retention: PropTypes.number,
167
+ launcherUrl: PropTypes.string.isRequired
168
+ };
169
+ SubscriptionBlocklet.defaultProps = {
170
+ sx: {},
171
+ retention: 0,
172
+ nftId: '',
173
+ launcherSessionId: ''
174
+ };
175
+ export default SubscriptionBlocklet;
@@ -0,0 +1,21 @@
1
+ import AccessTimeIcon from '@mui/icons-material/AccessTime';
2
+ import Box from '@mui/material/Box';
3
+ import PropTypes from 'prop-types';
4
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
5
+ export default function ChipLabel({
6
+ children
7
+ }) {
8
+ return /*#__PURE__*/_jsxs(Box, {
9
+ sx: {
10
+ display: 'flex',
11
+ alignItems: 'center',
12
+ gap: 1
13
+ },
14
+ children: [/*#__PURE__*/_jsx(AccessTimeIcon, {
15
+ fontSize: "small"
16
+ }), children]
17
+ });
18
+ }
19
+ ChipLabel.propTypes = {
20
+ children: PropTypes.node.isRequired
21
+ };
@@ -1,41 +1,26 @@
1
1
  import dayjs from '@abtnode/util/lib/dayjs';
2
2
  import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
3
- import AccessTimeIcon from '@mui/icons-material/AccessTime';
4
- import Box from '@mui/material/Box';
5
3
  import Chip from '@mui/material/Chip';
6
4
  import CircularProgress from '@mui/material/CircularProgress';
7
5
  import Popover from '@mui/material/Popover';
6
+ import useMediaQuery from '@mui/material/useMediaQuery';
8
7
  import prettyMs from 'pretty-ms-i18n';
9
8
  import PropTypes from 'prop-types';
10
9
  import { useRef } from 'react';
11
10
  import useAsyncRetry from 'react-use/lib/useAsyncRetry';
12
11
  import useSetState from 'react-use/lib/useSetState';
13
- import useMediaQuery from '@mui/material/useMediaQuery';
14
- import { formatPrettyMsLocale, getAsset, getAssetExpiration, getSubscriptionURL } from './util';
12
+ import { useNodeContext } from '../contexts/node';
13
+ import { formatPrettyMsLocale, getSubscriptionUrlV2 } from '../util';
14
+ import ChipLabel from './chip-label';
15
15
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
16
16
  const ALERT_THRESHOLD_MS = 30 * 24 * 60 * 60 * 1000;
17
17
  const DEFAULT_LAUNCHER_URL = 'https://launcher.arcblock.io/'; // 兼容: 旧版本的 blocklet.controller 没有 launcherUrl 字段
18
18
 
19
- // eslint-disable-next-line react/prop-types
20
- function ChipLabel({
21
- children
22
- }) {
23
- return /*#__PURE__*/_jsxs(Box, {
24
- sx: {
25
- display: 'flex',
26
- alignItems: 'center',
27
- gap: 1
28
- },
29
- children: [/*#__PURE__*/_jsx(AccessTimeIcon, {
30
- fontSize: "small"
31
- }), children]
32
- });
33
- }
34
- function Subscription({
19
+ function SubscriptionServer({
35
20
  launcherUrl,
36
21
  chainHost,
37
22
  nftId,
38
- retention,
23
+ launcherSessionId,
39
24
  ...props
40
25
  }) {
41
26
  const {
@@ -48,19 +33,32 @@ function Subscription({
48
33
  });
49
34
  const iframeRef = useRef(null);
50
35
  const isMobile = useMediaQuery(x => x.breakpoints.down('md'));
36
+ const node = useNodeContext();
51
37
  const {
52
38
  sx = {},
53
39
  ...rest
54
40
  } = props;
55
41
  const typoKey = isMobile ? 'mobile' : 'desktop';
56
42
  const asyncState = useAsyncRetry(async () => {
57
- const [asset, subscriptionURL] = await Promise.all([getAsset(chainHost, nftId), getSubscriptionURL({
43
+ const [data, subscriptionURL] = await Promise.all([
44
+ // 新 Launch 的 Server 会有 launcherSessionId 信息,旧的 Server 只有 nftId
45
+ // 这里做兼容处理,优先使用 launcherSessionId, 如果没有则使用 nftId
46
+ node.api.getLauncherSession({
47
+ input: {
48
+ launcherSessionId: launcherSessionId || nftId,
49
+ launcherUrl
50
+ }
51
+ }), getSubscriptionUrlV2({
58
52
  launcherUrl: launcherUrl || DEFAULT_LAUNCHER_URL,
59
- nftId,
53
+ nftDid: nftId,
54
+ launcherSessionId,
60
55
  locale
61
56
  })]);
57
+ if (data?.error) {
58
+ throw new Error(data.error);
59
+ }
62
60
  return {
63
- asset,
61
+ launcherSession: data.launcherSession,
64
62
  subscriptionURL
65
63
  };
66
64
  }, [locale]);
@@ -95,7 +93,7 @@ function Subscription({
95
93
  onClick: () => asyncState.retry()
96
94
  });
97
95
  }
98
- const expirationDate = getAssetExpiration(asyncState.value?.asset);
96
+ const expirationDate = asyncState.value?.launcherSession?.expirationDate;
99
97
  const isExpired = dayjs(expirationDate).isBefore(dayjs());
100
98
  const validityMs = dayjs(expirationDate).diff(dayjs(), 'ms');
101
99
  let status = 'success';
@@ -160,15 +158,18 @@ function Subscription({
160
158
  })]
161
159
  });
162
160
  }
163
- Subscription.propTypes = {
161
+ SubscriptionServer.propTypes = {
164
162
  chainHost: PropTypes.string.isRequired,
165
- nftId: PropTypes.string.isRequired,
163
+ nftId: PropTypes.string,
164
+ launcherSessionId: PropTypes.string,
166
165
  sx: PropTypes.object,
167
166
  retention: PropTypes.number,
168
167
  launcherUrl: PropTypes.string.isRequired
169
168
  };
170
- Subscription.defaultProps = {
169
+ SubscriptionServer.defaultProps = {
171
170
  sx: {},
172
- retention: 0
171
+ retention: 0,
172
+ nftId: '',
173
+ launcherSessionId: ''
173
174
  };
174
- export default Subscription;
175
+ export default SubscriptionServer;
package/es/util/index.js CHANGED
@@ -6,7 +6,6 @@ import filesize from 'filesize';
6
6
  import humanizeUrl from 'humanize-url';
7
7
  import isUrl from 'is-url';
8
8
  import get from 'lodash/get';
9
- import last from 'lodash/last';
10
9
  import trimEnd from 'lodash/trimEnd';
11
10
  import qs from 'querystring';
12
11
  import joinUrl from 'url-join';
@@ -531,9 +530,6 @@ export async function getAsset(chainHost, address) {
531
530
  }
532
531
  return state;
533
532
  }
534
- export function getAssetExpiration(asset) {
535
- return last(get(asset, 'data.value.expirationDate', []));
536
- }
537
533
 
538
534
  /**
539
535
  * 检查url是否 未添加到 store list 中
@@ -621,11 +617,25 @@ export const sortDomains = domains => {
621
617
  });
622
618
  };
623
619
  export const formatMountPoint = value => normalizePathPrefix(urlPathFriendly(value));
624
- export const getRenewBlockletURL = ({
625
- launcherUrl = '',
626
- nftId = '',
627
- locale = 'en'
628
- }) => joinUrl(launcherUrl, `/instances/${nftId}/renewal?locale=${locale}&return-url=${encodeURIComponent(window.location.href)}`);
620
+ const getLauncherBaseURL = async launcherUrl => {
621
+ if (!launcherUrl) {
622
+ return '';
623
+ }
624
+ let baseUrl = launcherUrl;
625
+ try {
626
+ const {
627
+ data: appMeta
628
+ } = await axios.get(joinUrl(launcherUrl, '__blocklet__.js?type=json'), {
629
+ timeout: 5000
630
+ });
631
+ const mountPoint = appMeta.componentMountPoints?.find(item => item.did === 'z8iZkFBbrVQxZHvcWWB3Sa2TrfGmSeFz9MSU7');
632
+ const launcherUrlObj = new URL(launcherUrl);
633
+ baseUrl = joinUrl(launcherUrlObj.origin, mountPoint?.mountPoint);
634
+ } catch (error) {
635
+ console.error(error);
636
+ }
637
+ return baseUrl;
638
+ };
629
639
  export const getSubscriptionURL = async ({
630
640
  launcherUrl = '',
631
641
  nftId = '',
@@ -649,6 +659,29 @@ export const getSubscriptionURL = async ({
649
659
  }
650
660
  return joinUrl(baseUrl, `/${nftId}/subscription?locale=${locale}&return-url=${encodeURIComponent(window.location.href)}`);
651
661
  };
662
+ export const getSubscriptionUrlV2 = async ({
663
+ launcherUrl = '',
664
+ launcherSessionId = '',
665
+ nftDid,
666
+ locale = 'en'
667
+ }) => {
668
+ if (!launcherUrl) {
669
+ return '';
670
+ }
671
+ const baseUrl = await getLauncherBaseURL(launcherUrl);
672
+ return joinUrl(baseUrl, `/embed/subscription?launcherSessionId=${launcherSessionId}&nftDid=${nftDid}&locale=${locale}`); // nftDid 是兼容字段
673
+ };
674
+ export const getManageSubscriptionURL = async ({
675
+ launcherUrl = '',
676
+ launcherSessionId = '',
677
+ locale = 'en'
678
+ }) => {
679
+ if (!launcherUrl) {
680
+ return '';
681
+ }
682
+ const baseUrl = await getLauncherBaseURL(launcherUrl);
683
+ return joinUrl(baseUrl, `/embed/manage-subscription?launcherSessionId=${launcherSessionId}&locale=${locale}`);
684
+ };
652
685
  export const nanoid = (length = 16) => [...Array(length)].map(() => Math.random().toString(36)[2]).join('');
653
686
  export const getSystemDomains = domains => domains.filter(x => x.isProtected);
654
687
  export const getLogoHash = logo => encodeURIComponent((logo || '').split('/').slice(-1)[0].slice(0, 7));
@@ -33,7 +33,6 @@ var _util3 = require("./util");
33
33
  var _node = require("../contexts/node");
34
34
  var _confirm = _interopRequireDefault(require("../confirm"));
35
35
  var _icons = _interopRequireDefault(require("./icons"));
36
- var _blocklet = require("../contexts/blocklet");
37
36
  var _jsxRuntime = require("react/jsx-runtime");
38
37
  var _templateObject;
39
38
  const _excluded = ["blocklet", "onStart", "onComplete", "variant", "hasPermission", "useBlockletUrlEvaluation"],
@@ -50,7 +49,7 @@ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e =
50
49
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
51
50
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
52
51
  function BlockletActions(_ref) {
53
- var _blocklet$controller, _blocklet$controller2;
52
+ var _blocklet$controller;
54
53
  let {
55
54
  blocklet,
56
55
  onStart,
@@ -74,14 +73,14 @@ function BlockletActions(_ref) {
74
73
  loading: recommendedUrlLoading,
75
74
  recommendedUrl
76
75
  } = useBlockletUrlEvaluation(blocklet);
77
- const {
78
- nftState
79
- } = (0, _blocklet.useBlockletContext)();
80
76
  const inProgress = (0, _util.isInProgress)(blocklet.status);
81
- let disableStart = (blocklet === null || blocklet === void 0 || (_blocklet$controller = blocklet.controller) === null || _blocklet$controller === void 0 || (_blocklet$controller = _blocklet$controller.status) === null || _blocklet$controller === void 0 ? void 0 : _blocklet$controller.value) === _constant.BLOCKLET_CONTROLLER_STATUS.suspended;
82
- if (!(nftState !== null && nftState !== void 0 && nftState.expired) && (blocklet === null || blocklet === void 0 || (_blocklet$controller2 = blocklet.controller) === null || _blocklet$controller2 === void 0 || (_blocklet$controller2 = _blocklet$controller2.status) === null || _blocklet$controller2 === void 0 ? void 0 : _blocklet$controller2.reason) === _constant.SUSPENDED_REASON.expired) {
83
- disableStart = false;
84
- }
77
+ const disableStart = (blocklet === null || blocklet === void 0 || (_blocklet$controller = blocklet.controller) === null || _blocklet$controller === void 0 || (_blocklet$controller = _blocklet$controller.status) === null || _blocklet$controller === void 0 ? void 0 : _blocklet$controller.value) === _constant.BLOCKLET_CONTROLLER_STATUS.suspended;
78
+
79
+ // TODO: PaymentKitV2 过期恢复后需要能立即启动
80
+ // if (!nftState?.expired && blocklet?.controller?.status?.reason === SUSPENDED_REASON.expired) {
81
+ // disableStart = false;
82
+ // }
83
+
85
84
  const {
86
85
  inService
87
86
  } = node;
@@ -0,0 +1,189 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _context = require("@arcblock/ux/lib/Locale/context");
8
+ var _dayjs = _interopRequireDefault(require("@abtnode/util/lib/dayjs"));
9
+ var _Chip = _interopRequireDefault(require("@mui/material/Chip"));
10
+ var _CircularProgress = _interopRequireDefault(require("@mui/material/CircularProgress"));
11
+ var _Popover = _interopRequireDefault(require("@mui/material/Popover"));
12
+ var _useMediaQuery = _interopRequireDefault(require("@mui/material/useMediaQuery"));
13
+ var _propTypes = _interopRequireDefault(require("prop-types"));
14
+ var _prettyMsI18n = _interopRequireDefault(require("pretty-ms-i18n"));
15
+ var _react = require("react");
16
+ var _useAsyncRetry = _interopRequireDefault(require("react-use/lib/useAsyncRetry"));
17
+ var _useSetState = _interopRequireDefault(require("react-use/lib/useSetState"));
18
+ var _node = require("../contexts/node");
19
+ var _util = require("../util");
20
+ var _chipLabel = _interopRequireDefault(require("./chip-label"));
21
+ var _jsxRuntime = require("react/jsx-runtime");
22
+ const _excluded = ["launcherUrl", "chainHost", "nftId", "launcherSessionId"],
23
+ _excluded2 = ["sx"];
24
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
26
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
27
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
28
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
29
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
30
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
31
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
32
+ const DEFAULT_LAUNCHER_URL = 'https://launcher.arcblock.io/'; // 兼容: 旧版本的 blocklet.controller 没有 launcherUrl 字段
33
+
34
+ const ALERT_THRESHOLD_MS = 30 * 24 * 60 * 60 * 1000;
35
+ function SubscriptionBlocklet(_ref) {
36
+ var _asyncState$value, _asyncState$value2, _launcherSession$subs, _asyncState$value3;
37
+ let {
38
+ launcherUrl,
39
+ chainHost,
40
+ nftId,
41
+ launcherSessionId
42
+ } = _ref,
43
+ props = _objectWithoutProperties(_ref, _excluded);
44
+ const {
45
+ t,
46
+ locale
47
+ } = (0, _context.useLocaleContext)();
48
+ const node = (0, _node.useNodeContext)();
49
+ const [state, setState] = (0, _useSetState.default)({
50
+ safeIframeRef: null,
51
+ popoverAnchorEl: null
52
+ });
53
+ const iframeRef = (0, _react.useRef)(null);
54
+ const isMobile = (0, _useMediaQuery.default)(x => x.breakpoints.down('md'));
55
+ const {
56
+ sx = {}
57
+ } = props,
58
+ rest = _objectWithoutProperties(props, _excluded2);
59
+ const typoKey = isMobile ? 'mobile' : 'desktop';
60
+ const asyncState = (0, _useAsyncRetry.default)(async () => {
61
+ const [data, subscriptionURL] = await Promise.all([node.api.getLauncherSession({
62
+ input: {
63
+ launcherSessionId,
64
+ launcherUrl
65
+ }
66
+ }), (0, _util.getSubscriptionUrlV2)({
67
+ launcherUrl: launcherUrl || DEFAULT_LAUNCHER_URL,
68
+ nftDid: nftId,
69
+ launcherSessionId,
70
+ locale
71
+ })]);
72
+ if (data !== null && data !== void 0 && data.error) {
73
+ throw new Error(data.error);
74
+ }
75
+ return {
76
+ launcherSession: data.launcherSession,
77
+ subscriptionURL
78
+ };
79
+ }, [locale]);
80
+ if (asyncState.loading) {
81
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Chip.default, _objectSpread({
82
+ label: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_chipLabel.default, {
83
+ children: [!isMobile && t('expiration.desktop.loading'), /*#__PURE__*/(0, _jsxRuntime.jsx)(_CircularProgress.default, {
84
+ size: 16
85
+ })]
86
+ }),
87
+ variant: "success",
88
+ sx: _objectSpread({
89
+ cursor: 'pointer'
90
+ }, sx)
91
+ }, rest));
92
+ }
93
+ if (asyncState.error) {
94
+ console.error(asyncState.error);
95
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Chip.default, _objectSpread(_objectSpread({
96
+ label: /*#__PURE__*/(0, _jsxRuntime.jsx)(_chipLabel.default, {
97
+ children: t("expiration.".concat(typoKey, ".loadFailed"))
98
+ }),
99
+ color: "error",
100
+ variant: "success",
101
+ sx: _objectSpread({
102
+ cursor: 'pointer'
103
+ }, sx)
104
+ }, rest), {}, {
105
+ onClick: () => asyncState.retry()
106
+ }));
107
+ }
108
+ const handlePopoverClick = event => {
109
+ setState({
110
+ popoverAnchorEl: event.currentTarget
111
+ });
112
+ };
113
+ const handlePopoverClose = () => {
114
+ setState({
115
+ popoverAnchorEl: null
116
+ });
117
+ };
118
+ const launcherSession = (_asyncState$value = asyncState.value) === null || _asyncState$value === void 0 ? void 0 : _asyncState$value.launcherSession;
119
+ let status = 'success';
120
+ if (['expired', 'terminated'].includes((_asyncState$value2 = asyncState.value) === null || _asyncState$value2 === void 0 || (_asyncState$value2 = _asyncState$value2.launcherSession) === null || _asyncState$value2 === void 0 ? void 0 : _asyncState$value2.statusText)) {
121
+ status = 'error';
122
+ }
123
+ let validity = null;
124
+ if (launcherSession.expirationDate && !launcherSession.subscription) {
125
+ const validityMs = (0, _dayjs.default)(launcherSession.expirationDate).diff((0, _dayjs.default)(), 'ms');
126
+ validity = t("expiration.".concat(typoKey, ".tips.").concat(status), {
127
+ validity: (0, _prettyMsI18n.default)(validityMs, {
128
+ locale: (0, _util.formatPrettyMsLocale)(locale),
129
+ compact: true,
130
+ verbose: true
131
+ })
132
+ });
133
+ if (validityMs > 0 && validityMs <= ALERT_THRESHOLD_MS) {
134
+ status = 'warning';
135
+ }
136
+ }
137
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
138
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Chip.default, _objectSpread(_objectSpread({
139
+ label: /*#__PURE__*/(0, _jsxRuntime.jsx)(_chipLabel.default, {
140
+ children: validity || (launcherSession === null || launcherSession === void 0 || (_launcherSession$subs = launcherSession.subscription) === null || _launcherSession$subs === void 0 || (_launcherSession$subs = _launcherSession$subs.product) === null || _launcherSession$subs === void 0 ? void 0 : _launcherSession$subs.name) || t('common.subscription')
141
+ }),
142
+ color: status,
143
+ variant: status !== 'success' ? 'contained' : 'outlined',
144
+ sx: _objectSpread({
145
+ cursor: 'pointer'
146
+ }, sx)
147
+ }, rest), {}, {
148
+ onClick: handlePopoverClick
149
+ })), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Popover.default, {
150
+ id: "popover-info",
151
+ open: Boolean(state.popoverAnchorEl),
152
+ anchorEl: state.popoverAnchorEl,
153
+ onClose: handlePopoverClose,
154
+ anchorOrigin: {
155
+ vertical: 'bottom',
156
+ horizontal: 'right'
157
+ },
158
+ transformOrigin: {
159
+ vertical: 'top',
160
+ horizontal: 'right'
161
+ },
162
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("iframe", {
163
+ ref: iframeRef,
164
+ title: t('common.subscription'),
165
+ width: "360px",
166
+ height: "600px",
167
+ style: {
168
+ border: 0
169
+ },
170
+ src: (_asyncState$value3 = asyncState.value) === null || _asyncState$value3 === void 0 ? void 0 : _asyncState$value3.subscriptionURL
171
+ })
172
+ })]
173
+ });
174
+ }
175
+ SubscriptionBlocklet.propTypes = {
176
+ chainHost: _propTypes.default.string.isRequired,
177
+ nftId: _propTypes.default.string,
178
+ launcherSessionId: _propTypes.default.string,
179
+ sx: _propTypes.default.object,
180
+ retention: _propTypes.default.number,
181
+ launcherUrl: _propTypes.default.string.isRequired
182
+ };
183
+ SubscriptionBlocklet.defaultProps = {
184
+ sx: {},
185
+ retention: 0,
186
+ nftId: '',
187
+ launcherSessionId: ''
188
+ };
189
+ var _default = exports.default = SubscriptionBlocklet;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = ChipLabel;
7
+ var _AccessTime = _interopRequireDefault(require("@mui/icons-material/AccessTime"));
8
+ var _Box = _interopRequireDefault(require("@mui/material/Box"));
9
+ var _propTypes = _interopRequireDefault(require("prop-types"));
10
+ var _jsxRuntime = require("react/jsx-runtime");
11
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
+ function ChipLabel(_ref) {
13
+ let {
14
+ children
15
+ } = _ref;
16
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Box.default, {
17
+ sx: {
18
+ display: 'flex',
19
+ alignItems: 'center',
20
+ gap: 1
21
+ },
22
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_AccessTime.default, {
23
+ fontSize: "small"
24
+ }), children]
25
+ });
26
+ }
27
+ ChipLabel.propTypes = {
28
+ children: _propTypes.default.node.isRequired
29
+ };
@@ -6,20 +6,20 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  var _dayjs = _interopRequireDefault(require("@abtnode/util/lib/dayjs"));
8
8
  var _context = require("@arcblock/ux/lib/Locale/context");
9
- var _AccessTime = _interopRequireDefault(require("@mui/icons-material/AccessTime"));
10
- var _Box = _interopRequireDefault(require("@mui/material/Box"));
11
9
  var _Chip = _interopRequireDefault(require("@mui/material/Chip"));
12
10
  var _CircularProgress = _interopRequireDefault(require("@mui/material/CircularProgress"));
13
11
  var _Popover = _interopRequireDefault(require("@mui/material/Popover"));
12
+ var _useMediaQuery = _interopRequireDefault(require("@mui/material/useMediaQuery"));
14
13
  var _prettyMsI18n = _interopRequireDefault(require("pretty-ms-i18n"));
15
14
  var _propTypes = _interopRequireDefault(require("prop-types"));
16
15
  var _react = require("react");
17
16
  var _useAsyncRetry = _interopRequireDefault(require("react-use/lib/useAsyncRetry"));
18
17
  var _useSetState = _interopRequireDefault(require("react-use/lib/useSetState"));
19
- var _useMediaQuery = _interopRequireDefault(require("@mui/material/useMediaQuery"));
20
- var _util = require("./util");
18
+ var _node = require("../contexts/node");
19
+ var _util = require("../util");
20
+ var _chipLabel = _interopRequireDefault(require("./chip-label"));
21
21
  var _jsxRuntime = require("react/jsx-runtime");
22
- const _excluded = ["launcherUrl", "chainHost", "nftId", "retention"],
22
+ const _excluded = ["launcherUrl", "chainHost", "nftId", "launcherSessionId"],
23
23
  _excluded2 = ["sx"];
24
24
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
25
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
@@ -32,31 +32,15 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
32
32
  const ALERT_THRESHOLD_MS = 30 * 24 * 60 * 60 * 1000;
33
33
  const DEFAULT_LAUNCHER_URL = 'https://launcher.arcblock.io/'; // 兼容: 旧版本的 blocklet.controller 没有 launcherUrl 字段
34
34
 
35
- // eslint-disable-next-line react/prop-types
36
- function ChipLabel(_ref) {
37
- let {
38
- children
39
- } = _ref;
40
- return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Box.default, {
41
- sx: {
42
- display: 'flex',
43
- alignItems: 'center',
44
- gap: 1
45
- },
46
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_AccessTime.default, {
47
- fontSize: "small"
48
- }), children]
49
- });
50
- }
51
- function Subscription(_ref2) {
35
+ function SubscriptionServer(_ref) {
52
36
  var _asyncState$value, _asyncState$value2;
53
37
  let {
54
38
  launcherUrl,
55
39
  chainHost,
56
40
  nftId,
57
- retention
58
- } = _ref2,
59
- props = _objectWithoutProperties(_ref2, _excluded);
41
+ launcherSessionId
42
+ } = _ref,
43
+ props = _objectWithoutProperties(_ref, _excluded);
60
44
  const {
61
45
  t,
62
46
  locale
@@ -67,25 +51,38 @@ function Subscription(_ref2) {
67
51
  });
68
52
  const iframeRef = (0, _react.useRef)(null);
69
53
  const isMobile = (0, _useMediaQuery.default)(x => x.breakpoints.down('md'));
54
+ const node = (0, _node.useNodeContext)();
70
55
  const {
71
56
  sx = {}
72
57
  } = props,
73
58
  rest = _objectWithoutProperties(props, _excluded2);
74
59
  const typoKey = isMobile ? 'mobile' : 'desktop';
75
60
  const asyncState = (0, _useAsyncRetry.default)(async () => {
76
- const [asset, subscriptionURL] = await Promise.all([(0, _util.getAsset)(chainHost, nftId), (0, _util.getSubscriptionURL)({
61
+ const [data, subscriptionURL] = await Promise.all([
62
+ // 新 Launch 的 Server 会有 launcherSessionId 信息,旧的 Server 只有 nftId
63
+ // 这里做兼容处理,优先使用 launcherSessionId, 如果没有则使用 nftId
64
+ node.api.getLauncherSession({
65
+ input: {
66
+ launcherSessionId: launcherSessionId || nftId,
67
+ launcherUrl
68
+ }
69
+ }), (0, _util.getSubscriptionUrlV2)({
77
70
  launcherUrl: launcherUrl || DEFAULT_LAUNCHER_URL,
78
- nftId,
71
+ nftDid: nftId,
72
+ launcherSessionId,
79
73
  locale
80
74
  })]);
75
+ if (data !== null && data !== void 0 && data.error) {
76
+ throw new Error(data.error);
77
+ }
81
78
  return {
82
- asset,
79
+ launcherSession: data.launcherSession,
83
80
  subscriptionURL
84
81
  };
85
82
  }, [locale]);
86
83
  if (asyncState.loading) {
87
84
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Chip.default, _objectSpread({
88
- label: /*#__PURE__*/(0, _jsxRuntime.jsxs)(ChipLabel, {
85
+ label: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_chipLabel.default, {
89
86
  children: [!isMobile && t('expiration.desktop.loading'), /*#__PURE__*/(0, _jsxRuntime.jsx)(_CircularProgress.default, {
90
87
  size: 16
91
88
  })]
@@ -99,7 +96,7 @@ function Subscription(_ref2) {
99
96
  if (asyncState.error) {
100
97
  console.error(asyncState.error);
101
98
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Chip.default, _objectSpread(_objectSpread({
102
- label: /*#__PURE__*/(0, _jsxRuntime.jsx)(ChipLabel, {
99
+ label: /*#__PURE__*/(0, _jsxRuntime.jsx)(_chipLabel.default, {
103
100
  children: t("expiration.".concat(typoKey, ".loadFailed"))
104
101
  }),
105
102
  color: "error",
@@ -111,7 +108,7 @@ function Subscription(_ref2) {
111
108
  onClick: () => asyncState.retry()
112
109
  }));
113
110
  }
114
- const expirationDate = (0, _util.getAssetExpiration)((_asyncState$value = asyncState.value) === null || _asyncState$value === void 0 ? void 0 : _asyncState$value.asset);
111
+ const expirationDate = (_asyncState$value = asyncState.value) === null || _asyncState$value === void 0 || (_asyncState$value = _asyncState$value.launcherSession) === null || _asyncState$value === void 0 ? void 0 : _asyncState$value.expirationDate;
115
112
  const isExpired = (0, _dayjs.default)(expirationDate).isBefore((0, _dayjs.default)());
116
113
  const validityMs = (0, _dayjs.default)(expirationDate).diff((0, _dayjs.default)(), 'ms');
117
114
  let status = 'success';
@@ -133,7 +130,7 @@ function Subscription(_ref2) {
133
130
  };
134
131
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
135
132
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Chip.default, _objectSpread(_objectSpread({
136
- label: /*#__PURE__*/(0, _jsxRuntime.jsx)(ChipLabel, {
133
+ label: /*#__PURE__*/(0, _jsxRuntime.jsx)(_chipLabel.default, {
137
134
  children: t("expiration.".concat(typoKey, ".tips.").concat(status), {
138
135
  validity: (0, _prettyMsI18n.default)(validityMs, {
139
136
  locale: (0, _util.formatPrettyMsLocale)(locale),
@@ -175,15 +172,18 @@ function Subscription(_ref2) {
175
172
  })]
176
173
  });
177
174
  }
178
- Subscription.propTypes = {
175
+ SubscriptionServer.propTypes = {
179
176
  chainHost: _propTypes.default.string.isRequired,
180
- nftId: _propTypes.default.string.isRequired,
177
+ nftId: _propTypes.default.string,
178
+ launcherSessionId: _propTypes.default.string,
181
179
  sx: _propTypes.default.object,
182
180
  retention: _propTypes.default.number,
183
181
  launcherUrl: _propTypes.default.string.isRequired
184
182
  };
185
- Subscription.defaultProps = {
183
+ SubscriptionServer.defaultProps = {
186
184
  sx: {},
187
- retention: 0
185
+ retention: 0,
186
+ nftId: '',
187
+ launcherSessionId: ''
188
188
  };
189
- var _default = exports.default = Subscription;
189
+ var _default = exports.default = SubscriptionServer;
package/lib/util/index.js CHANGED
@@ -23,14 +23,13 @@ exports.formatUrl = void 0;
23
23
  exports.getAccessUrl = getAccessUrl;
24
24
  exports.getAccessibleUrl = void 0;
25
25
  exports.getAsset = getAsset;
26
- exports.getAssetExpiration = getAssetExpiration;
27
26
  exports.getBlockletLogoUrl = void 0;
28
27
  exports.getBlockletMetaUrl = getBlockletMetaUrl;
29
28
  exports.getBlockletUrl = getBlockletUrl;
30
29
  exports.getBlockletUrlParams = void 0;
31
30
  exports.getBlockletUrls = getBlockletUrls;
32
31
  exports.getExplorerLink = getExplorerLink;
33
- exports.getTransferAppLink = exports.getSystemDomains = exports.getSubscriptionURL = exports.getStoreList = exports.getRenewBlockletURL = exports.getPathPrefix = exports.getLogoHash = exports.getIssuePassportLink = exports.getInviteLink = void 0;
32
+ exports.getTransferAppLink = exports.getSystemDomains = exports.getSubscriptionUrlV2 = exports.getSubscriptionURL = exports.getStoreList = exports.getPathPrefix = exports.getManageSubscriptionURL = exports.getLogoHash = exports.getIssuePassportLink = exports.getInviteLink = void 0;
34
33
  exports.getWebWalletUrl = getWebWalletUrl;
35
34
  exports.isNewStoreUrl = exports.isInstalling = exports.isDownloading = exports.isChrome = exports.isCertificateMatch = exports.isBlockletDev = exports.hasRequiredSteps = void 0;
36
35
  exports.isProtectedRole = isProtectedRole;
@@ -46,7 +45,6 @@ var _filesize = _interopRequireDefault(require("filesize"));
46
45
  var _humanizeUrl = _interopRequireDefault(require("humanize-url"));
47
46
  var _isUrl = _interopRequireDefault(require("is-url"));
48
47
  var _get = _interopRequireDefault(require("lodash/get"));
49
- var _last = _interopRequireDefault(require("lodash/last"));
50
48
  var _trimEnd = _interopRequireDefault(require("lodash/trimEnd"));
51
49
  var _querystring = _interopRequireDefault(require("querystring"));
52
50
  var _urlJoin = _interopRequireDefault(require("url-join"));
@@ -617,9 +615,6 @@ async function getAsset(chainHost, address) {
617
615
  }
618
616
  return state;
619
617
  }
620
- function getAssetExpiration(asset) {
621
- return (0, _last.default)((0, _get.default)(asset, 'data.value.expirationDate', []));
622
- }
623
618
 
624
619
  /**
625
620
  * 检查url是否 未添加到 store list 中
@@ -715,33 +710,44 @@ const sortDomains = domains => {
715
710
  exports.sortDomains = sortDomains;
716
711
  const formatMountPoint = value => (0, _normalizePathPrefix.default)((0, _urlPathFriendly.default)(value));
717
712
  exports.formatMountPoint = formatMountPoint;
718
- const getRenewBlockletURL = _ref7 => {
719
- let {
720
- launcherUrl = '',
721
- nftId = '',
722
- locale = 'en'
723
- } = _ref7;
724
- return (0, _urlJoin.default)(launcherUrl, "/instances/".concat(nftId, "/renewal?locale=").concat(locale, "&return-url=").concat(encodeURIComponent(window.location.href)));
713
+ const getLauncherBaseURL = async launcherUrl => {
714
+ if (!launcherUrl) {
715
+ return '';
716
+ }
717
+ let baseUrl = launcherUrl;
718
+ try {
719
+ var _appMeta$componentMou;
720
+ const {
721
+ data: appMeta
722
+ } = await _axios.default.get((0, _urlJoin.default)(launcherUrl, '__blocklet__.js?type=json'), {
723
+ timeout: 5000
724
+ });
725
+ const mountPoint = (_appMeta$componentMou = appMeta.componentMountPoints) === null || _appMeta$componentMou === void 0 ? void 0 : _appMeta$componentMou.find(item => item.did === 'z8iZkFBbrVQxZHvcWWB3Sa2TrfGmSeFz9MSU7');
726
+ const launcherUrlObj = new URL(launcherUrl);
727
+ baseUrl = (0, _urlJoin.default)(launcherUrlObj.origin, mountPoint === null || mountPoint === void 0 ? void 0 : mountPoint.mountPoint);
728
+ } catch (error) {
729
+ console.error(error);
730
+ }
731
+ return baseUrl;
725
732
  };
726
- exports.getRenewBlockletURL = getRenewBlockletURL;
727
- const getSubscriptionURL = async _ref8 => {
733
+ const getSubscriptionURL = async _ref7 => {
728
734
  let {
729
735
  launcherUrl = '',
730
736
  nftId = '',
731
737
  locale = 'en'
732
- } = _ref8;
738
+ } = _ref7;
733
739
  if (!launcherUrl) {
734
740
  return '';
735
741
  }
736
742
  let baseUrl = (0, _urlJoin.default)(launcherUrl, '/instances');
737
743
  try {
738
- var _appMeta$componentMou;
744
+ var _appMeta$componentMou2;
739
745
  const {
740
746
  data: appMeta
741
747
  } = await _axios.default.get((0, _urlJoin.default)(launcherUrl, '__blocklet__.js?type=json'), {
742
748
  timeout: 5000
743
749
  });
744
- const mountPoint = (_appMeta$componentMou = appMeta.componentMountPoints) === null || _appMeta$componentMou === void 0 ? void 0 : _appMeta$componentMou.find(item => item.did === 'z8iZy4P83i6AgnNdNUexsh2kBcsDHoqcwPavn');
750
+ const mountPoint = (_appMeta$componentMou2 = appMeta.componentMountPoints) === null || _appMeta$componentMou2 === void 0 ? void 0 : _appMeta$componentMou2.find(item => item.did === 'z8iZy4P83i6AgnNdNUexsh2kBcsDHoqcwPavn');
745
751
  const launcherUrlObj = new URL(launcherUrl);
746
752
  baseUrl = (0, _urlJoin.default)(launcherUrlObj.origin, mountPoint === null || mountPoint === void 0 ? void 0 : mountPoint.mountPoint, '/nfts');
747
753
  } catch (error) {
@@ -750,6 +756,33 @@ const getSubscriptionURL = async _ref8 => {
750
756
  return (0, _urlJoin.default)(baseUrl, "/".concat(nftId, "/subscription?locale=").concat(locale, "&return-url=").concat(encodeURIComponent(window.location.href)));
751
757
  };
752
758
  exports.getSubscriptionURL = getSubscriptionURL;
759
+ const getSubscriptionUrlV2 = async _ref8 => {
760
+ let {
761
+ launcherUrl = '',
762
+ launcherSessionId = '',
763
+ nftDid,
764
+ locale = 'en'
765
+ } = _ref8;
766
+ if (!launcherUrl) {
767
+ return '';
768
+ }
769
+ const baseUrl = await getLauncherBaseURL(launcherUrl);
770
+ return (0, _urlJoin.default)(baseUrl, "/embed/subscription?launcherSessionId=".concat(launcherSessionId, "&nftDid=").concat(nftDid, "&locale=").concat(locale)); // nftDid 是兼容字段
771
+ };
772
+ exports.getSubscriptionUrlV2 = getSubscriptionUrlV2;
773
+ const getManageSubscriptionURL = async _ref9 => {
774
+ let {
775
+ launcherUrl = '',
776
+ launcherSessionId = '',
777
+ locale = 'en'
778
+ } = _ref9;
779
+ if (!launcherUrl) {
780
+ return '';
781
+ }
782
+ const baseUrl = await getLauncherBaseURL(launcherUrl);
783
+ return (0, _urlJoin.default)(baseUrl, "/embed/manage-subscription?launcherSessionId=".concat(launcherSessionId, "&locale=").concat(locale));
784
+ };
785
+ exports.getManageSubscriptionURL = getManageSubscriptionURL;
753
786
  const nanoid = exports.nanoid = function nanoid() {
754
787
  let length = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 16;
755
788
  return [...Array(length)].map(() => Math.random().toString(36)[2]).join('');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abtnode/ux",
3
- "version": "1.16.25-beta-85e265d1",
3
+ "version": "1.16.25-beta-bc165d9b",
4
4
  "description": "UX components shared across abtnode packages",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -28,9 +28,9 @@
28
28
  "author": "linchen <linchen1987@foxmail.com> (http://github.com/linchen1987)",
29
29
  "license": "Apache-2.0",
30
30
  "dependencies": {
31
- "@abtnode/auth": "1.16.25-beta-85e265d1",
32
- "@abtnode/constant": "1.16.25-beta-85e265d1",
33
- "@abtnode/util": "1.16.25-beta-85e265d1",
31
+ "@abtnode/auth": "1.16.25-beta-bc165d9b",
32
+ "@abtnode/constant": "1.16.25-beta-bc165d9b",
33
+ "@abtnode/util": "1.16.25-beta-bc165d9b",
34
34
  "@ahooksjs/use-url-state": "^3.5.1",
35
35
  "@arcblock/did": "^1.18.113",
36
36
  "@arcblock/did-connect": "^2.9.63",
@@ -40,10 +40,10 @@
40
40
  "@arcblock/react-hooks": "^2.9.63",
41
41
  "@arcblock/terminal": "^2.9.63",
42
42
  "@arcblock/ux": "^2.9.63",
43
- "@blocklet/constant": "1.16.25-beta-85e265d1",
43
+ "@blocklet/constant": "1.16.25-beta-bc165d9b",
44
44
  "@blocklet/launcher-layout": "2.2.66",
45
45
  "@blocklet/list": "^0.12.79",
46
- "@blocklet/meta": "1.16.25-beta-85e265d1",
46
+ "@blocklet/meta": "1.16.25-beta-bc165d9b",
47
47
  "@blocklet/ui-react": "^2.9.63",
48
48
  "@blocklet/uploader": "^0.0.75",
49
49
  "@emotion/react": "^11.10.4",
@@ -107,7 +107,7 @@
107
107
  "jest": "^29.7.0",
108
108
  "jest-environment-jsdom": "^29.7.0"
109
109
  },
110
- "gitHead": "ea2dbf135591636c3d1899374b99d66eee61c7d2",
110
+ "gitHead": "a7895ed39e47c8c6bd10d32317804cc1904714ef",
111
111
  "exports": {
112
112
  ".": {
113
113
  "import": "./es/index.js",