@abtnode/ux 1.16.19-beta-7d3ef675 → 1.16.19-beta-ba354e01

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 (49) hide show
  1. package/es/blocklet/component/add-component-core.js +35 -27
  2. package/es/blocklet/component/button.js +12 -0
  3. package/es/blocklet/component/did-space/connect-to.js +355 -0
  4. package/es/blocklet/component/did-space/connected.js +42 -0
  5. package/es/blocklet/component/did-space/delete.js +104 -0
  6. package/es/blocklet/component/did-space/disconnect.js +230 -0
  7. package/es/blocklet/component/did-space/index.js +73 -0
  8. package/es/blocklet/component/did-space/item.js +233 -0
  9. package/es/blocklet/component/index.js +3 -3
  10. package/es/blocklet/component/step-actions.js +99 -0
  11. package/es/blocklet/publish/create-release.js +14 -13
  12. package/es/blocklet/publish/project-list.js +1 -0
  13. package/es/blocklet/publish/release-list.js +1 -0
  14. package/es/blocklet/publish/tree.js +4 -0
  15. package/es/blocklet/resource-type.js +34 -0
  16. package/es/blocklet/storage/connect-to.js +11 -15
  17. package/es/contexts/config-space.js +160 -0
  18. package/es/hooks/use-mobile.js +17 -0
  19. package/es/hooks/use-storage-endpoint.js +23 -0
  20. package/es/images.js +48 -0
  21. package/es/locales/en.js +2 -0
  22. package/es/locales/zh.js +2 -0
  23. package/es/util/index.js +5 -1
  24. package/es/util/spaces.js +66 -5
  25. package/lib/blocklet/component/add-component-core.js +44 -36
  26. package/lib/blocklet/component/button.js +23 -0
  27. package/lib/blocklet/component/did-space/connect-to.js +362 -0
  28. package/lib/blocklet/component/did-space/connected.js +49 -0
  29. package/lib/blocklet/component/did-space/delete.js +111 -0
  30. package/lib/blocklet/component/did-space/disconnect.js +241 -0
  31. package/lib/blocklet/component/did-space/index.js +82 -0
  32. package/lib/blocklet/component/did-space/item.js +197 -0
  33. package/lib/blocklet/component/index.js +3 -3
  34. package/lib/blocklet/component/step-actions.js +63 -0
  35. package/lib/blocklet/publish/create-release.js +14 -13
  36. package/lib/blocklet/publish/project-list.js +1 -0
  37. package/lib/blocklet/publish/release-list.js +1 -0
  38. package/lib/blocklet/publish/tree.js +45 -38
  39. package/lib/blocklet/resource-type.js +51 -0
  40. package/lib/blocklet/storage/connect-to.js +11 -15
  41. package/lib/contexts/config-space.js +169 -0
  42. package/lib/hooks/use-mobile.js +24 -0
  43. package/lib/hooks/use-storage-endpoint.js +28 -0
  44. package/lib/images.js +51 -0
  45. package/lib/locales/en.js +2 -0
  46. package/lib/locales/zh.js +2 -0
  47. package/lib/util/index.js +8 -2
  48. package/lib/util/spaces.js +69 -3
  49. package/package.json +11 -7
@@ -43,7 +43,8 @@ var _agreement = _interopRequireDefault(require("../agreement"));
43
43
  var _installFromUrl = _interopRequireDefault(require("../install-from-url"));
44
44
  var _selectStore = _interopRequireDefault(require("./select-store"));
45
45
  var _storeBlockletList = _interopRequireDefault(require("./store-blocklet-list"));
46
- var _spaceConnector = _interopRequireDefault(require("./space-connector"));
46
+ var _didSpace = _interopRequireDefault(require("./did-space"));
47
+ var _configSpace = require("../../contexts/config-space");
47
48
  var _jsxRuntime = require("react/jsx-runtime");
48
49
  var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7;
49
50
  const _excluded = ["name", "validation"],
@@ -254,6 +255,13 @@ function AddComponentCore(_ref3) {
254
255
  }
255
256
  }, [activeStep]); // eslint-disable-line
256
257
 
258
+ const refreshDidSpaceEndpoint = () => {
259
+ var _getDIDSpaceEndpoint;
260
+ const didSpaceEndpoint = (_getDIDSpaceEndpoint = getDIDSpaceEndpoint(blocklet)) !== null && _getDIDSpaceEndpoint !== void 0 ? _getDIDSpaceEndpoint : '';
261
+ updateParams({
262
+ didSpaceEndpoint
263
+ });
264
+ };
257
265
  const getComponentName = () => {
258
266
  var _component$current;
259
267
  if (component !== null && component !== void 0 && (_component$current = component.current) !== null && _component$current !== void 0 && _component$current.meta) {
@@ -316,6 +324,10 @@ function AddComponentCore(_ref3) {
316
324
  break;
317
325
  default:
318
326
  }
327
+ const didSpaceEndpoint = getDIDSpaceEndpoint(blocklet);
328
+ updateParams(p => _objectSpread(_objectSpread({}, p), {}, {
329
+ didSpaceEndpoint
330
+ }));
319
331
  }), [blocklet === null || blocklet === void 0 ? void 0 : (_blocklet$meta2 = blocklet.meta) === null || _blocklet$meta2 === void 0 ? void 0 : _blocklet$meta2.did]);
320
332
  useSubscription(_constant.BlockletEvents.downloadFailed, createBlockletEventHandler(() => {
321
333
  setInstallErrorResult(t('blocklet.component.installComponentError'));
@@ -424,7 +436,7 @@ function AddComponentCore(_ref3) {
424
436
  errMsg
425
437
  };
426
438
  };
427
- const onNext = async payload => {
439
+ const _onNext = async payload => {
428
440
  const {
429
441
  errMsg
430
442
  } = validateInput(_objectSpread(_objectSpread({}, params), {}, {
@@ -503,7 +515,7 @@ function AddComponentCore(_ref3) {
503
515
  } = _ref4;
504
516
  component.current.downloadTokenList = downloadTokenList;
505
517
  setIsWaitingPurchase(false);
506
- onNext();
518
+ _onNext();
507
519
  };
508
520
  const setConfigValue = _ref5 => {
509
521
  var _blocklet$settings, _meta$environments;
@@ -683,7 +695,7 @@ function AddComponentCore(_ref3) {
683
695
  updateParams({
684
696
  showFromUrlDialog: false
685
697
  });
686
- onNext();
698
+ _onNext();
687
699
  },
688
700
  handleText: {
689
701
  title: t('blocklet.component.addComponentTip.fromUrl'),
@@ -772,7 +784,7 @@ function AddComponentCore(_ref3) {
772
784
  }),
773
785
  onCancel: onOver,
774
786
  onConfirm: () => {
775
- onNext();
787
+ _onNext();
776
788
  }
777
789
  }, {
778
790
  key: 'agreement',
@@ -785,7 +797,7 @@ function AddComponentCore(_ref3) {
785
797
  subTitle: t('blocklet.component.addComponentTip.introduction')
786
798
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_agreement.default, {
787
799
  meta: meta,
788
- onClickNext: onNext,
800
+ onClickNext: _onNext,
789
801
  handleDescEle: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
790
802
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("p", {
791
803
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
@@ -807,7 +819,7 @@ function AddComponentCore(_ref3) {
807
819
  onCancel: _onCancel,
808
820
  onConfirm: () => {
809
821
  setIsWaitingPurchase(false);
810
- onNext();
822
+ _onNext();
811
823
  }
812
824
  }, meta && params.requirePurchase && {
813
825
  key: 'purchase',
@@ -895,7 +907,7 @@ function AddComponentCore(_ref3) {
895
907
  confirm: t('common.next'),
896
908
  onCancel: _onCancel,
897
909
  onConfirm: () => {
898
- onNext();
910
+ _onNext();
899
911
  }
900
912
  }, meta && (params === null || params === void 0 ? void 0 : params.hasEnvironmentsStep) && {
901
913
  key: 'environment',
@@ -942,7 +954,7 @@ function AddComponentCore(_ref3) {
942
954
  cancel: t('common.pre'),
943
955
  confirm: t('common.next'),
944
956
  onCancel: _onCancel,
945
- onConfirm: onNext
957
+ onConfirm: _onNext
946
958
  }, meta && (params === null || params === void 0 ? void 0 : params.didSpaceCapability) && {
947
959
  key: 'didSpace',
948
960
  name: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
@@ -950,41 +962,37 @@ function AddComponentCore(_ref3) {
950
962
  }),
951
963
  disabled: params.didSpaceCapability === 'required' && !params.didSpaceEndpoint,
952
964
  body: () => {
953
- return /*#__PURE__*/(0, _jsxRuntime.jsxs)(TypographyWrapper, {
954
- component: "div",
955
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(PageHeaderWrapper, {
956
- title: t('blocklet.component.didSpaceConfig'),
957
- subTitle: t('blocklet.component.didSpaceConfigTip')
958
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Box.default, {
959
- sx: {
960
- mt: '36px',
961
- '& > div': {
962
- maxWidth: 'unset !important',
963
- '& .MuiAutocomplete-root': {
964
- maxWidth: 'unset !important'
965
- }
966
- }
967
- },
968
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_spaceConnector.default, {
965
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_configSpace.ConfigSpaceProvider, {
966
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(TypographyWrapper, {
967
+ component: "div",
968
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(PageHeaderWrapper, {
969
+ title: t('blocklet.component.didSpaceConfig'),
970
+ subTitle: t('blocklet.component.didSpaceConfigTip')
971
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Box.default, {
969
972
  sx: {
970
- '& .MuiFormHelperText-root': {
971
- wordBreak: 'break-all'
973
+ mt: '36px',
974
+ '& > div': {
975
+ maxWidth: 'unset !important',
976
+ '& .MuiAutocomplete-root': {
977
+ maxWidth: 'unset !important'
978
+ }
972
979
  }
973
980
  },
974
- helperText: params.didSpaceEndpoint && t('blocklet.component.didSpaceConnected', {
975
- endpoint: params.didSpaceEndpoint
976
- }),
977
- onConnect: () => {
978
- onNext();
979
- }
980
- })
981
- })]
981
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_didSpace.default, {
982
+ blockletMeta: component.current.meta,
983
+ onNext: () => {
984
+ _onNext();
985
+ },
986
+ onEndpointUpdate: refreshDidSpaceEndpoint
987
+ })
988
+ })]
989
+ })
982
990
  });
983
991
  },
984
992
  cancel: t('common.pre'),
985
993
  confirm: t('common.next'),
986
994
  onCancel: _onCancel,
987
- onConfirm: onNext
995
+ onConfirm: _onNext
988
996
  }, {
989
997
  key: 'install',
990
998
  name: t('common.install'),
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = StyledButton;
7
+ var _Button = _interopRequireDefault(require("@arcblock/ux/lib/Button"));
8
+ var _jsxRuntime = require("react/jsx-runtime");
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ 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; }
11
+ 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; }
12
+ 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; }
13
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
14
+ 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); }
15
+ function _objectDestructuringEmpty(obj) { if (obj == null) throw new TypeError("Cannot destructure " + obj); }
16
+ function StyledButton(_ref) {
17
+ let props = Object.assign({}, (_objectDestructuringEmpty(_ref), _ref));
18
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.default, _objectSpread({
19
+ className: "bottom-button",
20
+ variant: "contained",
21
+ color: "primary"
22
+ }, props));
23
+ }
@@ -0,0 +1,362 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _material = require("@mui/material");
8
+ var _react = _interopRequireWildcard(require("react"));
9
+ var _Button = _interopRequireDefault(require("@arcblock/ux/lib/Button"));
10
+ var _context = require("@arcblock/ux/lib/Locale/context");
11
+ var _Connect = _interopRequireDefault(require("@arcblock/did-connect/lib/Connect"));
12
+ var _urlJoin = _interopRequireDefault(require("url-join"));
13
+ var _Toast = _interopRequireDefault(require("@arcblock/ux/lib/Toast"));
14
+ var _SplitButton = _interopRequireDefault(require("@arcblock/ux/lib/SplitButton"));
15
+ var _Dialog = _interopRequireDefault(require("@arcblock/ux/lib/Dialog"));
16
+ var _Alert = _interopRequireDefault(require("@arcblock/ux/lib/Alert"));
17
+ var _propTypes = require("prop-types");
18
+ var _constant = require("@abtnode/constant");
19
+ var _useBlockletInfoForConnectDidSpaces = _interopRequireDefault(require("../../../hooks/use-blocklet-info-for-connect-did-spaces"));
20
+ var _spaces = require("../../../util/spaces");
21
+ var _util = require("../../../../lib/util");
22
+ var _blocklet = require("../../../contexts/blocklet");
23
+ var _configSpace = require("../../../contexts/config-space");
24
+ var _node = require("../../../contexts/node");
25
+ var _api = require("../../../util/api");
26
+ var _jsxRuntime = require("react/jsx-runtime");
27
+ const _excluded = ["onConnect"];
28
+ /**
29
+ * @typedef {import('../../../contexts/config-space').SpaceGateway} SpaceGateway
30
+ */
31
+ /**
32
+ * @FIXME: 后续可以思考一下,refactor 一下
33
+ * @description
34
+ * @param {{
35
+ * onConnect(spaceGateway: SpaceGateway): void | Promise<void>,
36
+ * }} { onConnect, ...rest }
37
+ * @return {React.Component}
38
+ */
39
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
40
+ 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); }
41
+ 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; }
42
+ 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; }
43
+ 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; }
44
+ 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; }
45
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
46
+ 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); }
47
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
48
+ 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; }
49
+ function ConnectTo(_ref) {
50
+ let {
51
+ onConnect
52
+ } = _ref,
53
+ rest = _objectWithoutProperties(_ref, _excluded);
54
+ const {
55
+ blocklet
56
+ } = (0, _blocklet.useBlockletContext)();
57
+ const {
58
+ info
59
+ } = (0, _node.useNodeContext)();
60
+ const {
61
+ t,
62
+ locale
63
+ } = (0, _context.useLocaleContext)();
64
+ const [url, setUrl] = (0, _react.useState)('');
65
+ const [loading, setLoading] = (0, _react.useState)(false);
66
+ const [open, setOpen] = (0, _react.useState)(false);
67
+ const [errorMessage, setErrorMessage] = (0, _react.useState)('');
68
+ const blockletInfo = (0, _useBlockletInfoForConnectDidSpaces.default)({
69
+ blocklet
70
+ });
71
+ const webWalletUrl = (0, _util.getWebWalletUrl)(info);
72
+ const {
73
+ storageEndpoint
74
+ } = (0, _configSpace.useConfigSpaceContext)();
75
+ const [authorizeFromNftConnect, setAuthorizeFromNftConnect] = (0, _react.useState)({
76
+ open: false,
77
+ action: 'one-click-authorization',
78
+ checkTimeout: 1000 * 300,
79
+ prefix: (0, _urlJoin.default)(_constant.PROD_DID_SPACES.CORE_URL, 'space/api/did'),
80
+ baseUrl: new URL(_constant.PROD_DID_SPACES.CORE_URL).origin,
81
+ checkFn: _api.axios.create({
82
+ baseURL: (0, _urlJoin.default)(_constant.PROD_DID_SPACES.CORE_URL, 'space')
83
+ }).get,
84
+ messages: {
85
+ title: t('storage.spaces.provideNFT.title', {
86
+ appName: blockletInfo.appName
87
+ }, locale),
88
+ scan: t('storage.spaces.provideNFT.scan', {
89
+ appName: blockletInfo.appName
90
+ }, locale),
91
+ confirm: '',
92
+ success: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
93
+ gutterBottom: true,
94
+ children: t('storage.spaces.provideNFT.success')
95
+ })
96
+ },
97
+ onClose: () => {
98
+ // eslint-disable-next-line no-shadow
99
+ setAuthorizeFromNftConnect(preValue => _objectSpread(_objectSpread({}, preValue), {}, {
100
+ open: false
101
+ }));
102
+ }
103
+ });
104
+ const [authorizeConnect, setAuthorizeConnect] = (0, _react.useState)({
105
+ open: false,
106
+ action: 'one-click-authorization',
107
+ checkTimeout: 1000 * 300,
108
+ messages: {
109
+ title: t('storage.spaces.authorize.title', {
110
+ appName: blockletInfo.appName
111
+ }, locale),
112
+ scan: t('storage.spaces.authorize.scan', {
113
+ appName: blockletInfo.appName
114
+ }, locale),
115
+ confirm: '',
116
+ success: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
117
+ gutterBottom: true,
118
+ children: t('storage.spaces.authorize.success')
119
+ })
120
+ },
121
+ onClose: () => {
122
+ // eslint-disable-next-line no-shadow
123
+ setAuthorizeConnect(preValue => _objectSpread(_objectSpread({}, preValue), {}, {
124
+ open: false
125
+ }));
126
+ }
127
+ });
128
+ const onAuthorizeConnectSuccess = (response, decrypt) => {
129
+ setTimeout(async () => {
130
+ setAuthorizeConnect(preValue => _objectSpread(_objectSpread({}, preValue), {}, {
131
+ open: false
132
+ }));
133
+ setUrl(null);
134
+ setAuthorizeFromNftConnect(preValue => _objectSpread(_objectSpread({}, preValue), {}, {
135
+ open: false
136
+ }));
137
+ const endpoint = decrypt(response.endpoint);
138
+ const space = response.space ? decrypt(response.space) : {};
139
+
140
+ // eslint-disable-next-line no-use-before-define
141
+ await updateSpaceGateway(_objectSpread(_objectSpread({
142
+ endpoint
143
+ }, {
144
+ did: (0, _spaces.getDIDSpaceDidFromEndpoint)(endpoint),
145
+ name: 'DID Space'
146
+ }), space));
147
+ }, 0);
148
+ };
149
+
150
+ /**
151
+ *
152
+ * @param {} {endpoint, name, did}
153
+ * @returns {Promise<void>}
154
+ */
155
+ const updateSpaceGateway = async _ref2 => {
156
+ let {
157
+ did,
158
+ name,
159
+ endpoint
160
+ } = _ref2;
161
+ const spaceGatewayUrl = await (0, _spaces.getSpaceGatewayUrl)(endpoint);
162
+ if (!(await (0, _spaces.isValidSpaceGatewayUrl)(spaceGatewayUrl))) {
163
+ _Toast.default.error(t('storage.spaces.gateway.add.invalidUrl'));
164
+ return;
165
+ }
166
+
167
+ /** @type {SpaceGateway} */
168
+ const spaceGateway = {
169
+ name,
170
+ did,
171
+ url: spaceGatewayUrl,
172
+ endpoint
173
+ };
174
+ await onConnect(spaceGateway);
175
+ _Toast.default.success(t('storage.spaces.connectedWithName', {
176
+ name: spaceGateway.name
177
+ }));
178
+ };
179
+ const handleUseWalletConnect = () => {
180
+ setAuthorizeFromNftConnect(preValue => _objectSpread(_objectSpread({}, preValue), {}, {
181
+ open: true,
182
+ extraParams: {
183
+ appDid: blockletInfo.appDid,
184
+ appName: blockletInfo.appName,
185
+ appDescription: blockletInfo.appDescription,
186
+ scopes: blockletInfo.scopes,
187
+ appUrl: blockletInfo.appUrl,
188
+ referrer: blockletInfo.referrer,
189
+ nodeDid: info.did
190
+ }
191
+ }));
192
+ };
193
+ const handleUseSpaceGatewayConnect = async () => {
194
+ try {
195
+ setLoading(true);
196
+ const spaceGatewayUrl = await (0, _spaces.getSpaceGatewayUrl)(url);
197
+ const didSpacesCoreUrl = (0, _spaces.extraDIDSpacesCoreUrl)(spaceGatewayUrl);
198
+ const spaceDid = new URL(spaceGatewayUrl).searchParams.get('spaceDid');
199
+ if (!(await (0, _spaces.isValidSpaceGatewayUrl)(didSpacesCoreUrl))) {
200
+ throw new Error(t('storage.spaces.gateway.add.invalidUrl'));
201
+ }
202
+ setAuthorizeConnect(preValue => _objectSpread(_objectSpread({}, preValue), {}, {
203
+ open: true,
204
+ prefix: (0, _urlJoin.default)(didSpacesCoreUrl, 'space/api/did'),
205
+ baseUrl: new URL(didSpacesCoreUrl).origin,
206
+ checkFn: _api.axios.create({
207
+ baseURL: (0, _urlJoin.default)(didSpacesCoreUrl, 'space')
208
+ }).get,
209
+ extraParams: {
210
+ appDid: blockletInfo.appDid,
211
+ appName: blockletInfo.appName,
212
+ appDescription: blockletInfo.appDescription,
213
+ scopes: blockletInfo.scopes,
214
+ appUrl: blockletInfo.appUrl,
215
+ referrer: blockletInfo.referrer,
216
+ nodeDid: info.did,
217
+ spaceDid
218
+ }
219
+ }));
220
+ setOpen(false);
221
+ } catch (err) {
222
+ const _errorMessage = "".concat(t('storage.spaces.gateway.add.failed', locale), ": ").concat((0, _util.formatError)(err));
223
+ setErrorMessage(_errorMessage);
224
+ } finally {
225
+ setLoading(false);
226
+ }
227
+ };
228
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Box, {
229
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_SplitButton.default, {
230
+ color: "primary",
231
+ style: {
232
+ textTransform: 'none !important',
233
+ fontSize: '1rem'
234
+ },
235
+ size: "small",
236
+ onClick: handleUseWalletConnect,
237
+ variant: "outlined",
238
+ menu: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_SplitButton.default.Item, _objectSpread(_objectSpread({
239
+ sx: {
240
+ textTransform: 'none'
241
+ },
242
+ onClick: () => setOpen(true),
243
+ size: "small"
244
+ }, rest), {}, {
245
+ children: storageEndpoint ? t('storage.spaces.connect.useSpaceGatewayReconnect') : t('storage.spaces.connect.useSpaceGateway')
246
+ }), "1")],
247
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
248
+ sx: {
249
+ fontWeight: 'bold',
250
+ textTransform: 'none'
251
+ },
252
+ children: storageEndpoint ? t('storage.spaces.connect.useWalletReconnect') : t('storage.spaces.connect.useWallet')
253
+ })
254
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Connect.default, {
255
+ forceConnected: false,
256
+ saveConnect: false,
257
+ prefix: authorizeFromNftConnect.prefix,
258
+ open: authorizeFromNftConnect.open,
259
+ popup: true,
260
+ action: authorizeFromNftConnect.action,
261
+ webWalletUrl: webWalletUrl,
262
+ baseUrl: authorizeFromNftConnect.baseUrl,
263
+ checkFn: authorizeFromNftConnect.checkFn,
264
+ onSuccess: onAuthorizeConnectSuccess,
265
+ onClose: authorizeFromNftConnect.onClose,
266
+ checkTimeout: authorizeFromNftConnect.checkTimeout,
267
+ extraParams: authorizeFromNftConnect.extraParams,
268
+ messages: authorizeFromNftConnect.messages,
269
+ locale: locale
270
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Connect.default, {
271
+ forceConnected: false,
272
+ saveConnect: false,
273
+ prefix: authorizeConnect.prefix,
274
+ open: authorizeConnect.open,
275
+ popup: true,
276
+ action: authorizeConnect.action,
277
+ baseUrl: authorizeConnect.baseUrl,
278
+ checkFn: authorizeConnect.checkFn,
279
+ onSuccess: onAuthorizeConnectSuccess,
280
+ onClose: authorizeConnect.onClose,
281
+ checkTimeout: authorizeConnect.checkTimeout,
282
+ extraParams: authorizeConnect.extraParams,
283
+ messages: authorizeConnect.messages,
284
+ locale: locale
285
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Dialog.default, {
286
+ title: t('storage.spaces.gateway.add.title'),
287
+ fullWidth: true,
288
+ maxWidth: "md",
289
+ open: open,
290
+ onClose: () => setOpen(false),
291
+ PaperProps: {
292
+ style: {
293
+ minHeight: 'auto'
294
+ }
295
+ },
296
+ actions: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
297
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.default, {
298
+ onClick: e => {
299
+ e.stopPropagation();
300
+ setOpen(false);
301
+ },
302
+ color: "inherit",
303
+ children: t('common.cancel')
304
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Button.default, {
305
+ onClick: handleUseSpaceGatewayConnect,
306
+ color: "primary",
307
+ disabled: loading || !url,
308
+ variant: "contained",
309
+ autoFocus: true,
310
+ children: [loading && /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.CircularProgress, {
311
+ size: 16
312
+ }), t('common.confirm')]
313
+ })]
314
+ }),
315
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
316
+ style: {
317
+ paddingTop: 12,
318
+ overflowY: 'hidden'
319
+ },
320
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.DialogContentText, {
321
+ component: "div",
322
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
323
+ component: "div",
324
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.TextField, {
325
+ label: t('storage.spaces.gateway.add.label'),
326
+ autoComplete: "off",
327
+ variant: "outlined",
328
+ name: "url",
329
+ fullWidth: true,
330
+ value: url,
331
+ onChange: e => {
332
+ setErrorMessage(null);
333
+ setUrl(e.target.value);
334
+ },
335
+ disabled: loading,
336
+ onKeyPress: async e => {
337
+ if (e.key === 'Enter') {
338
+ await handleUseSpaceGatewayConnect();
339
+ }
340
+ },
341
+ autoFocus: true
342
+ })
343
+ })
344
+ })
345
+ }), Boolean(errorMessage) && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Alert.default, {
346
+ type: "error",
347
+ style: {
348
+ width: '100%'
349
+ },
350
+ children: errorMessage
351
+ })]
352
+ })]
353
+ });
354
+ }
355
+ ConnectTo.propTypes = {
356
+ onConnect: _propTypes.func
357
+ };
358
+ ConnectTo.defaultProps = {
359
+ onConnect: () => undefined
360
+ };
361
+ var _default = ConnectTo;
362
+ exports.default = _default;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _material = require("@mui/material");
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _context = require("@arcblock/ux/lib/Locale/context");
10
+ var _item = _interopRequireDefault(require("./item"));
11
+ var _configSpace = require("../../../contexts/config-space");
12
+ var _jsxRuntime = require("react/jsx-runtime");
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
+ function Connected() {
15
+ const {
16
+ t
17
+ } = (0, _context.useLocaleContext)();
18
+ const {
19
+ spaceGateway,
20
+ settingStorageEndpoint
21
+ } = (0, _configSpace.useConfigSpaceContext)();
22
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Box, {
23
+ display: "flex",
24
+ flexDirection: "column",
25
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, {
26
+ display: "flex",
27
+ flexDirection: "row",
28
+ alignItems: "center",
29
+ justifyContent: "space-between",
30
+ marginBottom: "12px",
31
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
32
+ fontSize: "1.2rem",
33
+ fontWeight: "bold",
34
+ children: t('storage.spaces.connected.title')
35
+ })
36
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, {
37
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_item.default, {
38
+ style: {
39
+ marginTop: '12px'
40
+ },
41
+ spaceGateway: spaceGateway,
42
+ connected: true,
43
+ onDisconnect: () => settingStorageEndpoint(null)
44
+ }, spaceGateway.endpoint)
45
+ })]
46
+ });
47
+ }
48
+ var _default = Connected;
49
+ exports.default = _default;