@abtnode/ux 1.16.15-beta-04d1e821 → 1.16.15-beta-933eb977
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/subscription.js +23 -14
- package/es/util/index.js +19 -2
- package/lib/subscription.js +24 -16
- package/lib/util/index.js +18 -2
- package/package.json +7 -7
package/es/subscription.js
CHANGED
|
@@ -15,6 +15,7 @@ import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
15
15
|
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
16
16
|
const ALERT_THRESHOLD_MS = 30 * 24 * 60 * 60 * 1000;
|
|
17
17
|
function Subscription({
|
|
18
|
+
launcherUrl,
|
|
18
19
|
chainHost,
|
|
19
20
|
nftId,
|
|
20
21
|
retention,
|
|
@@ -33,8 +34,18 @@ function Subscription({
|
|
|
33
34
|
sx = {},
|
|
34
35
|
...rest
|
|
35
36
|
} = props;
|
|
36
|
-
const
|
|
37
|
-
|
|
37
|
+
const asyncState = useAsyncRetry(async () => {
|
|
38
|
+
const [asset, subscriptionURL] = await Promise.all([getAsset(chainHost, nftId), getSubscriptionURL({
|
|
39
|
+
launcherUrl,
|
|
40
|
+
nftId,
|
|
41
|
+
locale
|
|
42
|
+
})]);
|
|
43
|
+
return {
|
|
44
|
+
asset,
|
|
45
|
+
subscriptionURL
|
|
46
|
+
};
|
|
47
|
+
}, [locale]);
|
|
48
|
+
if (asyncState.loading) {
|
|
38
49
|
return /*#__PURE__*/_jsxs(Box, {
|
|
39
50
|
sx: {
|
|
40
51
|
display: 'flex',
|
|
@@ -49,8 +60,8 @@ function Subscription({
|
|
|
49
60
|
}), t('expiration.loading')]
|
|
50
61
|
});
|
|
51
62
|
}
|
|
52
|
-
if (
|
|
53
|
-
console.error(
|
|
63
|
+
if (asyncState.error) {
|
|
64
|
+
console.error(asyncState.error);
|
|
54
65
|
return /*#__PURE__*/_jsx(Chip, {
|
|
55
66
|
label: t('expiration.loadFailed'),
|
|
56
67
|
color: "error",
|
|
@@ -60,11 +71,10 @@ function Subscription({
|
|
|
60
71
|
...sx
|
|
61
72
|
},
|
|
62
73
|
...rest,
|
|
63
|
-
onClick: () =>
|
|
74
|
+
onClick: () => asyncState.retry()
|
|
64
75
|
});
|
|
65
76
|
}
|
|
66
|
-
const expirationDate = getAssetExpiration(
|
|
67
|
-
const launcherUrl = assetState.value?.data?.value?.launcherUrl;
|
|
77
|
+
const expirationDate = getAssetExpiration(asyncState.value?.asset);
|
|
68
78
|
const isExpired = dayjs(expirationDate).isBefore(dayjs());
|
|
69
79
|
const validityMs = dayjs(expirationDate).diff(dayjs(), 'ms');
|
|
70
80
|
let status = 'success';
|
|
@@ -122,11 +132,7 @@ function Subscription({
|
|
|
122
132
|
style: {
|
|
123
133
|
border: 0
|
|
124
134
|
},
|
|
125
|
-
src:
|
|
126
|
-
launcherUrl,
|
|
127
|
-
nftId,
|
|
128
|
-
locale
|
|
129
|
-
})
|
|
135
|
+
src: asyncState.value?.subscriptionURL
|
|
130
136
|
})
|
|
131
137
|
})]
|
|
132
138
|
});
|
|
@@ -135,10 +141,13 @@ Subscription.propTypes = {
|
|
|
135
141
|
chainHost: PropTypes.string.isRequired,
|
|
136
142
|
nftId: PropTypes.string.isRequired,
|
|
137
143
|
sx: PropTypes.object,
|
|
138
|
-
retention: PropTypes.number
|
|
144
|
+
retention: PropTypes.number,
|
|
145
|
+
launcherUrl: PropTypes.string
|
|
139
146
|
};
|
|
140
147
|
Subscription.defaultProps = {
|
|
141
148
|
sx: {},
|
|
142
|
-
retention: 0
|
|
149
|
+
retention: 0,
|
|
150
|
+
launcherUrl: 'https://launcher.arcblock.io/' // 兼容: 旧版本的 blocklet.controller 没有 launcherUrl 字段
|
|
143
151
|
};
|
|
152
|
+
|
|
144
153
|
export default Subscription;
|
package/es/util/index.js
CHANGED
|
@@ -590,9 +590,26 @@ export const getRenewBlockletURL = ({
|
|
|
590
590
|
nftId = '',
|
|
591
591
|
locale = 'en'
|
|
592
592
|
}) => joinUrl(launcherUrl, `/instances/${nftId}/renewal?locale=${locale}&return-url=${encodeURIComponent(window.location.href)}`);
|
|
593
|
-
export const getSubscriptionURL = ({
|
|
593
|
+
export const getSubscriptionURL = async ({
|
|
594
594
|
launcherUrl = '',
|
|
595
595
|
nftId = '',
|
|
596
596
|
locale = 'en'
|
|
597
|
-
}) =>
|
|
597
|
+
}) => {
|
|
598
|
+
if (!launcherUrl) {
|
|
599
|
+
return '';
|
|
600
|
+
}
|
|
601
|
+
let baseUrl = joinUrl(launcherUrl, '/instances');
|
|
602
|
+
try {
|
|
603
|
+
const {
|
|
604
|
+
data: appMeta
|
|
605
|
+
} = await axios.get(joinUrl(launcherUrl, '__blocklet__.js?type=json'), {
|
|
606
|
+
timeout: 5000
|
|
607
|
+
});
|
|
608
|
+
const mountPoint = appMeta.componentMountPoints?.find(item => item.did === 'z8iZy4P83i6AgnNdNUexsh2kBcsDHoqcwPavn');
|
|
609
|
+
baseUrl = joinUrl(launcherUrl, mountPoint?.mountPoint, '/nfts');
|
|
610
|
+
} catch (error) {
|
|
611
|
+
console.error(error);
|
|
612
|
+
}
|
|
613
|
+
return joinUrl(baseUrl, `/${nftId}/subscription?locale=${locale}&return-url=${encodeURIComponent(window.location.href)}`);
|
|
614
|
+
};
|
|
598
615
|
export const nanoid = (length = 16) => [...Array(length)].map(() => Math.random().toString(36)[2]).join('');
|
package/lib/subscription.js
CHANGED
|
@@ -17,7 +17,7 @@ var _useAsyncRetry = _interopRequireDefault(require("react-use/lib/useAsyncRetry
|
|
|
17
17
|
var _useSetState = _interopRequireDefault(require("react-use/lib/useSetState"));
|
|
18
18
|
var _util = require("./util");
|
|
19
19
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
20
|
-
const _excluded = ["chainHost", "nftId", "retention"],
|
|
20
|
+
const _excluded = ["launcherUrl", "chainHost", "nftId", "retention"],
|
|
21
21
|
_excluded2 = ["sx"];
|
|
22
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
23
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
@@ -29,8 +29,9 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
|
|
|
29
29
|
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; }
|
|
30
30
|
const ALERT_THRESHOLD_MS = 30 * 24 * 60 * 60 * 1000;
|
|
31
31
|
function Subscription(_ref) {
|
|
32
|
-
var
|
|
32
|
+
var _asyncState$value, _asyncState$value2;
|
|
33
33
|
let {
|
|
34
|
+
launcherUrl,
|
|
34
35
|
chainHost,
|
|
35
36
|
nftId,
|
|
36
37
|
retention
|
|
@@ -49,8 +50,18 @@ function Subscription(_ref) {
|
|
|
49
50
|
sx = {}
|
|
50
51
|
} = props,
|
|
51
52
|
rest = _objectWithoutProperties(props, _excluded2);
|
|
52
|
-
const
|
|
53
|
-
|
|
53
|
+
const asyncState = (0, _useAsyncRetry.default)(async () => {
|
|
54
|
+
const [asset, subscriptionURL] = await Promise.all([(0, _util.getAsset)(chainHost, nftId), (0, _util.getSubscriptionURL)({
|
|
55
|
+
launcherUrl,
|
|
56
|
+
nftId,
|
|
57
|
+
locale
|
|
58
|
+
})]);
|
|
59
|
+
return {
|
|
60
|
+
asset,
|
|
61
|
+
subscriptionURL
|
|
62
|
+
};
|
|
63
|
+
}, [locale]);
|
|
64
|
+
if (asyncState.loading) {
|
|
54
65
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Box.default, _objectSpread(_objectSpread({
|
|
55
66
|
sx: _objectSpread({
|
|
56
67
|
display: 'flex',
|
|
@@ -64,8 +75,8 @@ function Subscription(_ref) {
|
|
|
64
75
|
}), t('expiration.loading')]
|
|
65
76
|
}));
|
|
66
77
|
}
|
|
67
|
-
if (
|
|
68
|
-
console.error(
|
|
78
|
+
if (asyncState.error) {
|
|
79
|
+
console.error(asyncState.error);
|
|
69
80
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Chip.default, _objectSpread(_objectSpread({
|
|
70
81
|
label: t('expiration.loadFailed'),
|
|
71
82
|
color: "error",
|
|
@@ -74,11 +85,10 @@ function Subscription(_ref) {
|
|
|
74
85
|
cursor: 'pointer'
|
|
75
86
|
}, sx)
|
|
76
87
|
}, rest), {}, {
|
|
77
|
-
onClick: () =>
|
|
88
|
+
onClick: () => asyncState.retry()
|
|
78
89
|
}));
|
|
79
90
|
}
|
|
80
|
-
const expirationDate = (0, _util.getAssetExpiration)(
|
|
81
|
-
const launcherUrl = (_assetState$value = assetState.value) === null || _assetState$value === void 0 ? void 0 : (_assetState$value$dat = _assetState$value.data) === null || _assetState$value$dat === void 0 ? void 0 : (_assetState$value$dat2 = _assetState$value$dat.value) === null || _assetState$value$dat2 === void 0 ? void 0 : _assetState$value$dat2.launcherUrl;
|
|
91
|
+
const expirationDate = (0, _util.getAssetExpiration)((_asyncState$value = asyncState.value) === null || _asyncState$value === void 0 ? void 0 : _asyncState$value.asset);
|
|
82
92
|
const isExpired = (0, _dayjs.default)(expirationDate).isBefore((0, _dayjs.default)());
|
|
83
93
|
const validityMs = (0, _dayjs.default)(expirationDate).diff((0, _dayjs.default)(), 'ms');
|
|
84
94
|
let status = 'success';
|
|
@@ -135,11 +145,7 @@ function Subscription(_ref) {
|
|
|
135
145
|
style: {
|
|
136
146
|
border: 0
|
|
137
147
|
},
|
|
138
|
-
src: (0
|
|
139
|
-
launcherUrl,
|
|
140
|
-
nftId,
|
|
141
|
-
locale
|
|
142
|
-
})
|
|
148
|
+
src: (_asyncState$value2 = asyncState.value) === null || _asyncState$value2 === void 0 ? void 0 : _asyncState$value2.subscriptionURL
|
|
143
149
|
})
|
|
144
150
|
})]
|
|
145
151
|
});
|
|
@@ -148,11 +154,13 @@ Subscription.propTypes = {
|
|
|
148
154
|
chainHost: _propTypes.default.string.isRequired,
|
|
149
155
|
nftId: _propTypes.default.string.isRequired,
|
|
150
156
|
sx: _propTypes.default.object,
|
|
151
|
-
retention: _propTypes.default.number
|
|
157
|
+
retention: _propTypes.default.number,
|
|
158
|
+
launcherUrl: _propTypes.default.string
|
|
152
159
|
};
|
|
153
160
|
Subscription.defaultProps = {
|
|
154
161
|
sx: {},
|
|
155
|
-
retention: 0
|
|
162
|
+
retention: 0,
|
|
163
|
+
launcherUrl: 'https://launcher.arcblock.io/' // 兼容: 旧版本的 blocklet.controller 没有 launcherUrl 字段
|
|
156
164
|
};
|
|
157
165
|
var _default = Subscription;
|
|
158
166
|
exports.default = _default;
|
package/lib/util/index.js
CHANGED
|
@@ -695,13 +695,29 @@ const getRenewBlockletURL = _ref7 => {
|
|
|
695
695
|
return (0, _urlJoin.default)(launcherUrl, "/instances/".concat(nftId, "/renewal?locale=").concat(locale, "&return-url=").concat(encodeURIComponent(window.location.href)));
|
|
696
696
|
};
|
|
697
697
|
exports.getRenewBlockletURL = getRenewBlockletURL;
|
|
698
|
-
const getSubscriptionURL = _ref8 => {
|
|
698
|
+
const getSubscriptionURL = async _ref8 => {
|
|
699
699
|
let {
|
|
700
700
|
launcherUrl = '',
|
|
701
701
|
nftId = '',
|
|
702
702
|
locale = 'en'
|
|
703
703
|
} = _ref8;
|
|
704
|
-
|
|
704
|
+
if (!launcherUrl) {
|
|
705
|
+
return '';
|
|
706
|
+
}
|
|
707
|
+
let baseUrl = (0, _urlJoin.default)(launcherUrl, '/instances');
|
|
708
|
+
try {
|
|
709
|
+
var _appMeta$componentMou;
|
|
710
|
+
const {
|
|
711
|
+
data: appMeta
|
|
712
|
+
} = await _axios.default.get((0, _urlJoin.default)(launcherUrl, '__blocklet__.js?type=json'), {
|
|
713
|
+
timeout: 5000
|
|
714
|
+
});
|
|
715
|
+
const mountPoint = (_appMeta$componentMou = appMeta.componentMountPoints) === null || _appMeta$componentMou === void 0 ? void 0 : _appMeta$componentMou.find(item => item.did === 'z8iZy4P83i6AgnNdNUexsh2kBcsDHoqcwPavn');
|
|
716
|
+
baseUrl = (0, _urlJoin.default)(launcherUrl, mountPoint === null || mountPoint === void 0 ? void 0 : mountPoint.mountPoint, '/nfts');
|
|
717
|
+
} catch (error) {
|
|
718
|
+
console.error(error);
|
|
719
|
+
}
|
|
720
|
+
return (0, _urlJoin.default)(baseUrl, "/".concat(nftId, "/subscription?locale=").concat(locale, "&return-url=").concat(encodeURIComponent(window.location.href)));
|
|
705
721
|
};
|
|
706
722
|
exports.getSubscriptionURL = getSubscriptionURL;
|
|
707
723
|
const nanoid = function nanoid() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abtnode/ux",
|
|
3
|
-
"version": "1.16.15-beta-
|
|
3
|
+
"version": "1.16.15-beta-933eb977",
|
|
4
4
|
"description": "UX components shared across abtnode packages",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
"author": "linchen <linchen1987@foxmail.com> (http://github.com/linchen1987)",
|
|
28
28
|
"license": "Apache-2.0",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@abtnode/auth": "1.16.15-beta-
|
|
31
|
-
"@abtnode/constant": "1.16.15-beta-
|
|
32
|
-
"@abtnode/util": "1.16.15-beta-
|
|
30
|
+
"@abtnode/auth": "1.16.15-beta-933eb977",
|
|
31
|
+
"@abtnode/constant": "1.16.15-beta-933eb977",
|
|
32
|
+
"@abtnode/util": "1.16.15-beta-933eb977",
|
|
33
33
|
"@ahooksjs/use-url-state": "^3.5.1",
|
|
34
34
|
"@arcblock/did": "^1.18.89",
|
|
35
35
|
"@arcblock/did-connect": "^2.7.6",
|
|
@@ -39,10 +39,10 @@
|
|
|
39
39
|
"@arcblock/react-hooks": "^2.7.6",
|
|
40
40
|
"@arcblock/terminal": "^2.7.6",
|
|
41
41
|
"@arcblock/ux": "^2.7.6",
|
|
42
|
-
"@blocklet/constant": "1.16.15-beta-
|
|
42
|
+
"@blocklet/constant": "1.16.15-beta-933eb977",
|
|
43
43
|
"@blocklet/launcher-layout": "2.1.93",
|
|
44
44
|
"@blocklet/list": "^0.12.27",
|
|
45
|
-
"@blocklet/meta": "1.16.15-beta-
|
|
45
|
+
"@blocklet/meta": "1.16.15-beta-933eb977",
|
|
46
46
|
"@blocklet/ui-react": "^2.7.6",
|
|
47
47
|
"@emotion/react": "^11.10.4",
|
|
48
48
|
"@emotion/styled": "^11.10.4",
|
|
@@ -98,7 +98,7 @@
|
|
|
98
98
|
"babel-plugin-inline-react-svg": "^1.1.2",
|
|
99
99
|
"glob": "^10.3.3"
|
|
100
100
|
},
|
|
101
|
-
"gitHead": "
|
|
101
|
+
"gitHead": "d98826a347c05fb1c3dc50a44d8d492290c406ad",
|
|
102
102
|
"exports": {
|
|
103
103
|
".": {
|
|
104
104
|
"import": "./es/index.js",
|