@abtnode/ux 1.16.15-beta-ed0db59e → 1.16.15-beta-d464647a
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/storage/action.js +26 -13
- package/es/blocklet/storage/backups.js +7 -14
- package/es/blocklet/storage/connect-to.js +28 -52
- package/es/blocklet/storage/connected.js +19 -110
- package/es/blocklet/storage/delete.js +2 -1
- package/es/blocklet/storage/index.js +5 -8
- package/es/blocklet/storage/item.js +52 -60
- package/es/contexts/blocklet-storage.js +199 -0
- package/es/hooks/use-backups.js +36 -17
- package/es/hooks/use-space-gateways.js +66 -0
- package/es/locales/en.js +1 -1
- package/es/locales/zh.js +1 -1
- package/lib/blocklet/storage/action.js +25 -12
- package/lib/blocklet/storage/backups.js +13 -25
- package/lib/blocklet/storage/connect-to.js +33 -62
- package/lib/blocklet/storage/connected.js +18 -113
- package/lib/blocklet/storage/delete.js +2 -1
- package/lib/blocklet/storage/index.js +5 -10
- package/lib/blocklet/storage/item.js +50 -58
- package/lib/contexts/blocklet-storage.js +209 -0
- package/lib/hooks/use-backups.js +36 -17
- package/lib/hooks/use-space-gateways.js +74 -0
- package/lib/locales/en.js +1 -1
- package/lib/locales/zh.js +1 -1
- package/package.json +16 -16
|
@@ -27,9 +27,10 @@ var _blocklet = require("../../contexts/blocklet");
|
|
|
27
27
|
var _useBlockletInfoForConnectDidSpaces = _interopRequireDefault(require("../../hooks/use-blocklet-info-for-connect-did-spaces"));
|
|
28
28
|
var _spaces = require("../../util/spaces");
|
|
29
29
|
var _previewNft = _interopRequireDefault(require("./preview-nft"));
|
|
30
|
+
var _blockletStorage = require("../../contexts/blocklet-storage");
|
|
30
31
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
31
32
|
var _templateObject;
|
|
32
|
-
const _excluded = ["spaceGateway", "connected", "
|
|
33
|
+
const _excluded = ["spaceGateway", "connected", "onDelete", "onBackupNow"];
|
|
33
34
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
34
35
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
35
36
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
@@ -83,24 +84,21 @@ SpaceDisconnected.defaultProps = {
|
|
|
83
84
|
* progress: any,
|
|
84
85
|
* onDelete: (spaceGateway: import('./connected').SpaceGateway) => Promise<void>,
|
|
85
86
|
* onBackupNow: () => Promise<void>,
|
|
86
|
-
* refreshSpaceGateways: () => void
|
|
87
87
|
* }} { spaceGateway }
|
|
88
88
|
*/
|
|
89
89
|
function SpaceItem(_ref) {
|
|
90
90
|
let {
|
|
91
91
|
spaceGateway,
|
|
92
92
|
connected,
|
|
93
|
-
progress,
|
|
94
93
|
onDelete,
|
|
95
|
-
onBackupNow
|
|
96
|
-
refreshSpaceGateways
|
|
94
|
+
onBackupNow
|
|
97
95
|
} = _ref,
|
|
98
96
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
97
|
+
const isMobile = (0, _material.useMediaQuery)(theme => theme.breakpoints.down('md'));
|
|
99
98
|
const {
|
|
100
99
|
t,
|
|
101
100
|
locale
|
|
102
101
|
} = (0, _context.useLocaleContext)();
|
|
103
|
-
const [loading, setLoading] = (0, _react.useState)(false);
|
|
104
102
|
/** @type {{ blocklet: import('@abtnode/client').BlockletState }} */
|
|
105
103
|
const {
|
|
106
104
|
blocklet
|
|
@@ -121,7 +119,17 @@ function SpaceItem(_ref) {
|
|
|
121
119
|
} = (0, _useBlockletInfoForConnectDidSpaces.default)({
|
|
122
120
|
blocklet
|
|
123
121
|
});
|
|
124
|
-
const
|
|
122
|
+
const {
|
|
123
|
+
updateSpaceGateway,
|
|
124
|
+
backupEndpoint,
|
|
125
|
+
backupProgress
|
|
126
|
+
} = (0, _blockletStorage.useBlockletStorageContext)();
|
|
127
|
+
|
|
128
|
+
// TEST:
|
|
129
|
+
const [loading, setLoading] = (0, _react.useState)(false);
|
|
130
|
+
// backupProgress.message = '(12/99)备份到备份到备份到备份到备';
|
|
131
|
+
// backupProgress.progress = 99;
|
|
132
|
+
|
|
125
133
|
const [authorizeConnect, setAuthorizeConnect] = (0, _react.useState)({
|
|
126
134
|
open: false,
|
|
127
135
|
action: 'one-click-authorization',
|
|
@@ -155,12 +163,12 @@ function SpaceItem(_ref) {
|
|
|
155
163
|
if (!connected) {
|
|
156
164
|
return true;
|
|
157
165
|
}
|
|
158
|
-
return (0, _spaces.hasPermissionByEndpoint)(
|
|
166
|
+
return (0, _spaces.hasPermissionByEndpoint)(backupEndpoint);
|
|
159
167
|
}, {
|
|
160
|
-
refreshDeps: [connected,
|
|
168
|
+
refreshDeps: [connected, backupEndpoint, authorizeConnect === null || authorizeConnect === void 0 ? void 0 : authorizeConnect.open, loading]
|
|
161
169
|
});
|
|
162
170
|
const shouldDisplayConnected = connected && hasPermission;
|
|
163
|
-
const
|
|
171
|
+
const shouldDisplayBackupButton = connected && !loading && hasPermission && !(spaceGateway !== null && spaceGateway !== void 0 && spaceGateway.loading);
|
|
164
172
|
const shouldDisplayBackupProgress = connected && loading && hasPermission;
|
|
165
173
|
const shouldDisplayReconnectNow = connected && !hasPermission && !hasPermissionLoading && !loading;
|
|
166
174
|
|
|
@@ -212,7 +220,7 @@ function SpaceItem(_ref) {
|
|
|
212
220
|
* @param {Function} decrypt
|
|
213
221
|
*/
|
|
214
222
|
const onAuthorizeConnectSuccess = async (response, decrypt) => {
|
|
215
|
-
var _space$name, _space$did
|
|
223
|
+
var _space$name, _space$did;
|
|
216
224
|
const endpoint = decrypt(response.endpoint);
|
|
217
225
|
const spaceDid = (0, _spaces.getDIDSpaceDidFromEndpoint)(endpoint);
|
|
218
226
|
const space = response.space ? decrypt(response.space) : {};
|
|
@@ -225,37 +233,15 @@ function SpaceItem(_ref) {
|
|
|
225
233
|
}));
|
|
226
234
|
return;
|
|
227
235
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
url: spaceGateway === null || spaceGateway === void 0 ? void 0 : spaceGateway.url
|
|
233
|
-
},
|
|
234
|
-
spaceGateway: _objectSpread(_objectSpread({}, spaceGateway), {}, {
|
|
235
|
-
name: (_space$name = space.name) !== null && _space$name !== void 0 ? _space$name : 'DID Space',
|
|
236
|
-
did: (_space$did = space.did) !== null && _space$did !== void 0 ? _space$did : (0, _spaces.getDIDSpaceDidFromEndpoint)(endpoint),
|
|
237
|
-
endpoint
|
|
238
|
-
})
|
|
239
|
-
}
|
|
236
|
+
const newSpaceGateway = _objectSpread(_objectSpread({}, spaceGateway), {}, {
|
|
237
|
+
name: (_space$name = space.name) !== null && _space$name !== void 0 ? _space$name : 'DID Space',
|
|
238
|
+
did: (_space$did = space.did) !== null && _space$did !== void 0 ? _space$did : (0, _spaces.getDIDSpaceDidFromEndpoint)(endpoint),
|
|
239
|
+
endpoint
|
|
240
240
|
});
|
|
241
|
-
|
|
242
|
-
await nodeApi.configBlocklet({
|
|
243
|
-
input: {
|
|
244
|
-
did: [blocklet.meta.did],
|
|
245
|
-
configs: [{
|
|
246
|
-
key: _constant.BLOCKLET_CONFIGURABLE_KEY.BLOCKLET_APP_BACKUP_ENDPOINT,
|
|
247
|
-
value: endpoint
|
|
248
|
-
}]
|
|
249
|
-
}
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
_Toast.default.success(t('storage.spaces.connectedWithName', {
|
|
253
|
-
name: (_spaceGateway$name = spaceGateway === null || spaceGateway === void 0 ? void 0 : spaceGateway.name) !== null && _spaceGateway$name !== void 0 ? _spaceGateway$name : 'DID Spaces'
|
|
254
|
-
}));
|
|
241
|
+
await updateSpaceGateway(newSpaceGateway);
|
|
255
242
|
setAuthorizeConnect(preValue => _objectSpread(_objectSpread({}, preValue), {}, {
|
|
256
243
|
open: false
|
|
257
244
|
}));
|
|
258
|
-
refreshSpaceGateways();
|
|
259
245
|
};
|
|
260
246
|
const _onBackupNow = async () => {
|
|
261
247
|
try {
|
|
@@ -272,20 +258,20 @@ function SpaceItem(_ref) {
|
|
|
272
258
|
}
|
|
273
259
|
};
|
|
274
260
|
(0, _react.useEffect)(() => {
|
|
275
|
-
if (
|
|
276
|
-
if ((
|
|
261
|
+
if (backupProgress !== null && backupProgress !== void 0 && backupProgress.completed) {
|
|
262
|
+
if ((backupProgress === null || backupProgress === void 0 ? void 0 : backupProgress.progress) === 100) {
|
|
277
263
|
_Toast.default.success(t('storage.spaces.backupSuccessfully'));
|
|
278
|
-
} else if ((
|
|
279
|
-
_Toast.default.error(
|
|
264
|
+
} else if ((backupProgress === null || backupProgress === void 0 ? void 0 : backupProgress.progress) === -1) {
|
|
265
|
+
_Toast.default.error(backupProgress === null || backupProgress === void 0 ? void 0 : backupProgress.message);
|
|
280
266
|
}
|
|
281
267
|
setLoading(false);
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
} else if (
|
|
268
|
+
backupProgress.progress = 0;
|
|
269
|
+
backupProgress.message = '';
|
|
270
|
+
} else if (backupProgress.progress) {
|
|
285
271
|
setLoading(true);
|
|
286
272
|
}
|
|
287
273
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
288
|
-
}, [
|
|
274
|
+
}, [backupProgress]);
|
|
289
275
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(BoxContainer, {
|
|
290
276
|
style: {
|
|
291
277
|
position: 'relative'
|
|
@@ -310,7 +296,8 @@ function SpaceItem(_ref) {
|
|
|
310
296
|
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Box, {
|
|
311
297
|
className: "spaces-info",
|
|
312
298
|
display: "flex",
|
|
313
|
-
flexGrow: 1,
|
|
299
|
+
flexGrow: (!isMobile || !shouldDisplayBackupProgress) && 1,
|
|
300
|
+
minWidth: "180px",
|
|
314
301
|
flexDirection: shouldDisplayBackupProgress ? 'row' : 'column',
|
|
315
302
|
sx: {
|
|
316
303
|
marginLeft: '20px',
|
|
@@ -380,7 +367,8 @@ function SpaceItem(_ref) {
|
|
|
380
367
|
className: "spaces-backup",
|
|
381
368
|
display: "flex",
|
|
382
369
|
alignItems: "center",
|
|
383
|
-
|
|
370
|
+
flex: isMobile && shouldDisplayBackupProgress && 1,
|
|
371
|
+
children: [shouldDisplayBackupButton && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Box, {
|
|
384
372
|
className: "backup-strategy",
|
|
385
373
|
display: "flex",
|
|
386
374
|
alignItems: "center",
|
|
@@ -414,12 +402,14 @@ function SpaceItem(_ref) {
|
|
|
414
402
|
display: "flex",
|
|
415
403
|
flexDirection: "column",
|
|
416
404
|
alignItems: "center",
|
|
417
|
-
minWidth:
|
|
405
|
+
minWidth: !isMobile && '640px',
|
|
406
|
+
marginLeft: isMobile && '16px',
|
|
407
|
+
width: isMobile && '360px',
|
|
418
408
|
marginRight: "auto",
|
|
419
|
-
alignSelf: "end",
|
|
409
|
+
alignSelf: "flex-end",
|
|
420
410
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
421
411
|
color: "primary",
|
|
422
|
-
children:
|
|
412
|
+
children: backupProgress === null || backupProgress === void 0 ? void 0 : backupProgress.message
|
|
423
413
|
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Box, {
|
|
424
414
|
sx: {
|
|
425
415
|
display: 'flex',
|
|
@@ -434,16 +424,16 @@ function SpaceItem(_ref) {
|
|
|
434
424
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.LinearProgress, {
|
|
435
425
|
color: "primary",
|
|
436
426
|
variant: "determinate",
|
|
437
|
-
value:
|
|
427
|
+
value: backupProgress === null || backupProgress === void 0 ? void 0 : backupProgress.progress
|
|
438
428
|
})
|
|
439
429
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, {
|
|
440
430
|
sx: {
|
|
441
|
-
|
|
431
|
+
maxWidth: '100%'
|
|
442
432
|
},
|
|
443
433
|
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Typography, {
|
|
444
434
|
variant: "body2",
|
|
445
435
|
color: "text.secondary",
|
|
446
|
-
children: [
|
|
436
|
+
children: [backupProgress === null || backupProgress === void 0 ? void 0 : backupProgress.progress, "%"]
|
|
447
437
|
})
|
|
448
438
|
})]
|
|
449
439
|
})]
|
|
@@ -462,13 +452,15 @@ function SpaceItem(_ref) {
|
|
|
462
452
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_action.default, {
|
|
463
453
|
sx: {
|
|
464
454
|
marginLeft: '16px',
|
|
465
|
-
marginRight: '16px'
|
|
455
|
+
marginRight: '16px',
|
|
456
|
+
alignItems: 'flex-end',
|
|
457
|
+
justifyItems: 'flex-end'
|
|
466
458
|
},
|
|
467
459
|
spaceGateway: spaceGateway,
|
|
468
460
|
connected: connected,
|
|
469
461
|
onDelete: onDelete,
|
|
470
462
|
onConnect: onConnect,
|
|
471
|
-
enableSwitchToSpace: (
|
|
463
|
+
enableSwitchToSpace: (backupProgress === null || backupProgress === void 0 ? void 0 : backupProgress.completed) || (0, _lodash.isEmpty)(backupProgress === null || backupProgress === void 0 ? void 0 : backupProgress.message)
|
|
472
464
|
})]
|
|
473
465
|
})]
|
|
474
466
|
})), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Connect.default, {
|
|
@@ -500,11 +492,11 @@ SpaceItem.propTypes = {
|
|
|
500
492
|
name: _propTypes.default.string.isRequired,
|
|
501
493
|
url: _propTypes.default.string.isRequired,
|
|
502
494
|
endpoint: _propTypes.default.string.isRequired,
|
|
503
|
-
protected: _propTypes.default.bool
|
|
495
|
+
protected: _propTypes.default.bool,
|
|
496
|
+
loading: _propTypes.default.bool
|
|
504
497
|
}).isRequired,
|
|
505
498
|
connected: _propTypes.default.bool.isRequired,
|
|
506
499
|
progress: _propTypes.default.any.isRequired,
|
|
507
|
-
refreshSpaceGateways: _propTypes.default.func.isRequired,
|
|
508
500
|
onDelete: _propTypes.default.func,
|
|
509
501
|
onBackupNow: _propTypes.default.func
|
|
510
502
|
};
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.BlockletStorageContext = exports.BlockletStorageConsumer = void 0;
|
|
7
|
+
exports.BlockletStorageProvider = BlockletStorageProvider;
|
|
8
|
+
exports.useBlockletStorageContext = useBlockletStorageContext;
|
|
9
|
+
var _react = require("react");
|
|
10
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
+
var _Toast = _interopRequireDefault(require("@arcblock/ux/lib/Toast"));
|
|
12
|
+
var _context = require("@arcblock/ux/lib/Locale/context");
|
|
13
|
+
var _constant = require("@blocklet/constant");
|
|
14
|
+
var _blocklet = require("./blocklet");
|
|
15
|
+
var _spaces = require("../util/spaces");
|
|
16
|
+
var _useSpaceGateways = _interopRequireDefault(require("../hooks/use-space-gateways"));
|
|
17
|
+
var _node = require("./node");
|
|
18
|
+
var _useBackupProgress = _interopRequireDefault(require("../hooks/use-backup-progress"));
|
|
19
|
+
var _useBackups = _interopRequireDefault(require("../hooks/use-backups"));
|
|
20
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
21
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
22
|
+
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; }
|
|
23
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
24
|
+
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; }
|
|
25
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
26
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } /**
|
|
27
|
+
* @typedef {import('../blocklet/storage/connected').SpaceGateway} SpaceGateway
|
|
28
|
+
* @typedef {import('@abtnode/client').Backup} Backup
|
|
29
|
+
*/ /**
|
|
30
|
+
* @typedef {{
|
|
31
|
+
* spaceGateways: SpaceGateway[],
|
|
32
|
+
* selectedGateway: SpaceGateway,
|
|
33
|
+
* addSpaceGateway: (spaceGateway: SpaceGateway) => Promise<void>,
|
|
34
|
+
* deleteSpaceGateway: (spaceGateway: SpaceGateway) => Promise<void>,
|
|
35
|
+
* updateSpaceGateway: (spaceGateway: SpaceGateway) => Promise<void>,
|
|
36
|
+
* refreshSpaceGateways: () => void,
|
|
37
|
+
* spaceGatewaysLoading: boolean,
|
|
38
|
+
* spaceGatewayIsSelected: (spaceGateway: SpaceGateway) => boolean,
|
|
39
|
+
*
|
|
40
|
+
* backupEndpoint: string,
|
|
41
|
+
* backupProgress: any,
|
|
42
|
+
* backups: Backup[],
|
|
43
|
+
* backupsLoading: boolean,
|
|
44
|
+
* }} BlockletStorageContextType
|
|
45
|
+
*/ /** @type {import('react').Context<BlockletStorageContextType>} */
|
|
46
|
+
const BlockletStorageContext = /*#__PURE__*/(0, _react.createContext)({});
|
|
47
|
+
exports.BlockletStorageContext = BlockletStorageContext;
|
|
48
|
+
const {
|
|
49
|
+
Provider,
|
|
50
|
+
Consumer
|
|
51
|
+
} = BlockletStorageContext;
|
|
52
|
+
exports.BlockletStorageConsumer = Consumer;
|
|
53
|
+
function BlockletStorageProvider(_ref) {
|
|
54
|
+
let {
|
|
55
|
+
children
|
|
56
|
+
} = _ref;
|
|
57
|
+
const {
|
|
58
|
+
t
|
|
59
|
+
} = (0, _context.useLocaleContext)();
|
|
60
|
+
/** @type {{ api: import('@abtnode/client') }} */
|
|
61
|
+
const {
|
|
62
|
+
api
|
|
63
|
+
} = (0, _node.useNodeContext)();
|
|
64
|
+
/** @type {{ blocklet: import('@abtnode/client').BlockletState }} */
|
|
65
|
+
const {
|
|
66
|
+
blocklet
|
|
67
|
+
} = (0, _blocklet.useBlockletContext)();
|
|
68
|
+
const [spaceGatewaysLoading, setSpaceGatewaysLoading] = (0, _react.useState)(false);
|
|
69
|
+
const [spaceGatewaysRefresh, setSpaceGatewaysRefresh] = (0, _react.useState)(false);
|
|
70
|
+
const {
|
|
71
|
+
spaceGateways
|
|
72
|
+
} = (0, _useSpaceGateways.default)({
|
|
73
|
+
refresh: spaceGatewaysRefresh,
|
|
74
|
+
setLoading: setSpaceGatewaysLoading
|
|
75
|
+
});
|
|
76
|
+
const backupProgress = (0, _useBackupProgress.default)({
|
|
77
|
+
appDid: blocklet === null || blocklet === void 0 ? void 0 : blocklet.appDid
|
|
78
|
+
});
|
|
79
|
+
const backupEndpoint = (0, _react.useMemo)(() => (0, _spaces.getSpaceBackupEndpoint)(blocklet === null || blocklet === void 0 ? void 0 : blocklet.environments),
|
|
80
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
81
|
+
[blocklet, spaceGatewaysRefresh]);
|
|
82
|
+
const [backupsLoading, setBackupsLoading] = (0, _react.useState)(false);
|
|
83
|
+
const {
|
|
84
|
+
backups
|
|
85
|
+
} = (0, _useBackups.default)({
|
|
86
|
+
deps: [backupProgress],
|
|
87
|
+
setLoading: setBackupsLoading
|
|
88
|
+
});
|
|
89
|
+
const [selectedSpaceGateway, setSelectedSpaceGateway] = (0, _react.useState)(spaceGateways === null || spaceGateways === void 0 ? void 0 : spaceGateways.find(x => x.endpoint === backupEndpoint));
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* @description
|
|
93
|
+
* @param {SpaceGateway} spaceGateway
|
|
94
|
+
* @param {string} endpoint
|
|
95
|
+
*
|
|
96
|
+
*/
|
|
97
|
+
const addSpaceGateway = async (spaceGateway, endpoint) => {
|
|
98
|
+
spaceGateways.push(_objectSpread(_objectSpread({}, spaceGateway), {}, {
|
|
99
|
+
loading: true
|
|
100
|
+
}));
|
|
101
|
+
await api.addBlockletSpaceGateway({
|
|
102
|
+
input: {
|
|
103
|
+
did: blocklet.meta.did,
|
|
104
|
+
spaceGateway
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
if (backupEndpoint !== endpoint) {
|
|
108
|
+
await api.configBlocklet({
|
|
109
|
+
input: {
|
|
110
|
+
did: [blocklet.meta.did],
|
|
111
|
+
configs: [{
|
|
112
|
+
key: _constant.BLOCKLET_CONFIGURABLE_KEY.BLOCKLET_APP_BACKUP_ENDPOINT,
|
|
113
|
+
value: endpoint
|
|
114
|
+
}]
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
refreshSpaceGateways();
|
|
119
|
+
setSelectedSpaceGateway(spaceGateway);
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* @description
|
|
124
|
+
* @param {SpaceGateway} spaceGateway
|
|
125
|
+
*/
|
|
126
|
+
const deleteSpaceGateway = async spaceGateway => {
|
|
127
|
+
if (!spaceGateway) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
if (spaceGateway.endpoint === backupEndpoint) {
|
|
131
|
+
_Toast.default.warning(t('storage.spaces.gateway.delete.failedForConnected'));
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
await api.deleteBlockletSpaceGateway({
|
|
135
|
+
input: {
|
|
136
|
+
did: blocklet.meta.did,
|
|
137
|
+
spaceGatewayDid: spaceGateway === null || spaceGateway === void 0 ? void 0 : spaceGateway.did
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
refreshSpaceGateways();
|
|
141
|
+
setSelectedSpaceGateway(spaceGateway);
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* @description
|
|
146
|
+
* @param {SpaceGateway} spaceGateway
|
|
147
|
+
*/
|
|
148
|
+
const updateSpaceGateway = async spaceGateway => {
|
|
149
|
+
var _spaceGateway$name;
|
|
150
|
+
await api.updateBlockletSpaceGateway({
|
|
151
|
+
input: {
|
|
152
|
+
did: blocklet.meta.did,
|
|
153
|
+
where: {
|
|
154
|
+
url: spaceGateway.url
|
|
155
|
+
},
|
|
156
|
+
spaceGateway
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
if (backupEndpoint !== spaceGateway.endpoint) {
|
|
160
|
+
await api.configBlocklet({
|
|
161
|
+
input: {
|
|
162
|
+
did: [blocklet.meta.did],
|
|
163
|
+
configs: [{
|
|
164
|
+
key: _constant.BLOCKLET_CONFIGURABLE_KEY.BLOCKLET_APP_BACKUP_ENDPOINT,
|
|
165
|
+
value: spaceGateway.endpoint
|
|
166
|
+
}]
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
_Toast.default.success(t('storage.spaces.connectedWithName', {
|
|
171
|
+
name: (_spaceGateway$name = spaceGateway === null || spaceGateway === void 0 ? void 0 : spaceGateway.name) !== null && _spaceGateway$name !== void 0 ? _spaceGateway$name : 'DID Spaces'
|
|
172
|
+
}));
|
|
173
|
+
refreshSpaceGateways();
|
|
174
|
+
};
|
|
175
|
+
const refreshSpaceGateways = () => {
|
|
176
|
+
setSpaceGatewaysRefresh(p => !p);
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* @description
|
|
181
|
+
* @param {SpaceGateway} spaceGateway
|
|
182
|
+
*/
|
|
183
|
+
const spaceGatewayIsSelected = spaceGateway => (spaceGateway === null || spaceGateway === void 0 ? void 0 : spaceGateway.endpoint) === backupEndpoint;
|
|
184
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Provider, {
|
|
185
|
+
value: {
|
|
186
|
+
spaceGateways,
|
|
187
|
+
selectedSpaceGateway,
|
|
188
|
+
addSpaceGateway,
|
|
189
|
+
deleteSpaceGateway,
|
|
190
|
+
updateSpaceGateway,
|
|
191
|
+
refreshSpaceGateways,
|
|
192
|
+
spaceGatewaysLoading,
|
|
193
|
+
spaceGatewayIsSelected,
|
|
194
|
+
backupEndpoint,
|
|
195
|
+
backupProgress,
|
|
196
|
+
backups,
|
|
197
|
+
backupsLoading
|
|
198
|
+
},
|
|
199
|
+
children: children
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
BlockletStorageProvider.propTypes = {
|
|
203
|
+
children: _propTypes.default.any.isRequired
|
|
204
|
+
};
|
|
205
|
+
BlockletStorageProvider.defaultProps = {};
|
|
206
|
+
function useBlockletStorageContext() {
|
|
207
|
+
const res = (0, _react.useContext)(BlockletStorageContext);
|
|
208
|
+
return res;
|
|
209
|
+
}
|
package/lib/hooks/use-backups.js
CHANGED
|
@@ -7,19 +7,26 @@ exports.default = useBackups;
|
|
|
7
7
|
var _react = require("react");
|
|
8
8
|
var _lodash = require("lodash");
|
|
9
9
|
var _ahooks = require("ahooks");
|
|
10
|
+
var _Toast = _interopRequireDefault(require("@arcblock/ux/lib/Toast"));
|
|
10
11
|
var _node = require("../contexts/node");
|
|
11
12
|
var _blocklet = require("../contexts/blocklet");
|
|
13
|
+
var _util = require("../util");
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
15
|
/**
|
|
13
16
|
* @description
|
|
14
|
-
* @param {{
|
|
15
|
-
* @return {{backups: import('@abtnode/client').Backup[]}}
|
|
17
|
+
* @param {{ deps: any[], setLoading: (bool: boolean) => void }} { deps }
|
|
18
|
+
* @return {{ backups: import('@abtnode/client').Backup[] }}
|
|
16
19
|
*/
|
|
17
20
|
function useBackups() {
|
|
18
|
-
var _blocklet$
|
|
21
|
+
var _blocklet$meta;
|
|
19
22
|
let {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
|
|
23
|
+
deps,
|
|
24
|
+
setLoading
|
|
25
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
|
|
26
|
+
deps: [],
|
|
27
|
+
setLoading: () => undefined
|
|
28
|
+
};
|
|
29
|
+
/** @type {{ blocklet: import('@abtnode/client').BlockletState }} */
|
|
23
30
|
const {
|
|
24
31
|
blocklet
|
|
25
32
|
} = (0, _blocklet.useBlockletContext)();
|
|
@@ -27,23 +34,35 @@ function useBackups() {
|
|
|
27
34
|
const {
|
|
28
35
|
api
|
|
29
36
|
} = (0, _node.useNodeContext)();
|
|
37
|
+
|
|
30
38
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
31
|
-
const fetchBackups = (0,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
did: blocklet === null || blocklet === void 0 ? void 0 : (_blocklet$meta = blocklet.meta) === null || _blocklet$meta === void 0 ? void 0 : _blocklet$meta.did
|
|
39
|
+
const fetchBackups = (0, _lodash.debounce)(async () => {
|
|
40
|
+
try {
|
|
41
|
+
setLoading(true);
|
|
42
|
+
if (!blocklet) {
|
|
43
|
+
setBackups([]);
|
|
44
|
+
return;
|
|
38
45
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
46
|
+
const {
|
|
47
|
+
backups: data
|
|
48
|
+
} = await api.getBlockletBackups({
|
|
49
|
+
input: {
|
|
50
|
+
did: blocklet.meta.did
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
setBackups(data !== null && data !== void 0 ? data : []);
|
|
54
|
+
} catch (error) {
|
|
55
|
+
console.error(error);
|
|
56
|
+
_Toast.default.error((0, _util.formatError)(error));
|
|
57
|
+
} finally {
|
|
58
|
+
setLoading(false);
|
|
59
|
+
}
|
|
60
|
+
}, 2000);
|
|
42
61
|
|
|
43
62
|
// eslint-disable-next-line require-await
|
|
44
63
|
(0, _ahooks.useAsyncEffect)(async () => {
|
|
45
64
|
fetchBackups();
|
|
46
|
-
}, [blocklet === null || blocklet === void 0 ? void 0 : (_blocklet$
|
|
65
|
+
}, [blocklet === null || blocklet === void 0 ? void 0 : (_blocklet$meta = blocklet.meta) === null || _blocklet$meta === void 0 ? void 0 : _blocklet$meta.did].concat(deps));
|
|
47
66
|
return {
|
|
48
67
|
backups
|
|
49
68
|
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = useSpaceGateways;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _ahooks = require("ahooks");
|
|
9
|
+
var _Toast = _interopRequireDefault(require("@arcblock/ux/lib/Toast"));
|
|
10
|
+
var _node = require("../contexts/node");
|
|
11
|
+
var _spaceGateway = require("../util/space-gateway");
|
|
12
|
+
var _util = require("../../lib/util");
|
|
13
|
+
var _blocklet = require("../contexts/blocklet");
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
/**
|
|
16
|
+
* @description
|
|
17
|
+
* @param {{
|
|
18
|
+
* blockletDid: string,
|
|
19
|
+
* setLoading: (bool: boolean) => void,
|
|
20
|
+
* refresh: boolean,
|
|
21
|
+
* }} { blockletDid, setLoading = () => undefined, refreshBlocklet }
|
|
22
|
+
* @return {{
|
|
23
|
+
* spaceGateways: Array<import('../contexts/blocklet-storage').SpaceGateway>
|
|
24
|
+
* }} {spaceGateways}
|
|
25
|
+
*/
|
|
26
|
+
function useSpaceGateways() {
|
|
27
|
+
var _blocklet$meta;
|
|
28
|
+
let {
|
|
29
|
+
setLoading,
|
|
30
|
+
refresh
|
|
31
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
32
|
+
/** @type {{ blocklet: import('@abtnode/client').BlockletState }} */
|
|
33
|
+
const {
|
|
34
|
+
blocklet,
|
|
35
|
+
actions: {
|
|
36
|
+
refreshBlocklet
|
|
37
|
+
}
|
|
38
|
+
} = (0, _blocklet.useBlockletContext)();
|
|
39
|
+
const blockletDid = blocklet === null || blocklet === void 0 ? void 0 : (_blocklet$meta = blocklet.meta) === null || _blocklet$meta === void 0 ? void 0 : _blocklet$meta.did;
|
|
40
|
+
const [spaceGateways, setSpaceGateways] = (0, _react.useState)([]);
|
|
41
|
+
const {
|
|
42
|
+
api
|
|
43
|
+
} = (0, _node.useNodeContext)();
|
|
44
|
+
(0, _ahooks.useAsyncEffect)(async () => {
|
|
45
|
+
try {
|
|
46
|
+
if (!blockletDid) {
|
|
47
|
+
setSpaceGateways([]);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
setLoading === null || setLoading === void 0 ? void 0 : setLoading(true);
|
|
51
|
+
const {
|
|
52
|
+
spaceGateways: _spaceGateways
|
|
53
|
+
} = await api.getBlockletSpaceGateways({
|
|
54
|
+
input: {
|
|
55
|
+
did: blockletDid
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
const latestSpaceGateways = await (0, _spaceGateway.updateSpaceGatewaysFromDIDSpaces)({
|
|
59
|
+
blockletDid,
|
|
60
|
+
nodeApi: api,
|
|
61
|
+
spaceGateways: _spaceGateways
|
|
62
|
+
});
|
|
63
|
+
setSpaceGateways(latestSpaceGateways !== null && latestSpaceGateways !== void 0 ? latestSpaceGateways : []);
|
|
64
|
+
} catch (error) {
|
|
65
|
+
console.error(error);
|
|
66
|
+
_Toast.default.error((0, _util.formatError)(error));
|
|
67
|
+
} finally {
|
|
68
|
+
setLoading === null || setLoading === void 0 ? void 0 : setLoading(false);
|
|
69
|
+
}
|
|
70
|
+
}, [blockletDid, refreshBlocklet, refresh]);
|
|
71
|
+
return {
|
|
72
|
+
spaceGateways
|
|
73
|
+
};
|
|
74
|
+
}
|
package/lib/locales/en.js
CHANGED
|
@@ -1372,7 +1372,7 @@ module.exports = {
|
|
|
1372
1372
|
provideNFT: {
|
|
1373
1373
|
title: 'Please show the DID Spaces NFT for {appName}',
|
|
1374
1374
|
scan: 'Use your DID Wallet to scan the QR code below to allow the app {appName} show DID space NFT',
|
|
1375
|
-
success: '
|
|
1375
|
+
success: 'Connected successfully'
|
|
1376
1376
|
},
|
|
1377
1377
|
backup: {
|
|
1378
1378
|
title: 'Backup',
|
package/lib/locales/zh.js
CHANGED