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