@abtnode/ux 1.16.14-beta-c308dc3b → 1.16.14-beta-963cb583

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 (213) hide show
  1. package/es/actions.js +97 -0
  2. package/es/analytics/card.js +92 -0
  3. package/es/analytics/chart.js +96 -0
  4. package/es/analytics/cpu.js +36 -0
  5. package/es/analytics/disk.js +111 -0
  6. package/es/analytics/memory.js +72 -0
  7. package/es/analytics/runtime.js +173 -0
  8. package/es/analytics/traffic.js +259 -0
  9. package/es/blocklet/access/config-access.js +307 -0
  10. package/es/blocklet/access/index.js +216 -0
  11. package/es/blocklet/actions.js +474 -0
  12. package/es/blocklet/add-cert.js +177 -0
  13. package/es/blocklet/agreement-app.js +21 -0
  14. package/es/blocklet/agreement.js +127 -0
  15. package/es/blocklet/app-avatar.js +57 -0
  16. package/es/blocklet/audit-logs.js +259 -0
  17. package/es/blocklet/blocklet-source.js +48 -0
  18. package/es/blocklet/bundle-avatar.js +64 -0
  19. package/es/blocklet/component/add.js +1313 -0
  20. package/es/blocklet/component/configuration.js +122 -0
  21. package/es/blocklet/component/delete.js +134 -0
  22. package/es/blocklet/component/environment.js +370 -0
  23. package/es/blocklet/component/index.js +975 -0
  24. package/es/blocklet/component/line.js +20 -0
  25. package/es/blocklet/component/navigation/locale-tabs.js +225 -0
  26. package/es/blocklet/component/navigation/navigation-actions.js +112 -0
  27. package/es/blocklet/component/navigation/navigation-dialog.js +607 -0
  28. package/es/blocklet/component/navigation/navigation-preview.js +101 -0
  29. package/es/blocklet/component/navigation/simple-select.js +124 -0
  30. package/es/blocklet/component/select-store.js +155 -0
  31. package/es/blocklet/component/selected/index.js +94 -0
  32. package/es/blocklet/component/setting.js +109 -0
  33. package/es/blocklet/component/sortable-tree.js +126 -0
  34. package/es/blocklet/component/space-connector.js +199 -0
  35. package/es/blocklet/component/space-selector.js +178 -0
  36. package/es/blocklet/component/start.js +101 -0
  37. package/es/blocklet/component/store-blocklet-list.js +200 -0
  38. package/es/blocklet/component/switch-control.js +57 -0
  39. package/es/blocklet/config-navigation.js +331 -0
  40. package/es/blocklet/configuration.js +603 -0
  41. package/es/blocklet/disk-info.js +75 -0
  42. package/es/blocklet/icons.js +18 -0
  43. package/es/blocklet/install-from-url.js +337 -0
  44. package/es/blocklet/log.js +90 -0
  45. package/es/blocklet/migration.js +149 -0
  46. package/es/blocklet/mode.js +19 -0
  47. package/es/blocklet/notification/email.js +257 -0
  48. package/es/blocklet/notification/index.js +49 -0
  49. package/es/blocklet/oauth/auth0.js +145 -0
  50. package/es/blocklet/oauth/common-settings.js +133 -0
  51. package/es/blocklet/oauth/federated-detail-dialog.js +175 -0
  52. package/es/blocklet/oauth/federated-invite-dialog.js +83 -0
  53. package/es/blocklet/oauth/federated-join-dialog.js +111 -0
  54. package/es/blocklet/oauth/federated-site-list.js +338 -0
  55. package/es/blocklet/oauth/federated.js +81 -0
  56. package/es/blocklet/oauth/index.js +69 -0
  57. package/es/blocklet/overview.js +293 -0
  58. package/es/blocklet/page-group.js +19 -0
  59. package/es/blocklet/preferences/app-sk.js +142 -0
  60. package/es/blocklet/preferences/index.js +305 -0
  61. package/es/blocklet/purchase/common.js +95 -0
  62. package/es/blocklet/purchase/component-purchase.js +237 -0
  63. package/es/blocklet/purchase/index.js +4 -0
  64. package/es/blocklet/router/action/add-domain-alias.js +167 -0
  65. package/es/blocklet/router/action/add-rule.js +211 -0
  66. package/es/blocklet/router/action/config-routing-rule.js +232 -0
  67. package/es/blocklet/router/action/delete-domain-alias.js +99 -0
  68. package/es/blocklet/router/action/delete-rule.js +108 -0
  69. package/es/blocklet/router/action/update-rule.js +209 -0
  70. package/es/blocklet/router/domain-actions.js +64 -0
  71. package/es/blocklet/router/domain-status.js +88 -0
  72. package/es/blocklet/router/rule-actions.js +66 -0
  73. package/es/blocklet/router/rule-list.js +190 -0
  74. package/es/blocklet/router/util.js +131 -0
  75. package/es/blocklet/runtime-info.js +68 -0
  76. package/es/blocklet/status.js +91 -0
  77. package/es/blocklet/storage/action.js +134 -0
  78. package/es/blocklet/storage/backups.js +241 -0
  79. package/es/blocklet/storage/connect-to.js +372 -0
  80. package/es/blocklet/storage/connected.js +198 -0
  81. package/es/blocklet/storage/delete.js +113 -0
  82. package/es/blocklet/storage/disconnect.js +243 -0
  83. package/es/blocklet/storage/index.js +19 -0
  84. package/es/blocklet/storage/item.js +558 -0
  85. package/es/blocklet/storage/preview-nft.js +286 -0
  86. package/es/blocklet/transfer-owner.js +198 -0
  87. package/es/blocklet/types.js +18 -0
  88. package/es/blocklet/util.js +145 -0
  89. package/es/blocklet/version.js +141 -0
  90. package/es/card-selector.js +134 -0
  91. package/es/certificate.js +105 -0
  92. package/es/chain.js +13 -0
  93. package/es/click-to-copy.js +22 -0
  94. package/es/confirm.js +149 -0
  95. package/es/contexts/audit-log.js +152 -0
  96. package/es/contexts/blocklet.js +10 -0
  97. package/es/contexts/deleting-blocklets.js +70 -0
  98. package/es/contexts/node.js +17 -0
  99. package/es/contexts/session.js +8 -0
  100. package/es/contexts/team.js +10 -0
  101. package/es/delete-confirm.js +121 -0
  102. package/es/did-address.js +46 -0
  103. package/es/dot.js +14 -0
  104. package/es/exchange-passport.js +102 -0
  105. package/es/form/form-select-input.js +184 -0
  106. package/es/form/form-text-input.js +178 -0
  107. package/es/form/form-wrapper.js +88 -0
  108. package/es/form/input-triggers.js +98 -0
  109. package/es/form/required.js +8 -0
  110. package/es/hooks/blocklet.js +229 -0
  111. package/es/hooks/confirm.js +90 -0
  112. package/es/hooks/mobile-width.js +11 -0
  113. package/es/hooks/url-evaluation.js +155 -0
  114. package/es/hooks/use-app-logo.js +16 -0
  115. package/es/hooks/use-backup-progress.js +31 -0
  116. package/es/hooks/use-blocklet-info-for-connect-did-spaces.js +50 -0
  117. package/es/hooks/use-bundle-logo.js +27 -0
  118. package/es/hooks/use-navigation.js +347 -0
  119. package/es/hooks/use-passport-id.js +14 -0
  120. package/es/hooks/use-subscription.js +22 -0
  121. package/es/icons/empty-space-nft.svg +59 -0
  122. package/es/icons/empty-spaces-nft.svg +58 -0
  123. package/es/icons/long-arrow.svg +5 -0
  124. package/es/icons/space-connected.svg +3 -0
  125. package/es/icons/space-disconnect.svg +3 -0
  126. package/es/index.js +3 -0
  127. package/es/invitation/invitation-app.js +58 -0
  128. package/es/invitation/invitation-login.js +68 -0
  129. package/es/invitation/invitation-passport.js +146 -0
  130. package/es/invitation/invitation-receive.js +138 -0
  131. package/es/invitation/invitation-success.js +93 -0
  132. package/es/invitation/invitation-user.js +90 -0
  133. package/es/invitation/invitation.js +90 -0
  134. package/es/issue-passport.js +142 -0
  135. package/es/launch-blocklet/content-layout.js +58 -0
  136. package/es/launch-blocklet/page-header.js +43 -0
  137. package/es/layout/addon.js +114 -0
  138. package/es/layout/feedback.js +55 -0
  139. package/es/locales/en.js +1541 -0
  140. package/es/locales/index.js +9 -0
  141. package/es/locales/zh.js +1544 -0
  142. package/es/logs/clock.js +11 -0
  143. package/es/logs/download.js +132 -0
  144. package/es/logs/log-terminal.js +253 -0
  145. package/es/lost-passport.js +452 -0
  146. package/es/nav-logo.js +219 -0
  147. package/es/passport-tag.js +43 -0
  148. package/es/permission.js +57 -0
  149. package/es/relative-time.js +53 -0
  150. package/es/result-message.js +11 -0
  151. package/es/schema-form/color-input.js +98 -0
  152. package/es/schema-form/common-prop-types.js +13 -0
  153. package/es/schema-form/index.js +215 -0
  154. package/es/schema-form/passport-input.js +55 -0
  155. package/es/schema-form/text-input.js +57 -0
  156. package/es/store/add.js +179 -0
  157. package/es/store/delete.js +96 -0
  158. package/es/store/item.js +76 -0
  159. package/es/subscription.js +144 -0
  160. package/es/table-icons.js +34 -0
  161. package/es/table.js +52 -0
  162. package/es/tag.js +21 -0
  163. package/es/team/members/actions.js +89 -0
  164. package/es/team/members/index.js +636 -0
  165. package/es/team/members/invitations.js +188 -0
  166. package/es/team/members/invite-member.js +208 -0
  167. package/es/team/members/issue-passport.js +152 -0
  168. package/es/team/members/member.js +408 -0
  169. package/es/team/members/passport-issuances.js +155 -0
  170. package/es/team/members/passports.js +364 -0
  171. package/es/team/members/toggle-user-approval.js +122 -0
  172. package/es/team/members/transfer-node.js +256 -0
  173. package/es/team/members/util.js +14 -0
  174. package/es/team/passports/color.js +127 -0
  175. package/es/team/passports/detail.js +312 -0
  176. package/es/team/passports/index.js +282 -0
  177. package/es/team/passports/mutate-role.js +198 -0
  178. package/es/team/passports/trusted-factories.js +221 -0
  179. package/es/team/passports/trusted-factory.js +343 -0
  180. package/es/team/passports/trusted-issuer.js +296 -0
  181. package/es/team/passports/trusted-issuers.js +226 -0
  182. package/es/team/search-input.js +46 -0
  183. package/es/team/styles/dialog.js +72 -0
  184. package/es/team/styles/list-header.js +31 -0
  185. package/es/util/api.js +6 -0
  186. package/es/util/constants.js +2 -0
  187. package/es/util/index.js +598 -0
  188. package/es/util/mode.js +4 -0
  189. package/es/util/space-gateway.js +51 -0
  190. package/es/util/spaces.js +160 -0
  191. package/es/who-can-access/config.js +38 -0
  192. package/es/wrap-locale.js +15 -0
  193. package/lib/blocklet/component/add.js +5 -0
  194. package/lib/blocklet/component/selected/index.js +47 -0
  195. package/lib/blocklet/component/space-connector.js +1 -1
  196. package/lib/blocklet/component/space-selector.js +1 -1
  197. package/lib/blocklet/storage/backups.js +1 -1
  198. package/lib/blocklet/storage/connect-to.js +6 -7
  199. package/lib/blocklet/storage/connected.js +1 -1
  200. package/lib/blocklet/storage/disconnect.js +1 -1
  201. package/lib/blocklet/storage/index.js +1 -1
  202. package/lib/blocklet/storage/item.js +1 -1
  203. package/lib/card-selector.js +14 -14
  204. package/lib/invitation/invitation-passport.js +7 -6
  205. package/lib/invitation/invitation-receive.js +1 -1
  206. package/lib/locales/en.js +12 -5
  207. package/lib/locales/zh.js +10 -3
  208. package/lib/lost-passport.js +2 -2
  209. package/lib/schema-form/passport-input.js +12 -11
  210. package/lib/team/passports/color.js +14 -14
  211. package/lib/team/passports/trusted-factory.js +1 -1
  212. package/lib/util/spaces.js +13 -1
  213. package/package.json +88 -21
@@ -0,0 +1,241 @@
1
+ import Tag from '@arcblock/ux/lib/Tag';
2
+ import Datatable from '@arcblock/ux/lib/Datatable';
3
+ import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
4
+ import { Box, CircularProgress, Icon, Link, Tooltip, Typography } from '@mui/material';
5
+ import React, { useCallback, useState } from 'react';
6
+ import { isEmpty, isNull, throttle } from 'lodash';
7
+ import { useAsyncEffect } from 'ahooks';
8
+ import dayjs from '@abtnode/util/lib/dayjs';
9
+ import HelpOutlineIcon from '@mui/icons-material/HelpOutline';
10
+ import { array, object } from 'prop-types';
11
+ import { useNodeContext } from '../../contexts/node';
12
+ import { useBlockletContext } from '../../contexts/blocklet';
13
+
14
+ /**
15
+ * @description
16
+ * @param {{ blocklet: import('@abtnode/client').BlockletState }} { blocklet }
17
+ * @return {{backups: import('@abtnode/client').Backup[]}}
18
+ */
19
+ import { jsx as _jsx } from "react/jsx-runtime";
20
+ import { jsxs as _jsxs } from "react/jsx-runtime";
21
+ import { Fragment as _Fragment } from "react/jsx-runtime";
22
+ function useBackups({
23
+ blocklet,
24
+ loading,
25
+ progress
26
+ }) {
27
+ const [backups, setBackups] = useState([]);
28
+ const {
29
+ api
30
+ } = useNodeContext();
31
+ // eslint-disable-next-line react-hooks/exhaustive-deps
32
+ const fetchBackups = useCallback(throttle(async () => {
33
+ const {
34
+ backups: data
35
+ } = await api.getBlockletBackups({
36
+ input: {
37
+ did: blocklet?.meta?.did
38
+ }
39
+ });
40
+ setBackups(data ?? []);
41
+ }, 2000), []);
42
+
43
+ // eslint-disable-next-line require-await
44
+ useAsyncEffect(async () => {
45
+ fetchBackups();
46
+ }, [blocklet?.meta?.did, progress, loading]);
47
+ return {
48
+ backups
49
+ };
50
+ }
51
+
52
+ /**
53
+ * @description
54
+ * @param {{
55
+ * progress: any,
56
+ * spaceGateways: Array<import('./connected').SpaceGateway>
57
+ * }} { progress, spaceGateways, ...rest }
58
+ * @return {*}
59
+ */
60
+ function SpacesBackupRecords({
61
+ progress,
62
+ spaceGateways,
63
+ ...rest
64
+ }) {
65
+ const {
66
+ t,
67
+ locale
68
+ } = useLocaleContext();
69
+ const {
70
+ blocklet
71
+ } = useBlockletContext();
72
+ const {
73
+ backups
74
+ } = useBackups({
75
+ blocklet,
76
+ progress
77
+ });
78
+ const columns = [{
79
+ label: 'DID Spaces',
80
+ name: 'target',
81
+ options: {
82
+ // eslint-disable-next-line react/no-unstable-nested-components
83
+ customBodyRenderLite: index => {
84
+ // eslint-disable-next-line no-unused-vars
85
+ const {
86
+ targetUrl,
87
+ targetName
88
+ } = backups[index];
89
+ const spaceName = spaceGateways.find(spaceGateway => targetUrl?.includes(spaceGateway?.url))?.name || targetName || 'DID Space';
90
+ return /*#__PURE__*/_jsx(Link, {
91
+ fontSize: "16px",
92
+ href: targetUrl,
93
+ target: "_blank",
94
+ children: spaceName
95
+ });
96
+ }
97
+ }
98
+ }, {
99
+ label: t('common.strategy'),
100
+ name: 'strategy',
101
+ options: {
102
+ /**
103
+ * @param {0 | 1} strategy
104
+ * @returns {React.ReactNode}
105
+ */
106
+ // eslint-disable-next-line react/no-unstable-nested-components
107
+ customBodyRender: strategy => {
108
+ const text = strategy === 0 ? t('common.auto') : t('common.manual');
109
+ return /*#__PURE__*/_jsx(Tag, {
110
+ children: text
111
+ });
112
+ }
113
+ }
114
+ }, {
115
+ label: t('common.startTime'),
116
+ name: 'createdAt',
117
+ options: {
118
+ /**
119
+ * @param {0 | 1} strategy
120
+ * @returns {React.ReactNode}
121
+ */
122
+ // eslint-disable-next-line react/no-unstable-nested-components
123
+ customBodyRender: createdAt => {
124
+ return dayjs(createdAt).format('YYYY-MM-DD HH:mm:ss');
125
+ }
126
+ }
127
+ }, {
128
+ label: t('common.endTime'),
129
+ name: 'updatedAt',
130
+ options: {
131
+ /**
132
+ * @param {string} updatedAt
133
+ * @returns {React.ReactNode}
134
+ */
135
+ // eslint-disable-next-line react/no-unstable-nested-components
136
+ customBodyRender: updatedAt => {
137
+ if (isEmpty(updatedAt)) {
138
+ return '';
139
+ }
140
+ return dayjs(updatedAt).format('YYYY-MM-DD HH:mm:ss');
141
+ }
142
+ }
143
+ }, {
144
+ label: t('common.status'),
145
+ name: 'status',
146
+ options: {
147
+ /**
148
+ * @param {string} status
149
+ * @returns {React.ReactNode}
150
+ */
151
+ // eslint-disable-next-line react/no-unstable-nested-components
152
+ customBodyRenderLite: index => {
153
+ const {
154
+ status,
155
+ message
156
+ } = backups?.[index] ?? {};
157
+ if (isNull(status)) {
158
+ return /*#__PURE__*/_jsxs(Typography, {
159
+ display: "inline-flex",
160
+ alignItems: "center",
161
+ fontSize: "14px",
162
+ children: [/*#__PURE__*/_jsx(CircularProgress, {
163
+ sx: {
164
+ marginRight: '4px'
165
+ },
166
+ size: "12px"
167
+ }), t('common.progress')]
168
+ });
169
+ }
170
+ const node = !status ? /*#__PURE__*/_jsx(Tag, {
171
+ type: "success",
172
+ children: t('common.succeeded')
173
+ }) : /*#__PURE__*/_jsxs(Box, {
174
+ display: "inline-flex",
175
+ alignItems: "center",
176
+ children: [/*#__PURE__*/_jsx(Tag, {
177
+ type: "error",
178
+ children: t('common.failed')
179
+ }), " \xA0", /*#__PURE__*/_jsx(Tooltip, {
180
+ style: {
181
+ display: 'flex',
182
+ alignItems: 'center',
183
+ flexShrink: 0
184
+ },
185
+ title: message,
186
+ children: /*#__PURE__*/_jsx(Icon, {
187
+ children: /*#__PURE__*/_jsx(HelpOutlineIcon, {
188
+ style: {
189
+ width: '24px',
190
+ height: '24px'
191
+ },
192
+ color: "error"
193
+ })
194
+ })
195
+ })]
196
+ });
197
+ return node;
198
+ }
199
+ }
200
+ }];
201
+ return /*#__PURE__*/_jsx(Box, {
202
+ ...rest,
203
+ children: backups?.length ? /*#__PURE__*/_jsx(Datatable, {
204
+ title: /*#__PURE__*/_jsx(Typography, {
205
+ fontSize: "1.2rem",
206
+ fontWeight: "bold",
207
+ children: t('storage.spaces.backup.records')
208
+ }),
209
+ data: backups,
210
+ columns: columns,
211
+ emptyNode: t('storage.spaces.record.emptyData', locale),
212
+ options: {
213
+ download: false,
214
+ filter: false,
215
+ print: false
216
+ }
217
+ }) : /*#__PURE__*/_jsxs(_Fragment, {
218
+ children: [/*#__PURE__*/_jsx(Box, {
219
+ display: "flex",
220
+ height: "56px",
221
+ lineHeight: "56px",
222
+ alignItems: "center",
223
+ children: /*#__PURE__*/_jsx(Typography, {
224
+ fontSize: "1.2rem",
225
+ fontWeight: "bold",
226
+ children: t('storage.spaces.backup.records')
227
+ })
228
+ }), /*#__PURE__*/_jsx(Box, {
229
+ color: "#9397A1",
230
+ marginTop: "16px",
231
+ marginBottom: "24px",
232
+ children: t('storage.spaces.record.emptyData')
233
+ })]
234
+ })
235
+ });
236
+ }
237
+ SpacesBackupRecords.propTypes = {
238
+ progress: object.isRequired,
239
+ spaceGateways: array.isRequired
240
+ };
241
+ export default SpacesBackupRecords;
@@ -0,0 +1,372 @@
1
+ import { Box, CircularProgress, DialogContentText, TextField, Typography } from '@mui/material';
2
+ import React, { useMemo, useState } from 'react';
3
+ import Button from '@arcblock/ux/lib/Button';
4
+ import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
5
+ import DidConnect from '@arcblock/did-connect/lib/Connect';
6
+ import joinUrl from 'url-join';
7
+ import toast from '@arcblock/ux/lib/Toast';
8
+ import { BLOCKLET_CONFIGURABLE_KEY } from '@blocklet/constant';
9
+ import SplitButton from '@arcblock/ux/lib/SplitButton';
10
+ import Dialog from '@arcblock/ux/lib/Dialog';
11
+ import Alert from '@arcblock/ux/lib/Alert';
12
+ import { array, func } from 'prop-types';
13
+ import { useBlockletContext } from '../../contexts/blocklet';
14
+ import { axios } from '../../util/api';
15
+ import { formatError, getPathPrefix, getWebWalletUrl } from '../../util';
16
+ import { useNodeContext } from '../../contexts/node';
17
+ import useBlockletInfoForConnectDIDSpaces from '../../hooks/use-blocklet-info-for-connect-did-spaces';
18
+ import { getDIDSpaceDidFromEndpoint, getSpaceBackupEndpoint, isValidSpaceGatewayUrl } from '../../util/spaces';
19
+ /**
20
+ * @description
21
+ * @param {{
22
+ * spaceGateways?: Array<import('./connected').SpaceGateway>,
23
+ * refreshSpaceGateways: () => void,
24
+ * }} { spaceGateways, refreshSpaceGateways, ...rest }
25
+ * @return {*}
26
+ */
27
+ import { jsx as _jsx } from "react/jsx-runtime";
28
+ import { jsxs as _jsxs } from "react/jsx-runtime";
29
+ import { Fragment as _Fragment } from "react/jsx-runtime";
30
+ function ConnectTo({
31
+ spaceGateways,
32
+ refreshSpaceGateways,
33
+ ...rest
34
+ }) {
35
+ const {
36
+ blocklet
37
+ } = useBlockletContext();
38
+ const {
39
+ info,
40
+ api: nodeApi
41
+ } = useNodeContext();
42
+ const {
43
+ t,
44
+ locale
45
+ } = useLocaleContext();
46
+ const spaceBackupEndpoint = useMemo(() => getSpaceBackupEndpoint(blocklet?.environments), [blocklet]);
47
+ const [url, setUrl] = useState('');
48
+ const [loading, setLoading] = useState(false);
49
+ const [open, setOpen] = useState(false);
50
+ const [errorMessage, setErrorMessage] = useState('');
51
+ const blockletInfo = useBlockletInfoForConnectDIDSpaces({
52
+ blocklet
53
+ });
54
+ const webWalletUrl = getWebWalletUrl(info);
55
+ const [authorizeFromNftConnect, setAuthorizeFromNftConnect] = useState({
56
+ open: false,
57
+ action: 'get-did-spaces-endpoint',
58
+ checkTimeout: 1000 * 300,
59
+ checkFn: axios.create({
60
+ baseURL: joinUrl(window.location.origin, getPathPrefix())
61
+ }).get,
62
+ messages: {
63
+ title: t('storage.spaces.provideNFT.title', {
64
+ appName: blockletInfo.appName
65
+ }, locale),
66
+ scan: t('storage.spaces.provideNFT.scan', {
67
+ appName: blockletInfo.appName
68
+ }, locale),
69
+ confirm: '',
70
+ success: /*#__PURE__*/_jsx(Typography, {
71
+ gutterBottom: true,
72
+ children: t('storage.spaces.provideNFT.success')
73
+ })
74
+ },
75
+ onClose: () => {
76
+ // eslint-disable-next-line no-shadow
77
+ setAuthorizeFromNftConnect(preValue => ({
78
+ ...preValue,
79
+ open: false
80
+ }));
81
+ }
82
+ });
83
+ const [authorizeConnect, setAuthorizeConnect] = useState({
84
+ open: false,
85
+ action: 'one-click-authorization',
86
+ checkTimeout: 1000 * 300,
87
+ messages: {
88
+ title: t('storage.spaces.authorize.title', {
89
+ appName: blockletInfo.appName
90
+ }, locale),
91
+ scan: t('storage.spaces.authorize.scan', {
92
+ appName: blockletInfo.appName
93
+ }, locale),
94
+ confirm: '',
95
+ success: /*#__PURE__*/_jsx(Typography, {
96
+ gutterBottom: true,
97
+ children: t('storage.spaces.authorize.success')
98
+ })
99
+ },
100
+ onClose: () => {
101
+ // eslint-disable-next-line no-shadow
102
+ setAuthorizeConnect(preValue => ({
103
+ ...preValue,
104
+ open: false
105
+ }));
106
+ }
107
+ });
108
+ const onAuthorizeConnectSuccess = (response, decrypt) => {
109
+ setTimeout(async () => {
110
+ setAuthorizeConnect(preValue => ({
111
+ ...preValue,
112
+ open: false
113
+ }));
114
+ setAuthorizeFromNftConnect(preValue => ({
115
+ ...preValue,
116
+ open: false
117
+ }));
118
+ const endpoint = decrypt(response.endpoint);
119
+ const space = response.space ? decrypt(response.space) : {};
120
+ await addSpaceGateway({
121
+ endpoint,
122
+ // name 默认为 DID Space,兼容旧版本的 DID Spaces
123
+ ...{
124
+ did: getDIDSpaceDidFromEndpoint(endpoint),
125
+ name: 'DID Space'
126
+ },
127
+ ...space
128
+ });
129
+ }, 0);
130
+ };
131
+
132
+ /**
133
+ *
134
+ * @param {{
135
+ * endpoint: string,
136
+ * name: string,
137
+ * did: string,
138
+ * }} {endpoint, name, did}
139
+ * @returns {Promise<void>}
140
+ */
141
+ const addSpaceGateway = async ({
142
+ endpoint,
143
+ name,
144
+ did
145
+ }) => {
146
+ let normalizeUrl = endpoint?.replace(/\/api\/.+/, '')?.trim()?.replace(/\/$/, '');
147
+ if (!normalizeUrl.startsWith('http')) {
148
+ // eslint-disable-next-line no-param-reassign
149
+ normalizeUrl = `https://${normalizeUrl}`;
150
+ }
151
+ if (!(await isValidSpaceGatewayUrl(normalizeUrl))) {
152
+ toast.error(t('storage.spaces.gateway.add.invalidUrl'));
153
+ return;
154
+ }
155
+ const duplicate = spaceGateways.some(s => s.endpoint === endpoint);
156
+ if (duplicate) {
157
+ toast.error(t('storage.spaces.gateway.add.duplicate', {
158
+ name
159
+ }));
160
+ return;
161
+ }
162
+ const spaceGateway = {
163
+ name,
164
+ did,
165
+ url: normalizeUrl,
166
+ endpoint
167
+ };
168
+ await nodeApi.addBlockletSpaceGateway({
169
+ input: {
170
+ did: blocklet.meta.did,
171
+ spaceGateway
172
+ }
173
+ });
174
+ if (spaceBackupEndpoint !== endpoint) {
175
+ await nodeApi.configBlocklet({
176
+ input: {
177
+ did: [blocklet.meta.did],
178
+ configs: [{
179
+ key: BLOCKLET_CONFIGURABLE_KEY.BLOCKLET_APP_BACKUP_ENDPOINT,
180
+ value: endpoint
181
+ }]
182
+ }
183
+ });
184
+ }
185
+ toast.success(t('storage.spaces.connectedWithName', {
186
+ name: spaceGateway?.name ?? 'DID Spaces'
187
+ }));
188
+ refreshSpaceGateways();
189
+ };
190
+ const handleUseWalletConnect = () => {
191
+ setAuthorizeFromNftConnect(preValue => ({
192
+ ...preValue,
193
+ open: true,
194
+ extraParams: {
195
+ appDid: blockletInfo.appDid,
196
+ appName: blockletInfo.appName,
197
+ appDescription: blockletInfo.appDescription,
198
+ scopes: blockletInfo.scopes,
199
+ appUrl: blockletInfo.appUrl,
200
+ referrer: blockletInfo.referrer,
201
+ nodeDid: info.did
202
+ }
203
+ }));
204
+ };
205
+ const handleUseSpaceGatewayConnect = async () => {
206
+ try {
207
+ setLoading(true);
208
+ const fullUrl = url.startsWith('http') ? url : `https://${url}`;
209
+ if (!(await isValidSpaceGatewayUrl(fullUrl))) {
210
+ throw new Error(t('storage.spaces.gateway.add.invalidUrl'));
211
+ }
212
+ setAuthorizeConnect(preValue => ({
213
+ ...preValue,
214
+ open: true,
215
+ prefix: joinUrl(fullUrl, 'space/api/did'),
216
+ baseUrl: new URL(fullUrl).origin,
217
+ checkFn: axios.create({
218
+ baseURL: joinUrl(fullUrl, 'space')
219
+ }).get,
220
+ extraParams: {
221
+ appDid: blockletInfo.appDid,
222
+ appName: blockletInfo.appName,
223
+ appDescription: blockletInfo.appDescription,
224
+ scopes: blockletInfo.scopes,
225
+ appUrl: blockletInfo.appUrl,
226
+ referrer: blockletInfo.referrer,
227
+ nodeDid: info.did
228
+ }
229
+ }));
230
+ setOpen(false);
231
+ } catch (err) {
232
+ const _errorMessage = `${t('storage.spaces.gateway.add.failed', locale)}: ${formatError(err)}`;
233
+ setErrorMessage(_errorMessage);
234
+ } finally {
235
+ setLoading(false);
236
+ }
237
+ };
238
+ return /*#__PURE__*/_jsxs(Box, {
239
+ children: [/*#__PURE__*/_jsx(SplitButton, {
240
+ color: "primary",
241
+ style: {
242
+ textTransform: 'none !important',
243
+ fontSize: '1rem'
244
+ },
245
+ size: "small",
246
+ onClick: handleUseWalletConnect,
247
+ menu: [/*#__PURE__*/_jsx(SplitButton.Item, {
248
+ sx: {
249
+ textTransform: 'none'
250
+ },
251
+ onClick: () => setOpen(true),
252
+ size: "small",
253
+ ...rest,
254
+ children: t('storage.spaces.connect.useSpaceGateway')
255
+ }, "1")],
256
+ children: /*#__PURE__*/_jsx(Typography, {
257
+ sx: {
258
+ fontWeight: 'bold',
259
+ textTransform: 'none'
260
+ },
261
+ children: t('storage.spaces.connect.useWallet')
262
+ })
263
+ }), /*#__PURE__*/_jsx(DidConnect, {
264
+ forceConnected: false,
265
+ saveConnect: false,
266
+ prefix: authorizeFromNftConnect.prefix,
267
+ open: authorizeFromNftConnect.open,
268
+ popup: true,
269
+ action: authorizeFromNftConnect.action,
270
+ webWalletUrl: webWalletUrl,
271
+ baseUrl: authorizeFromNftConnect.baseUrl,
272
+ checkFn: authorizeFromNftConnect.checkFn,
273
+ onSuccess: onAuthorizeConnectSuccess,
274
+ onClose: authorizeFromNftConnect.onClose,
275
+ checkTimeout: authorizeFromNftConnect.checkTimeout,
276
+ extraParams: authorizeFromNftConnect.extraParams,
277
+ messages: authorizeFromNftConnect.messages,
278
+ locale: locale
279
+ }), /*#__PURE__*/_jsx(DidConnect, {
280
+ forceConnected: false,
281
+ saveConnect: false,
282
+ prefix: authorizeConnect.prefix,
283
+ open: authorizeConnect.open,
284
+ popup: true,
285
+ action: authorizeConnect.action,
286
+ baseUrl: authorizeConnect.baseUrl,
287
+ checkFn: authorizeConnect.checkFn,
288
+ onSuccess: onAuthorizeConnectSuccess,
289
+ onClose: authorizeConnect.onClose,
290
+ checkTimeout: authorizeConnect.checkTimeout,
291
+ extraParams: authorizeConnect.extraParams,
292
+ messages: authorizeConnect.messages,
293
+ locale: locale
294
+ }), /*#__PURE__*/_jsxs(Dialog, {
295
+ title: t('storage.spaces.gateway.add.title'),
296
+ fullWidth: true,
297
+ maxWidth: "md",
298
+ open: open,
299
+ onClose: () => setOpen(false),
300
+ PaperProps: {
301
+ style: {
302
+ minHeight: 'auto'
303
+ }
304
+ },
305
+ actions: /*#__PURE__*/_jsxs(_Fragment, {
306
+ children: [/*#__PURE__*/_jsx(Button, {
307
+ onClick: e => {
308
+ e.stopPropagation();
309
+ setOpen(false);
310
+ },
311
+ color: "inherit",
312
+ children: t('common.cancel')
313
+ }), /*#__PURE__*/_jsxs(Button, {
314
+ onClick: handleUseSpaceGatewayConnect,
315
+ color: "primary",
316
+ disabled: loading || !url,
317
+ variant: "contained",
318
+ autoFocus: true,
319
+ children: [loading && /*#__PURE__*/_jsx(CircularProgress, {
320
+ size: 16
321
+ }), t('common.confirm')]
322
+ })]
323
+ }),
324
+ children: [/*#__PURE__*/_jsx("div", {
325
+ style: {
326
+ paddingTop: 12,
327
+ overflowY: 'hidden'
328
+ },
329
+ children: /*#__PURE__*/_jsx(DialogContentText, {
330
+ component: "div",
331
+ children: /*#__PURE__*/_jsx(Typography, {
332
+ component: "div",
333
+ children: /*#__PURE__*/_jsx(TextField, {
334
+ label: t('storage.spaces.gateway.add.label'),
335
+ autoComplete: "off",
336
+ variant: "outlined",
337
+ name: "url",
338
+ fullWidth: true,
339
+ value: url,
340
+ onChange: e => {
341
+ setErrorMessage(null);
342
+ setUrl(e.target.value);
343
+ },
344
+ disabled: loading,
345
+ onKeyPress: async e => {
346
+ if (e.key === 'Enter') {
347
+ await handleUseSpaceGatewayConnect();
348
+ }
349
+ },
350
+ autoFocus: true
351
+ })
352
+ })
353
+ })
354
+ }), Boolean(errorMessage) && /*#__PURE__*/_jsx(Alert, {
355
+ type: "error",
356
+ style: {
357
+ width: '100%'
358
+ },
359
+ children: errorMessage
360
+ })]
361
+ })]
362
+ });
363
+ }
364
+ ConnectTo.propTypes = {
365
+ spaceGateways: array,
366
+ refreshSpaceGateways: func
367
+ };
368
+ ConnectTo.defaultProps = {
369
+ spaceGateways: [],
370
+ refreshSpaceGateways: () => undefined
371
+ };
372
+ export default ConnectTo;