@arcblock/ux 2.4.43 → 2.4.45
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/lib/Address/compact-text.js +145 -0
- package/lib/Address/did-address.js +218 -0
- package/lib/Address/index.js +54 -0
- package/lib/Address/responsive-did-address.js +106 -0
- package/lib/Avatar/did-motif.js +89 -0
- package/lib/Avatar/etherscan-blockies.js +108 -0
- package/lib/Avatar/index.js +166 -0
- package/lib/CodeBlock/LightBox.js +1 -1
- package/lib/DidLogo/index.js +46 -0
- package/lib/SessionManager/index.js +408 -0
- package/lib/Util/wallet.js +49 -0
- package/lib/WebWalletSWKeeper/index.js +143 -0
- package/lib/index.js +48 -0
- package/package.json +6 -4
- package/src/Address/compact-text.js +77 -0
- package/src/Address/did-address.js +215 -0
- package/src/Address/index.js +22 -0
- package/src/Address/responsive-did-address.js +77 -0
- package/src/Avatar/did-motif.js +40 -0
- package/src/Avatar/etherscan-blockies.js +81 -0
- package/src/Avatar/index.js +141 -0
- package/src/CodeBlock/LightBox.js +5 -3
- package/src/DidLogo/index.js +30 -0
- package/src/SessionManager/index.js +366 -0
- package/src/Util/wallet.js +35 -0
- package/src/WebWalletSWKeeper/index.js +103 -0
- package/src/index.js +12 -0
@@ -0,0 +1,408 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
|
8
|
+
var _react = require("react");
|
9
|
+
|
10
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
11
|
+
|
12
|
+
var _material = require("@mui/material");
|
13
|
+
|
14
|
+
var _Account = _interopRequireDefault(require("@arcblock/icons/lib/Account"));
|
15
|
+
|
16
|
+
var _ShieldCheck = _interopRequireDefault(require("mdi-material-ui/ShieldCheck"));
|
17
|
+
|
18
|
+
var _OpenIn = _interopRequireDefault(require("@arcblock/icons/lib/OpenIn"));
|
19
|
+
|
20
|
+
var _Disconnect = _interopRequireDefault(require("@arcblock/icons/lib/Disconnect"));
|
21
|
+
|
22
|
+
var _Switch = _interopRequireDefault(require("@arcblock/icons/lib/Switch"));
|
23
|
+
|
24
|
+
var _PersonOutline = _interopRequireDefault(require("@mui/icons-material/PersonOutline"));
|
25
|
+
|
26
|
+
var _VpnKeyOutlined = _interopRequireDefault(require("@mui/icons-material/VpnKeyOutlined"));
|
27
|
+
|
28
|
+
var _useBrowser = _interopRequireDefault(require("@arcblock/react-hooks/lib/useBrowser"));
|
29
|
+
|
30
|
+
var _Theme = require("../Theme");
|
31
|
+
|
32
|
+
var _Avatar = _interopRequireDefault(require("../Avatar"));
|
33
|
+
|
34
|
+
var _Address = _interopRequireDefault(require("../Address"));
|
35
|
+
|
36
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
37
|
+
|
38
|
+
var _templateObject;
|
39
|
+
|
40
|
+
const _excluded = ["session", "locale", "showText", "showRole", "switchDid", "switchProfile", "switchPassport", "disableLogout", "onLogin", "onLogout", "onSwitchDid", "onSwitchProfile", "onSwitchPassport", "menu", "menuRender", "dark", "size"],
|
41
|
+
_excluded2 = ["svgIcon"];
|
42
|
+
|
43
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
44
|
+
|
45
|
+
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
46
|
+
|
47
|
+
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; }
|
48
|
+
|
49
|
+
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; }
|
50
|
+
|
51
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
52
|
+
|
53
|
+
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; }
|
54
|
+
|
55
|
+
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; }
|
56
|
+
|
57
|
+
const messages = {
|
58
|
+
zh: {
|
59
|
+
switchDid: '切换账户',
|
60
|
+
switchProfile: '切换用户信息',
|
61
|
+
switchPassport: '切换通行证',
|
62
|
+
disconnect: '退出',
|
63
|
+
connect: '登录',
|
64
|
+
openInWallet: '打开 DID 钱包'
|
65
|
+
},
|
66
|
+
en: {
|
67
|
+
switchDid: 'Switch DID',
|
68
|
+
switchProfile: 'Switch Profile',
|
69
|
+
switchPassport: 'Switch Passport',
|
70
|
+
disconnect: 'Disconnect',
|
71
|
+
connect: 'Connect',
|
72
|
+
openInWallet: 'Open DID Wallet'
|
73
|
+
}
|
74
|
+
};
|
75
|
+
|
76
|
+
function SessionManager(_ref) {
|
77
|
+
var _session$user, _session$user$avatar, _session$user3, _session$user4;
|
78
|
+
|
79
|
+
let {
|
80
|
+
session,
|
81
|
+
locale,
|
82
|
+
showText,
|
83
|
+
showRole,
|
84
|
+
switchDid,
|
85
|
+
switchProfile,
|
86
|
+
switchPassport,
|
87
|
+
disableLogout,
|
88
|
+
onLogin,
|
89
|
+
onLogout,
|
90
|
+
onSwitchDid,
|
91
|
+
onSwitchProfile,
|
92
|
+
onSwitchPassport,
|
93
|
+
menu,
|
94
|
+
menuRender,
|
95
|
+
dark,
|
96
|
+
size
|
97
|
+
} = _ref,
|
98
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
99
|
+
|
100
|
+
const userAnchorRef = (0, _react.useRef)(null);
|
101
|
+
const [userOpen, setUserOpen] = (0, _react.useState)(false); // base64 img maybe have some blank char, need encodeURIComponent to transform it
|
102
|
+
|
103
|
+
const avatar = (_session$user = session.user) === null || _session$user === void 0 ? void 0 : (_session$user$avatar = _session$user.avatar) === null || _session$user$avatar === void 0 ? void 0 : _session$user$avatar.replace(/\s/g, encodeURIComponent(' '));
|
104
|
+
const currentRole = (0, _react.useMemo)(() => {
|
105
|
+
var _session$user2, _session$user2$passpo;
|
106
|
+
|
107
|
+
return (_session$user2 = session.user) === null || _session$user2 === void 0 ? void 0 : (_session$user2$passpo = _session$user2.passports) === null || _session$user2$passpo === void 0 ? void 0 : _session$user2$passpo.find(item => item.name === session.user.role);
|
108
|
+
}, [session.user]);
|
109
|
+
const browser = (0, _useBrowser.default)();
|
110
|
+
|
111
|
+
if (!session.user) {
|
112
|
+
return showText ? /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Button, _objectSpread(_objectSpread({
|
113
|
+
sx: [{
|
114
|
+
borderRadius: '100vw'
|
115
|
+
}, dark && {
|
116
|
+
color: '#fff',
|
117
|
+
borderColor: '#fff'
|
118
|
+
}],
|
119
|
+
variant: "outlined",
|
120
|
+
onClick: _onLogin,
|
121
|
+
"aria-label": "login button"
|
122
|
+
}, rest), {}, {
|
123
|
+
"data-cy": "sessionManager-login",
|
124
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Account.default, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
125
|
+
style: {
|
126
|
+
lineHeight: '25px'
|
127
|
+
},
|
128
|
+
children: messages[locale].connect
|
129
|
+
})]
|
130
|
+
})) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.IconButton, _objectSpread(_objectSpread({}, rest), {}, {
|
131
|
+
onClick: _onLogin,
|
132
|
+
"data-cy": "sessionManager-login",
|
133
|
+
size: "medium",
|
134
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Account.default, {
|
135
|
+
style: {
|
136
|
+
width: size,
|
137
|
+
height: size,
|
138
|
+
color: dark ? '#fff' : ''
|
139
|
+
}
|
140
|
+
})
|
141
|
+
}));
|
142
|
+
}
|
143
|
+
|
144
|
+
function onToggleUser() {
|
145
|
+
setUserOpen(prevOpen => !prevOpen);
|
146
|
+
}
|
147
|
+
|
148
|
+
function onCloseUser(e) {
|
149
|
+
if (userAnchorRef.current && userAnchorRef.current.contains(e.target)) {
|
150
|
+
return;
|
151
|
+
}
|
152
|
+
|
153
|
+
setUserOpen(false);
|
154
|
+
}
|
155
|
+
|
156
|
+
function _onLogin() {
|
157
|
+
session.login(onLogin);
|
158
|
+
}
|
159
|
+
|
160
|
+
function _onLogout() {
|
161
|
+
session.logout(function () {
|
162
|
+
setUserOpen(false);
|
163
|
+
onLogout(...arguments);
|
164
|
+
});
|
165
|
+
}
|
166
|
+
|
167
|
+
function _onSwitchDid() {
|
168
|
+
session.switchDid(function () {
|
169
|
+
setUserOpen(false);
|
170
|
+
onSwitchDid(...arguments);
|
171
|
+
});
|
172
|
+
}
|
173
|
+
|
174
|
+
function _onSwitchProfile() {
|
175
|
+
session.switchProfile(function () {
|
176
|
+
setUserOpen(false);
|
177
|
+
onSwitchProfile(...arguments);
|
178
|
+
});
|
179
|
+
}
|
180
|
+
|
181
|
+
function _onSwitchPassport() {
|
182
|
+
setUserOpen(false);
|
183
|
+
session.switchPassport(function () {
|
184
|
+
setUserOpen(false);
|
185
|
+
onSwitchPassport(...arguments);
|
186
|
+
});
|
187
|
+
}
|
188
|
+
|
189
|
+
const message = messages[locale] || messages.en;
|
190
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
191
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.IconButton, _objectSpread(_objectSpread({
|
192
|
+
ref: userAnchorRef,
|
193
|
+
onClick: onToggleUser
|
194
|
+
}, rest), {}, {
|
195
|
+
"data-cy": "sessionManager-logout-popup",
|
196
|
+
size: "medium",
|
197
|
+
style: {
|
198
|
+
lineHeight: 1
|
199
|
+
},
|
200
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Avatar.default, {
|
201
|
+
variant: "circle",
|
202
|
+
did: session.user.did,
|
203
|
+
src: avatar,
|
204
|
+
size: size,
|
205
|
+
shape: "circle"
|
206
|
+
})
|
207
|
+
})), userAnchorRef.current && /*#__PURE__*/(0, _jsxRuntime.jsx)(StyledPopper, {
|
208
|
+
open: userOpen,
|
209
|
+
disablePortal: true,
|
210
|
+
anchorEl: userAnchorRef.current,
|
211
|
+
placement: "bottom-end",
|
212
|
+
$dark: dark,
|
213
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Paper, {
|
214
|
+
sx: [theme => ({
|
215
|
+
borderColor: '#F0F0F0',
|
216
|
+
boxShadow: '0px 8px 12px rgba(92, 92, 92, 0.04)',
|
217
|
+
borderRadius: theme.spacing(2),
|
218
|
+
overflow: 'hidden',
|
219
|
+
maxWidth: 'calc(100vw - 10px)',
|
220
|
+
'& .MuiChip-root .MuiChip-icon': {
|
221
|
+
color: theme.palette.success.main
|
222
|
+
}
|
223
|
+
}), dark && {
|
224
|
+
backgroundColor: '#27282c',
|
225
|
+
color: '#fff',
|
226
|
+
border: 0,
|
227
|
+
'& .MuiChip-root': {
|
228
|
+
borderColor: '#aaa'
|
229
|
+
},
|
230
|
+
'& .MuiListItem-root, & .MuiChip-label': {
|
231
|
+
color: '#aaa'
|
232
|
+
},
|
233
|
+
'& .MuiListItem-root:hover': {
|
234
|
+
backgroundColor: '#363434'
|
235
|
+
}
|
236
|
+
}],
|
237
|
+
variant: "outlined",
|
238
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.ClickAwayListener, {
|
239
|
+
onClickAway: onCloseUser,
|
240
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.MenuList, {
|
241
|
+
sx: {
|
242
|
+
p: 0
|
243
|
+
},
|
244
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
245
|
+
className: "session-manager-user",
|
246
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
247
|
+
className: "session-manager-user-name",
|
248
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
249
|
+
children: session.user.fullName
|
250
|
+
}), !!showRole && ((currentRole === null || currentRole === void 0 ? void 0 : currentRole.title) || ((_session$user3 = session.user) === null || _session$user3 === void 0 ? void 0 : _session$user3.role.toUpperCase())) && /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Chip, {
|
251
|
+
label: (currentRole === null || currentRole === void 0 ? void 0 : currentRole.title) || ((_session$user4 = session.user) === null || _session$user4 === void 0 ? void 0 : _session$user4.role.toUpperCase()),
|
252
|
+
size: "small",
|
253
|
+
variant: "outlined",
|
254
|
+
sx: {
|
255
|
+
height: 'auto',
|
256
|
+
marginRight: 0
|
257
|
+
},
|
258
|
+
icon: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.SvgIcon, {
|
259
|
+
component: _ShieldCheck.default,
|
260
|
+
size: "small"
|
261
|
+
})
|
262
|
+
})]
|
263
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Address.default, {
|
264
|
+
responsive: false,
|
265
|
+
children: session.user.did
|
266
|
+
})]
|
267
|
+
}), Array.isArray(menu) && menu.map((menuItem, index) => {
|
268
|
+
const {
|
269
|
+
svgIcon
|
270
|
+
} = menuItem,
|
271
|
+
menuProps = _objectWithoutProperties(menuItem, _excluded2);
|
272
|
+
|
273
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.MenuItem, _objectSpread(_objectSpread({
|
274
|
+
className: "session-manager-menu-item"
|
275
|
+
}, _objectSpread(_objectSpread({}, menuProps), {}, {
|
276
|
+
icon: undefined,
|
277
|
+
label: undefined
|
278
|
+
})), {}, {
|
279
|
+
children: [svgIcon ? svgIcon && /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.SvgIcon, {
|
280
|
+
component: svgIcon,
|
281
|
+
className: "session-manager-menu-icon"
|
282
|
+
}) : menuItem.icon, menuItem.label]
|
283
|
+
}), index);
|
284
|
+
}), menuRender({
|
285
|
+
classes: {
|
286
|
+
menuItem: 'session-manager-menu-item',
|
287
|
+
menuIcon: 'session-manager-menu-icon'
|
288
|
+
}
|
289
|
+
}), !browser.wallet && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.MenuItem, {
|
290
|
+
component: "a",
|
291
|
+
className: "session-manager-menu-item",
|
292
|
+
"data-cy": "sessionManager-openInWallet",
|
293
|
+
href: "https://www.abtwallet.io/",
|
294
|
+
target: "_blank",
|
295
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.SvgIcon, {
|
296
|
+
component: _OpenIn.default,
|
297
|
+
className: "session-manager-menu-icon"
|
298
|
+
}), message.openInWallet]
|
299
|
+
}), !!switchDid && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.MenuItem, {
|
300
|
+
className: "session-manager-menu-item",
|
301
|
+
onClick: _onSwitchDid,
|
302
|
+
"data-cy": "sessionManager-switch-trigger",
|
303
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.SvgIcon, {
|
304
|
+
component: _Switch.default,
|
305
|
+
className: "session-manager-menu-icon"
|
306
|
+
}), message.switchDid]
|
307
|
+
}), !!switchProfile && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.MenuItem, {
|
308
|
+
className: "session-manager-menu-item",
|
309
|
+
onClick: _onSwitchProfile,
|
310
|
+
"data-cy": "sessionManager-switch-profile-trigger",
|
311
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.SvgIcon, {
|
312
|
+
component: _PersonOutline.default,
|
313
|
+
className: "session-manager-menu-icon"
|
314
|
+
}), message.switchProfile]
|
315
|
+
}), !!switchPassport && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.MenuItem, {
|
316
|
+
className: "session-manager-menu-item",
|
317
|
+
onClick: _onSwitchPassport,
|
318
|
+
"data-cy": "sessionManager-switch-passport-trigger",
|
319
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.SvgIcon, {
|
320
|
+
component: _VpnKeyOutlined.default,
|
321
|
+
className: "session-manager-menu-icon"
|
322
|
+
}), message.switchPassport]
|
323
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.MenuItem, {
|
324
|
+
className: "session-manager-menu-item",
|
325
|
+
onClick: _onLogout,
|
326
|
+
disabled: disableLogout,
|
327
|
+
"data-cy": "sessionManager-logout-trigger",
|
328
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.SvgIcon, {
|
329
|
+
component: _Disconnect.default,
|
330
|
+
className: "session-manager-menu-icon"
|
331
|
+
}), message.disconnect]
|
332
|
+
})]
|
333
|
+
})
|
334
|
+
})
|
335
|
+
})
|
336
|
+
})]
|
337
|
+
});
|
338
|
+
}
|
339
|
+
|
340
|
+
SessionManager.propTypes = {
|
341
|
+
session: _propTypes.default.shape({
|
342
|
+
user: _propTypes.default.shape({
|
343
|
+
did: _propTypes.default.string.isRequired,
|
344
|
+
role: _propTypes.default.string.isRequired,
|
345
|
+
fullName: _propTypes.default.string,
|
346
|
+
avatar: _propTypes.default.string,
|
347
|
+
passports: _propTypes.default.arrayOf(_propTypes.default.shape({
|
348
|
+
name: _propTypes.default.string.isRequired,
|
349
|
+
title: _propTypes.default.string.isRequired
|
350
|
+
}))
|
351
|
+
}),
|
352
|
+
login: _propTypes.default.func.isRequired,
|
353
|
+
logout: _propTypes.default.func.isRequired,
|
354
|
+
switchDid: _propTypes.default.func.isRequired,
|
355
|
+
switchProfile: _propTypes.default.func.isRequired,
|
356
|
+
switchPassport: _propTypes.default.func.isRequired
|
357
|
+
}).isRequired,
|
358
|
+
locale: _propTypes.default.string,
|
359
|
+
showText: _propTypes.default.bool,
|
360
|
+
showRole: _propTypes.default.bool,
|
361
|
+
switchDid: _propTypes.default.bool,
|
362
|
+
switchProfile: _propTypes.default.bool,
|
363
|
+
switchPassport: _propTypes.default.bool,
|
364
|
+
disableLogout: _propTypes.default.bool,
|
365
|
+
onLogin: _propTypes.default.func,
|
366
|
+
onLogout: _propTypes.default.func,
|
367
|
+
onSwitchDid: _propTypes.default.func,
|
368
|
+
onSwitchProfile: _propTypes.default.func,
|
369
|
+
onSwitchPassport: _propTypes.default.func,
|
370
|
+
menu: _propTypes.default.array,
|
371
|
+
menuRender: _propTypes.default.func,
|
372
|
+
dark: _propTypes.default.bool,
|
373
|
+
size: _propTypes.default.number
|
374
|
+
};
|
375
|
+
|
376
|
+
const noop = () => {};
|
377
|
+
|
378
|
+
SessionManager.defaultProps = {
|
379
|
+
locale: 'en',
|
380
|
+
showText: false,
|
381
|
+
showRole: false,
|
382
|
+
switchDid: true,
|
383
|
+
switchProfile: true,
|
384
|
+
switchPassport: true,
|
385
|
+
disableLogout: false,
|
386
|
+
menu: [],
|
387
|
+
menuRender: noop,
|
388
|
+
onLogin: noop,
|
389
|
+
onLogout: noop,
|
390
|
+
onSwitchDid: noop,
|
391
|
+
onSwitchProfile: noop,
|
392
|
+
onSwitchPassport: noop,
|
393
|
+
dark: false,
|
394
|
+
size: 24
|
395
|
+
};
|
396
|
+
const StyledPopper = (0, _Theme.styled)(_material.Popper)(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n z-index: ", ";\n .MuiList-root {\n width: 280px;\n }\n .session-manager-user {\n font-size: 12px;\n flex-direction: column;\n align-items: flex-start;\n padding: 24px 24px 10px;\n }\n .session-manager-user-name {\n font-size: 20px;\n color: ", ";\n font-weight: bold;\n margin-bottom: 10px;\n display: flex;\n align-items: center;\n justify-content: space-between;\n }\n .session-manager-menu-item {\n padding: 18.5px 24px;\n color: #777;\n font-size: 16px;\n &:hover {\n background-color: #fbfbfb;\n }\n }\n .session-manager-menu-icon {\n color: #999;\n margin-right: 16px;\n }\n"])), _ref2 => {
|
397
|
+
let {
|
398
|
+
theme
|
399
|
+
} = _ref2;
|
400
|
+
return theme.zIndex.tooltip;
|
401
|
+
}, _ref3 => {
|
402
|
+
let {
|
403
|
+
$dark
|
404
|
+
} = _ref3;
|
405
|
+
return $dark ? '#aaa' : '#222';
|
406
|
+
});
|
407
|
+
var _default = SessionManager;
|
408
|
+
exports.default = _default;
|
@@ -0,0 +1,49 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.providerName = exports.getWebWalletUrl = exports.checkSameProtocol = void 0;
|
7
|
+
|
8
|
+
/* eslint-disable import/prefer-default-export */
|
9
|
+
const providerName = 'wallet_url';
|
10
|
+
/**
|
11
|
+
* 获取 web wallet url, 常用于为 did connect 组件传递 webWalletUrl 参数,
|
12
|
+
* 更明确的说, 这里获取的应该是 **default web wallet url**,
|
13
|
+
* 如果用户使用自定义的 web wallet url, 不应该使用该方法, 应该显式的将自定义的 web wallet url 传递给 did connect 组件
|
14
|
+
* (参考: https://github.com/blocklet/ocap-playground/issues/98)
|
15
|
+
*
|
16
|
+
* 获取优先级:
|
17
|
+
* - localStorage 使用 provider 注册
|
18
|
+
* - window.env.webWalletUrl
|
19
|
+
* - window.blocklet.webWalletUrl
|
20
|
+
* - production web wallet url
|
21
|
+
*/
|
22
|
+
|
23
|
+
exports.providerName = providerName;
|
24
|
+
|
25
|
+
const getWebWalletUrl = () => {
|
26
|
+
var _window$env, _window$blocklet;
|
27
|
+
|
28
|
+
return window.localStorage.getItem(providerName) || ((_window$env = window.env) === null || _window$env === void 0 ? void 0 : _window$env.webWalletUrl) || ((_window$blocklet = window.blocklet) === null || _window$blocklet === void 0 ? void 0 : _window$blocklet.webWalletUrl) || 'https://web.abtwallet.io/';
|
29
|
+
}; // 检查 wallet url protocol 和当前页面地址的 protocol 是否一致
|
30
|
+
|
31
|
+
|
32
|
+
exports.getWebWalletUrl = getWebWalletUrl;
|
33
|
+
|
34
|
+
const checkSameProtocol = webWalletUrl => {
|
35
|
+
const {
|
36
|
+
protocol
|
37
|
+
} = window.location;
|
38
|
+
let walletProtocol = '';
|
39
|
+
|
40
|
+
try {
|
41
|
+
walletProtocol = new URL(webWalletUrl).protocol;
|
42
|
+
} catch (error) {
|
43
|
+
walletProtocol = '';
|
44
|
+
}
|
45
|
+
|
46
|
+
return protocol === walletProtocol;
|
47
|
+
};
|
48
|
+
|
49
|
+
exports.checkSameProtocol = checkSameProtocol;
|
@@ -0,0 +1,143 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.withWebWalletSWKeeper = exports.default = void 0;
|
7
|
+
|
8
|
+
var _react = require("react");
|
9
|
+
|
10
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
11
|
+
|
12
|
+
var _useIdle = _interopRequireDefault(require("react-use/lib/useIdle"));
|
13
|
+
|
14
|
+
var _useLocalStorage = _interopRequireDefault(require("react-use/lib/useLocalStorage"));
|
15
|
+
|
16
|
+
var _useBrowser = _interopRequireDefault(require("@arcblock/react-hooks/lib/useBrowser"));
|
17
|
+
|
18
|
+
var _wallet = require("../Util/wallet");
|
19
|
+
|
20
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
21
|
+
|
22
|
+
const _excluded = ["webWalletUrl", "maxIdleTime"];
|
23
|
+
|
24
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
25
|
+
|
26
|
+
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; }
|
27
|
+
|
28
|
+
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; }
|
29
|
+
|
30
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
31
|
+
|
32
|
+
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; }
|
33
|
+
|
34
|
+
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; }
|
35
|
+
|
36
|
+
// 默认最大空闲时间: 30min
|
37
|
+
const DEFAULT_MAX_IDLE_TIME = 1000 * 60 * 30; // 可使用 localStorage.setItem('wallet_sw_keeper_disabled', 1) 来禁用嵌入 wallet iframe
|
38
|
+
|
39
|
+
const STORAGE_KEY_DISABLED = 'wallet_sw_keeper_disabled'; // iframe id, 如果存在多个 WebWalletSWKeeper 组件实例, 共享此 id, 保证只有一个 iframe
|
40
|
+
|
41
|
+
let id;
|
42
|
+
|
43
|
+
const injectIframe = webWalletUrl => {
|
44
|
+
const iframe = document.createElement('iframe');
|
45
|
+
iframe.title = 'abt wallet';
|
46
|
+
iframe.id = id;
|
47
|
+
iframe.style.width = 0;
|
48
|
+
iframe.style.height = 0;
|
49
|
+
iframe.style.border = 0; // https://stackoverflow.com/questions/27858989/iframe-with-0-height-creates-a-gap
|
50
|
+
|
51
|
+
iframe.style.display = 'block'; // fix: 页面自动滚动到底部问题 (https://github.com/blocklet/abt-wallet/issues/1160)
|
52
|
+
// top: 0 可能不是必须的, 但测试中发现, 如果不设置, 在某些特殊情况下似乎也会导致页面自动滚动到底部
|
53
|
+
|
54
|
+
iframe.style.position = 'absolute';
|
55
|
+
iframe.style.top = 0;
|
56
|
+
iframe.src = "".concat(webWalletUrl, "?action=iframe");
|
57
|
+
document.body.appendChild(iframe);
|
58
|
+
};
|
59
|
+
|
60
|
+
const removeIframe = () => {
|
61
|
+
const iframe = document.getElementById(id);
|
62
|
+
|
63
|
+
if (iframe) {
|
64
|
+
document.body.removeChild(iframe);
|
65
|
+
}
|
66
|
+
};
|
67
|
+
|
68
|
+
const cleanup = () => {
|
69
|
+
removeIframe();
|
70
|
+
id = null;
|
71
|
+
};
|
72
|
+
|
73
|
+
const enable = webWalletUrl => {
|
74
|
+
if (!id) {
|
75
|
+
id = "web_wallet_sw_keeper_".concat(Date.now());
|
76
|
+
injectIframe(webWalletUrl);
|
77
|
+
}
|
78
|
+
}; // 该组件通过嵌入一个 web wallet iframe 帮助 web wallet service worker 延最大空闲时间
|
79
|
+
|
80
|
+
|
81
|
+
function WebWalletSWKeeper(_ref) {
|
82
|
+
let {
|
83
|
+
webWalletUrl,
|
84
|
+
maxIdleTime
|
85
|
+
} = _ref;
|
86
|
+
const isIdle = (0, _useIdle.default)(maxIdleTime); // 用户操作空闲时间超过 maxIdleTime 时禁用, 活跃时启用
|
87
|
+
|
88
|
+
(0, _react.useEffect)(() => {
|
89
|
+
if (isIdle) {
|
90
|
+
cleanup();
|
91
|
+
} else {
|
92
|
+
enable(webWalletUrl);
|
93
|
+
} // eslint-disable-next-line react-hooks/exhaustive-deps
|
94
|
+
|
95
|
+
}, [isIdle]); // 组件销毁时自动清理
|
96
|
+
|
97
|
+
(0, _react.useEffect)(() => () => cleanup(), []);
|
98
|
+
return null;
|
99
|
+
}
|
100
|
+
|
101
|
+
WebWalletSWKeeper.propTypes = {
|
102
|
+
webWalletUrl: _propTypes.default.string.isRequired,
|
103
|
+
maxIdleTime: _propTypes.default.number
|
104
|
+
};
|
105
|
+
WebWalletSWKeeper.defaultProps = {
|
106
|
+
maxIdleTime: DEFAULT_MAX_IDLE_TIME
|
107
|
+
};
|
108
|
+
var _default = WebWalletSWKeeper;
|
109
|
+
exports.default = _default;
|
110
|
+
|
111
|
+
const withWebWalletSWKeeper = Component => {
|
112
|
+
// eslint-disable-next-line react/prop-types
|
113
|
+
return function WithWebWalletSWKeeperComponent(_ref2) {
|
114
|
+
let {
|
115
|
+
webWalletUrl,
|
116
|
+
maxIdleTime
|
117
|
+
} = _ref2,
|
118
|
+
rest = _objectWithoutProperties(_ref2, _excluded);
|
119
|
+
|
120
|
+
const browser = (0, _useBrowser.default)(); // eslint-disable-next-line no-param-reassign
|
121
|
+
|
122
|
+
webWalletUrl = webWalletUrl || (0, _wallet.getWebWalletUrl)();
|
123
|
+
const [disabled] = (0, _useLocalStorage.default)(STORAGE_KEY_DISABLED);
|
124
|
+
const webWalletExtension = window.ABT_DEV || window.ABT;
|
125
|
+
const isSameProtocol = (0, _wallet.checkSameProtocol)(webWalletUrl);
|
126
|
+
const isWalletWebview = browser.wallet; // 以下几种情况不会嵌入 wallet iframe :
|
127
|
+
// - 通过设置 localStorage#wallet_sw_keeper_disabled = 1 明确禁止 (开发调试过程中可以使用, 避免控制台打印一堆日志影响调试)
|
128
|
+
// - 检查到 wallet 浏览器插件
|
129
|
+
// - webWalletUrl 与当前页面 url 的 protocol 不同
|
130
|
+
// - wallet webview
|
131
|
+
|
132
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
133
|
+
children: [!disabled && !webWalletExtension && isSameProtocol && !isWalletWebview && /*#__PURE__*/(0, _jsxRuntime.jsx)(WebWalletSWKeeper, {
|
134
|
+
webWalletUrl: webWalletUrl,
|
135
|
+
maxIdleTime: maxIdleTime
|
136
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, _objectSpread({
|
137
|
+
webWalletUrl: webWalletUrl
|
138
|
+
}, rest))]
|
139
|
+
});
|
140
|
+
};
|
141
|
+
};
|
142
|
+
|
143
|
+
exports.withWebWalletSWKeeper = withWebWalletSWKeeper;
|