@abtnode/ux 1.16.25-next-0ba03ffc → 1.16.25-next-44800645
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/blocklet/actions.js +9 -8
- package/es/blocklet/router/action/add-rule.js +12 -0
- package/es/blocklet/router/action/config-routing-rule.js +55 -4
- package/es/blocklet/router/action/update-rule.js +12 -0
- package/es/blocklet/router/rule-list.js +10 -2
- package/es/locales/ar.js +5 -1
- package/es/locales/de.js +5 -1
- package/es/locales/en.js +5 -1
- package/es/locales/es.js +5 -1
- package/es/locales/fr.js +5 -1
- package/es/locales/hi.js +5 -1
- package/es/locales/i18n.db +0 -0
- package/es/locales/id.js +5 -1
- package/es/locales/ja.js +5 -1
- package/es/locales/ko.js +5 -1
- package/es/locales/pt.js +5 -1
- package/es/locales/ru.js +5 -1
- package/es/locales/th.js +5 -1
- package/es/locales/vi.js +5 -1
- package/es/locales/zh-tw.js +5 -1
- package/es/locales/zh.js +5 -1
- package/es/{subscription/server.js → subscription.js} +28 -23
- package/es/util/index.js +5 -42
- package/lib/blocklet/actions.js +9 -8
- package/lib/blocklet/router/action/add-rule.js +12 -0
- package/lib/blocklet/router/action/config-routing-rule.js +52 -3
- package/lib/blocklet/router/action/update-rule.js +13 -0
- package/lib/blocklet/router/rule-list.js +10 -1
- package/lib/locales/ar.js +5 -1
- package/lib/locales/de.js +5 -1
- package/lib/locales/en.js +5 -1
- package/lib/locales/es.js +5 -1
- package/lib/locales/fr.js +5 -1
- package/lib/locales/hi.js +5 -1
- package/lib/locales/i18n.db +0 -0
- package/lib/locales/id.js +5 -1
- package/lib/locales/ja.js +5 -1
- package/lib/locales/ko.js +5 -1
- package/lib/locales/pt.js +5 -1
- package/lib/locales/ru.js +5 -1
- package/lib/locales/th.js +5 -1
- package/lib/locales/vi.js +5 -1
- package/lib/locales/zh-tw.js +5 -1
- package/lib/locales/zh.js +5 -1
- package/lib/{subscription/server.js → subscription.js} +35 -29
- package/lib/util/index.js +13 -51
- package/package.json +7 -7
- package/es/subscription/blocklet.js +0 -174
- package/es/subscription/chip-label.js +0 -22
- package/lib/subscription/blocklet.js +0 -186
- package/lib/subscription/chip-label.js +0 -29
package/lib/util/index.js
CHANGED
|
@@ -30,7 +30,7 @@ exports.getBlockletUrl = getBlockletUrl;
|
|
|
30
30
|
exports.getBlockletUrlParams = void 0;
|
|
31
31
|
exports.getBlockletUrls = getBlockletUrls;
|
|
32
32
|
exports.getExplorerLink = getExplorerLink;
|
|
33
|
-
exports.getTransferAppLink = exports.getSystemDomains = exports.
|
|
33
|
+
exports.getTransferAppLink = exports.getSystemDomains = exports.getSubscriptionURL = exports.getStoreList = exports.getRenewBlockletURL = exports.getPathPrefix = exports.getLogoHash = exports.getIssuePassportLink = exports.getInviteLink = void 0;
|
|
34
34
|
exports.getWebWalletUrl = getWebWalletUrl;
|
|
35
35
|
exports.isNewStoreUrl = exports.isInstalling = exports.isDownloading = exports.isChrome = exports.isCertificateMatch = exports.isBlockletDev = exports.hasRequiredSteps = void 0;
|
|
36
36
|
exports.isProtectedRole = isProtectedRole;
|
|
@@ -715,44 +715,33 @@ const sortDomains = domains => {
|
|
|
715
715
|
exports.sortDomains = sortDomains;
|
|
716
716
|
const formatMountPoint = value => (0, _normalizePathPrefix.default)((0, _urlPathFriendly.default)(value));
|
|
717
717
|
exports.formatMountPoint = formatMountPoint;
|
|
718
|
-
const
|
|
719
|
-
if (!launcherUrl) {
|
|
720
|
-
return '';
|
|
721
|
-
}
|
|
722
|
-
let baseUrl = launcherUrl;
|
|
723
|
-
try {
|
|
724
|
-
var _appMeta$componentMou;
|
|
725
|
-
const {
|
|
726
|
-
data: appMeta
|
|
727
|
-
} = await _axios.default.get((0, _urlJoin.default)(launcherUrl, '__blocklet__.js?type=json'), {
|
|
728
|
-
timeout: 5000
|
|
729
|
-
});
|
|
730
|
-
const mountPoint = (_appMeta$componentMou = appMeta.componentMountPoints) === null || _appMeta$componentMou === void 0 ? void 0 : _appMeta$componentMou.find(item => item.did === 'z8iZkFBbrVQxZHvcWWB3Sa2TrfGmSeFz9MSU7');
|
|
731
|
-
const launcherUrlObj = new URL(launcherUrl);
|
|
732
|
-
baseUrl = (0, _urlJoin.default)(launcherUrlObj.origin, mountPoint === null || mountPoint === void 0 ? void 0 : mountPoint.mountPoint);
|
|
733
|
-
} catch (error) {
|
|
734
|
-
console.error(error);
|
|
735
|
-
}
|
|
736
|
-
return baseUrl;
|
|
737
|
-
};
|
|
738
|
-
const getSubscriptionURL = async _ref7 => {
|
|
718
|
+
const getRenewBlockletURL = _ref7 => {
|
|
739
719
|
let {
|
|
740
720
|
launcherUrl = '',
|
|
741
721
|
nftId = '',
|
|
742
722
|
locale = 'en'
|
|
743
723
|
} = _ref7;
|
|
724
|
+
return (0, _urlJoin.default)(launcherUrl, "/instances/".concat(nftId, "/renewal?locale=").concat(locale, "&return-url=").concat(encodeURIComponent(window.location.href)));
|
|
725
|
+
};
|
|
726
|
+
exports.getRenewBlockletURL = getRenewBlockletURL;
|
|
727
|
+
const getSubscriptionURL = async _ref8 => {
|
|
728
|
+
let {
|
|
729
|
+
launcherUrl = '',
|
|
730
|
+
nftId = '',
|
|
731
|
+
locale = 'en'
|
|
732
|
+
} = _ref8;
|
|
744
733
|
if (!launcherUrl) {
|
|
745
734
|
return '';
|
|
746
735
|
}
|
|
747
736
|
let baseUrl = (0, _urlJoin.default)(launcherUrl, '/instances');
|
|
748
737
|
try {
|
|
749
|
-
var _appMeta$
|
|
738
|
+
var _appMeta$componentMou;
|
|
750
739
|
const {
|
|
751
740
|
data: appMeta
|
|
752
741
|
} = await _axios.default.get((0, _urlJoin.default)(launcherUrl, '__blocklet__.js?type=json'), {
|
|
753
742
|
timeout: 5000
|
|
754
743
|
});
|
|
755
|
-
const mountPoint = (_appMeta$
|
|
744
|
+
const mountPoint = (_appMeta$componentMou = appMeta.componentMountPoints) === null || _appMeta$componentMou === void 0 ? void 0 : _appMeta$componentMou.find(item => item.did === 'z8iZy4P83i6AgnNdNUexsh2kBcsDHoqcwPavn');
|
|
756
745
|
const launcherUrlObj = new URL(launcherUrl);
|
|
757
746
|
baseUrl = (0, _urlJoin.default)(launcherUrlObj.origin, mountPoint === null || mountPoint === void 0 ? void 0 : mountPoint.mountPoint, '/nfts');
|
|
758
747
|
} catch (error) {
|
|
@@ -761,33 +750,6 @@ const getSubscriptionURL = async _ref7 => {
|
|
|
761
750
|
return (0, _urlJoin.default)(baseUrl, "/".concat(nftId, "/subscription?locale=").concat(locale, "&return-url=").concat(encodeURIComponent(window.location.href)));
|
|
762
751
|
};
|
|
763
752
|
exports.getSubscriptionURL = getSubscriptionURL;
|
|
764
|
-
const getSubscriptionUrlV2 = async _ref8 => {
|
|
765
|
-
let {
|
|
766
|
-
launcherUrl = '',
|
|
767
|
-
launcherSessionId = '',
|
|
768
|
-
nftDid,
|
|
769
|
-
locale = 'en'
|
|
770
|
-
} = _ref8;
|
|
771
|
-
if (!launcherUrl) {
|
|
772
|
-
return '';
|
|
773
|
-
}
|
|
774
|
-
const baseUrl = await getLauncherBaseURL(launcherUrl);
|
|
775
|
-
return (0, _urlJoin.default)(baseUrl, "/embed/subscription?launcherSessionId=".concat(launcherSessionId, "&nftDid=").concat(nftDid, "&locale=").concat(locale)); // nftDid 是兼容字段
|
|
776
|
-
};
|
|
777
|
-
exports.getSubscriptionUrlV2 = getSubscriptionUrlV2;
|
|
778
|
-
const getManageSubscriptionURL = async _ref9 => {
|
|
779
|
-
let {
|
|
780
|
-
launcherUrl = '',
|
|
781
|
-
launcherSessionId = '',
|
|
782
|
-
locale = 'en'
|
|
783
|
-
} = _ref9;
|
|
784
|
-
if (!launcherUrl) {
|
|
785
|
-
return '';
|
|
786
|
-
}
|
|
787
|
-
const baseUrl = await getLauncherBaseURL(launcherUrl);
|
|
788
|
-
return (0, _urlJoin.default)(baseUrl, "/embed/manage-subscription?launcherSessionId=".concat(launcherSessionId, "&locale=").concat(locale));
|
|
789
|
-
};
|
|
790
|
-
exports.getManageSubscriptionURL = getManageSubscriptionURL;
|
|
791
753
|
const nanoid = exports.nanoid = function nanoid() {
|
|
792
754
|
let length = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 16;
|
|
793
755
|
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-next-
|
|
3
|
+
"version": "1.16.25-next-44800645",
|
|
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-next-
|
|
32
|
-
"@abtnode/constant": "1.16.25-next-
|
|
33
|
-
"@abtnode/util": "1.16.25-next-
|
|
31
|
+
"@abtnode/auth": "1.16.25-next-44800645",
|
|
32
|
+
"@abtnode/constant": "1.16.25-next-44800645",
|
|
33
|
+
"@abtnode/util": "1.16.25-next-44800645",
|
|
34
34
|
"@ahooksjs/use-url-state": "^3.5.1",
|
|
35
35
|
"@arcblock/did": "^1.18.113",
|
|
36
36
|
"@arcblock/did-connect": "^2.9.54",
|
|
@@ -40,10 +40,10 @@
|
|
|
40
40
|
"@arcblock/react-hooks": "^2.9.54",
|
|
41
41
|
"@arcblock/terminal": "^2.9.54",
|
|
42
42
|
"@arcblock/ux": "^2.9.54",
|
|
43
|
-
"@blocklet/constant": "1.16.25-next-
|
|
43
|
+
"@blocklet/constant": "1.16.25-next-44800645",
|
|
44
44
|
"@blocklet/launcher-layout": "2.2.54",
|
|
45
45
|
"@blocklet/list": "^0.12.76",
|
|
46
|
-
"@blocklet/meta": "1.16.25-next-
|
|
46
|
+
"@blocklet/meta": "1.16.25-next-44800645",
|
|
47
47
|
"@blocklet/ui-react": "^2.9.54",
|
|
48
48
|
"@blocklet/uploader": "^0.0.74",
|
|
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": "
|
|
110
|
+
"gitHead": "7d09cee17eb88bcfe6a4b298a0394c5945aa5f2e",
|
|
111
111
|
"exports": {
|
|
112
112
|
".": {
|
|
113
113
|
"import": "./es/index.js",
|
|
@@ -1,174 +0,0 @@
|
|
|
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 } from "react/jsx-runtime";
|
|
16
|
-
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
17
|
-
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
18
|
-
const DEFAULT_LAUNCHER_URL = 'https://launcher.arcblock.io/'; // 兼容: 旧版本的 blocklet.controller 没有 launcherUrl 字段
|
|
19
|
-
|
|
20
|
-
const ALERT_THRESHOLD_MS = 30 * 24 * 60 * 60 * 1000;
|
|
21
|
-
function SubscriptionBlocklet({
|
|
22
|
-
launcherUrl,
|
|
23
|
-
chainHost,
|
|
24
|
-
nftId,
|
|
25
|
-
launcherSessionId,
|
|
26
|
-
...props
|
|
27
|
-
}) {
|
|
28
|
-
const {
|
|
29
|
-
t,
|
|
30
|
-
locale
|
|
31
|
-
} = useLocaleContext();
|
|
32
|
-
const node = useNodeContext();
|
|
33
|
-
const [state, setState] = useSetState({
|
|
34
|
-
safeIframeRef: null,
|
|
35
|
-
popoverAnchorEl: null
|
|
36
|
-
});
|
|
37
|
-
const iframeRef = useRef(null);
|
|
38
|
-
const isMobile = useMediaQuery(x => x.breakpoints.down('md'));
|
|
39
|
-
const {
|
|
40
|
-
sx = {},
|
|
41
|
-
...rest
|
|
42
|
-
} = props;
|
|
43
|
-
const typoKey = isMobile ? 'mobile' : 'desktop';
|
|
44
|
-
const asyncState = useAsyncRetry(async () => {
|
|
45
|
-
const [data, subscriptionURL] = await Promise.all([node.api.getLauncherSession({
|
|
46
|
-
input: {
|
|
47
|
-
launcherSessionId,
|
|
48
|
-
launcherUrl
|
|
49
|
-
}
|
|
50
|
-
}), getSubscriptionUrlV2({
|
|
51
|
-
launcherUrl: launcherUrl || DEFAULT_LAUNCHER_URL,
|
|
52
|
-
nftDid: nftId,
|
|
53
|
-
launcherSessionId,
|
|
54
|
-
locale
|
|
55
|
-
})]);
|
|
56
|
-
return {
|
|
57
|
-
launcherSession: data.launcherSession,
|
|
58
|
-
subscriptionURL
|
|
59
|
-
};
|
|
60
|
-
}, [locale]);
|
|
61
|
-
if (asyncState.loading) {
|
|
62
|
-
return /*#__PURE__*/_jsx(Chip, {
|
|
63
|
-
label: /*#__PURE__*/_jsxs(ChipLabel, {
|
|
64
|
-
children: [!isMobile && t('expiration.desktop.loading'), /*#__PURE__*/_jsx(CircularProgress, {
|
|
65
|
-
size: 16
|
|
66
|
-
})]
|
|
67
|
-
}),
|
|
68
|
-
variant: "success",
|
|
69
|
-
sx: {
|
|
70
|
-
cursor: 'pointer',
|
|
71
|
-
...sx
|
|
72
|
-
},
|
|
73
|
-
...rest
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
if (asyncState.error) {
|
|
77
|
-
console.error(asyncState.error);
|
|
78
|
-
return /*#__PURE__*/_jsx(Chip, {
|
|
79
|
-
label: /*#__PURE__*/_jsx(ChipLabel, {
|
|
80
|
-
children: t(`expiration.${typoKey}.loadFailed`)
|
|
81
|
-
}),
|
|
82
|
-
color: "error",
|
|
83
|
-
variant: "success",
|
|
84
|
-
sx: {
|
|
85
|
-
cursor: 'pointer',
|
|
86
|
-
...sx
|
|
87
|
-
},
|
|
88
|
-
...rest,
|
|
89
|
-
onClick: () => asyncState.retry()
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
const handlePopoverClick = event => {
|
|
93
|
-
setState({
|
|
94
|
-
popoverAnchorEl: event.currentTarget
|
|
95
|
-
});
|
|
96
|
-
};
|
|
97
|
-
const handlePopoverClose = () => {
|
|
98
|
-
setState({
|
|
99
|
-
popoverAnchorEl: null
|
|
100
|
-
});
|
|
101
|
-
};
|
|
102
|
-
const launcherSession = asyncState.value?.launcherSession;
|
|
103
|
-
let status = 'success';
|
|
104
|
-
if (['expired', 'terminated'].includes(asyncState.value?.launcherSession?.statusText)) {
|
|
105
|
-
status = 'error';
|
|
106
|
-
}
|
|
107
|
-
let validity = null;
|
|
108
|
-
if (launcherSession.expirationDate && !launcherSession.subscription) {
|
|
109
|
-
const validityMs = dayjs(launcherSession.expirationDate).diff(dayjs(), 'ms');
|
|
110
|
-
validity = t(`expiration.${typoKey}.tips.${status}`, {
|
|
111
|
-
validity: prettyMs(validityMs, {
|
|
112
|
-
locale: formatPrettyMsLocale(locale),
|
|
113
|
-
compact: true,
|
|
114
|
-
verbose: true
|
|
115
|
-
})
|
|
116
|
-
});
|
|
117
|
-
if (validityMs > 0 && validityMs <= ALERT_THRESHOLD_MS) {
|
|
118
|
-
status = 'warning';
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
122
|
-
children: [/*#__PURE__*/_jsx(Chip, {
|
|
123
|
-
label: /*#__PURE__*/_jsx(ChipLabel, {
|
|
124
|
-
children: validity || launcherSession?.subscription?.product?.name || t('common.subscription')
|
|
125
|
-
}),
|
|
126
|
-
color: status,
|
|
127
|
-
variant: status !== 'success' ? 'contained' : 'outlined',
|
|
128
|
-
sx: {
|
|
129
|
-
cursor: 'pointer',
|
|
130
|
-
...sx
|
|
131
|
-
},
|
|
132
|
-
...rest,
|
|
133
|
-
onClick: handlePopoverClick
|
|
134
|
-
}), /*#__PURE__*/_jsx(Popover, {
|
|
135
|
-
id: "popover-info",
|
|
136
|
-
open: Boolean(state.popoverAnchorEl),
|
|
137
|
-
anchorEl: state.popoverAnchorEl,
|
|
138
|
-
onClose: handlePopoverClose,
|
|
139
|
-
anchorOrigin: {
|
|
140
|
-
vertical: 'bottom',
|
|
141
|
-
horizontal: 'right'
|
|
142
|
-
},
|
|
143
|
-
transformOrigin: {
|
|
144
|
-
vertical: 'top',
|
|
145
|
-
horizontal: 'right'
|
|
146
|
-
},
|
|
147
|
-
children: /*#__PURE__*/_jsx("iframe", {
|
|
148
|
-
ref: iframeRef,
|
|
149
|
-
title: t('common.subscription'),
|
|
150
|
-
width: "360px",
|
|
151
|
-
height: "600px",
|
|
152
|
-
style: {
|
|
153
|
-
border: 0
|
|
154
|
-
},
|
|
155
|
-
src: asyncState.value?.subscriptionURL
|
|
156
|
-
})
|
|
157
|
-
})]
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
SubscriptionBlocklet.propTypes = {
|
|
161
|
-
chainHost: PropTypes.string.isRequired,
|
|
162
|
-
nftId: PropTypes.string,
|
|
163
|
-
launcherSessionId: PropTypes.string,
|
|
164
|
-
sx: PropTypes.object,
|
|
165
|
-
retention: PropTypes.number,
|
|
166
|
-
launcherUrl: PropTypes.string.isRequired
|
|
167
|
-
};
|
|
168
|
-
SubscriptionBlocklet.defaultProps = {
|
|
169
|
-
sx: {},
|
|
170
|
-
retention: 0,
|
|
171
|
-
nftId: '',
|
|
172
|
-
launcherSessionId: ''
|
|
173
|
-
};
|
|
174
|
-
export default SubscriptionBlocklet;
|
|
@@ -1,22 +0,0 @@
|
|
|
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 } from "react/jsx-runtime";
|
|
5
|
-
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
6
|
-
export default function ChipLabel({
|
|
7
|
-
children
|
|
8
|
-
}) {
|
|
9
|
-
return /*#__PURE__*/_jsxs(Box, {
|
|
10
|
-
sx: {
|
|
11
|
-
display: 'flex',
|
|
12
|
-
alignItems: 'center',
|
|
13
|
-
gap: 1
|
|
14
|
-
},
|
|
15
|
-
children: [/*#__PURE__*/_jsx(AccessTimeIcon, {
|
|
16
|
-
fontSize: "small"
|
|
17
|
-
}), children]
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
ChipLabel.propTypes = {
|
|
21
|
-
children: PropTypes.node.isRequired
|
|
22
|
-
};
|
|
@@ -1,186 +0,0 @@
|
|
|
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 : String(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, _asyncState$value2$la, _launcherSession$subs, _launcherSession$subs2, _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
|
-
return {
|
|
73
|
-
launcherSession: data.launcherSession,
|
|
74
|
-
subscriptionURL
|
|
75
|
-
};
|
|
76
|
-
}, [locale]);
|
|
77
|
-
if (asyncState.loading) {
|
|
78
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Chip.default, _objectSpread({
|
|
79
|
-
label: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_chipLabel.default, {
|
|
80
|
-
children: [!isMobile && t('expiration.desktop.loading'), /*#__PURE__*/(0, _jsxRuntime.jsx)(_CircularProgress.default, {
|
|
81
|
-
size: 16
|
|
82
|
-
})]
|
|
83
|
-
}),
|
|
84
|
-
variant: "success",
|
|
85
|
-
sx: _objectSpread({
|
|
86
|
-
cursor: 'pointer'
|
|
87
|
-
}, sx)
|
|
88
|
-
}, rest));
|
|
89
|
-
}
|
|
90
|
-
if (asyncState.error) {
|
|
91
|
-
console.error(asyncState.error);
|
|
92
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Chip.default, _objectSpread(_objectSpread({
|
|
93
|
-
label: /*#__PURE__*/(0, _jsxRuntime.jsx)(_chipLabel.default, {
|
|
94
|
-
children: t("expiration.".concat(typoKey, ".loadFailed"))
|
|
95
|
-
}),
|
|
96
|
-
color: "error",
|
|
97
|
-
variant: "success",
|
|
98
|
-
sx: _objectSpread({
|
|
99
|
-
cursor: 'pointer'
|
|
100
|
-
}, sx)
|
|
101
|
-
}, rest), {}, {
|
|
102
|
-
onClick: () => asyncState.retry()
|
|
103
|
-
}));
|
|
104
|
-
}
|
|
105
|
-
const handlePopoverClick = event => {
|
|
106
|
-
setState({
|
|
107
|
-
popoverAnchorEl: event.currentTarget
|
|
108
|
-
});
|
|
109
|
-
};
|
|
110
|
-
const handlePopoverClose = () => {
|
|
111
|
-
setState({
|
|
112
|
-
popoverAnchorEl: null
|
|
113
|
-
});
|
|
114
|
-
};
|
|
115
|
-
const launcherSession = (_asyncState$value = asyncState.value) === null || _asyncState$value === void 0 ? void 0 : _asyncState$value.launcherSession;
|
|
116
|
-
let status = 'success';
|
|
117
|
-
if (['expired', 'terminated'].includes((_asyncState$value2 = asyncState.value) === null || _asyncState$value2 === void 0 ? void 0 : (_asyncState$value2$la = _asyncState$value2.launcherSession) === null || _asyncState$value2$la === void 0 ? void 0 : _asyncState$value2$la.statusText)) {
|
|
118
|
-
status = 'error';
|
|
119
|
-
}
|
|
120
|
-
let validity = null;
|
|
121
|
-
if (launcherSession.expirationDate && !launcherSession.subscription) {
|
|
122
|
-
const validityMs = (0, _dayjs.default)(launcherSession.expirationDate).diff((0, _dayjs.default)(), 'ms');
|
|
123
|
-
validity = t("expiration.".concat(typoKey, ".tips.").concat(status), {
|
|
124
|
-
validity: (0, _prettyMsI18n.default)(validityMs, {
|
|
125
|
-
locale: (0, _util.formatPrettyMsLocale)(locale),
|
|
126
|
-
compact: true,
|
|
127
|
-
verbose: true
|
|
128
|
-
})
|
|
129
|
-
});
|
|
130
|
-
if (validityMs > 0 && validityMs <= ALERT_THRESHOLD_MS) {
|
|
131
|
-
status = 'warning';
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
135
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Chip.default, _objectSpread(_objectSpread({
|
|
136
|
-
label: /*#__PURE__*/(0, _jsxRuntime.jsx)(_chipLabel.default, {
|
|
137
|
-
children: validity || (launcherSession === null || launcherSession === void 0 ? void 0 : (_launcherSession$subs = launcherSession.subscription) === null || _launcherSession$subs === void 0 ? void 0 : (_launcherSession$subs2 = _launcherSession$subs.product) === null || _launcherSession$subs2 === void 0 ? void 0 : _launcherSession$subs2.name) || t('common.subscription')
|
|
138
|
-
}),
|
|
139
|
-
color: status,
|
|
140
|
-
variant: status !== 'success' ? 'contained' : 'outlined',
|
|
141
|
-
sx: _objectSpread({
|
|
142
|
-
cursor: 'pointer'
|
|
143
|
-
}, sx)
|
|
144
|
-
}, rest), {}, {
|
|
145
|
-
onClick: handlePopoverClick
|
|
146
|
-
})), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Popover.default, {
|
|
147
|
-
id: "popover-info",
|
|
148
|
-
open: Boolean(state.popoverAnchorEl),
|
|
149
|
-
anchorEl: state.popoverAnchorEl,
|
|
150
|
-
onClose: handlePopoverClose,
|
|
151
|
-
anchorOrigin: {
|
|
152
|
-
vertical: 'bottom',
|
|
153
|
-
horizontal: 'right'
|
|
154
|
-
},
|
|
155
|
-
transformOrigin: {
|
|
156
|
-
vertical: 'top',
|
|
157
|
-
horizontal: 'right'
|
|
158
|
-
},
|
|
159
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("iframe", {
|
|
160
|
-
ref: iframeRef,
|
|
161
|
-
title: t('common.subscription'),
|
|
162
|
-
width: "360px",
|
|
163
|
-
height: "600px",
|
|
164
|
-
style: {
|
|
165
|
-
border: 0
|
|
166
|
-
},
|
|
167
|
-
src: (_asyncState$value3 = asyncState.value) === null || _asyncState$value3 === void 0 ? void 0 : _asyncState$value3.subscriptionURL
|
|
168
|
-
})
|
|
169
|
-
})]
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
SubscriptionBlocklet.propTypes = {
|
|
173
|
-
chainHost: _propTypes.default.string.isRequired,
|
|
174
|
-
nftId: _propTypes.default.string,
|
|
175
|
-
launcherSessionId: _propTypes.default.string,
|
|
176
|
-
sx: _propTypes.default.object,
|
|
177
|
-
retention: _propTypes.default.number,
|
|
178
|
-
launcherUrl: _propTypes.default.string.isRequired
|
|
179
|
-
};
|
|
180
|
-
SubscriptionBlocklet.defaultProps = {
|
|
181
|
-
sx: {},
|
|
182
|
-
retention: 0,
|
|
183
|
-
nftId: '',
|
|
184
|
-
launcherSessionId: ''
|
|
185
|
-
};
|
|
186
|
-
var _default = exports.default = SubscriptionBlocklet;
|
|
@@ -1,29 +0,0 @@
|
|
|
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
|
-
};
|