@arcblock/ux 2.9.48 → 2.9.50
Sign up to get free protection for your applications and to get access to all the features.
- package/es/DID/index.js +110 -8
- package/lib/DID/index.js +112 -13
- package/package.json +6 -5
- package/src/DID/index.jsx +98 -5
package/es/DID/index.js
CHANGED
@@ -1,10 +1,25 @@
|
|
1
|
-
import
|
1
|
+
import { forwardRef, useState } from 'react';
|
2
2
|
import PropTypes from 'prop-types';
|
3
3
|
import { getDIDMotifInfo } from '@arcblock/did-motif';
|
4
|
+
import QRCode from 'qrcode.react';
|
5
|
+
import { Icon } from '@iconify/react';
|
6
|
+
import IconQrCode from '@iconify-icons/material-symbols/qr-code-rounded';
|
7
|
+
import { Box, Dialog, DialogContent, DialogTitle } from '@mui/material';
|
8
|
+
import { useMemoizedFn } from 'ahooks';
|
4
9
|
import Address from '../Address';
|
5
10
|
import Avatar from '../Avatar';
|
6
11
|
import { isEthereumDid, getFontSize, getDIDColor } from '../Util';
|
7
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
13
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
14
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
15
|
+
const translations = {
|
16
|
+
en: {
|
17
|
+
scanQrcode: 'Scan with DID Wallet to transfer token to here'
|
18
|
+
},
|
19
|
+
zh: {
|
20
|
+
scanQrcode: '扫描此二维码,用 DID 钱包转账'
|
21
|
+
}
|
22
|
+
};
|
8
23
|
const DIDPropTypes = {
|
9
24
|
did: PropTypes.string.isRequired,
|
10
25
|
size: PropTypes.number,
|
@@ -13,12 +28,19 @@ const DIDPropTypes = {
|
|
13
28
|
responsive: PropTypes.bool,
|
14
29
|
showCopyButtonInTooltip: PropTypes.bool,
|
15
30
|
showAvatar: PropTypes.bool,
|
31
|
+
showQrcode: PropTypes.bool,
|
16
32
|
inline: PropTypes.bool,
|
17
33
|
append: PropTypes.any,
|
18
34
|
compact: PropTypes.bool,
|
19
35
|
startChars: PropTypes.number,
|
20
36
|
endChars: PropTypes.number,
|
21
|
-
locale: PropTypes.oneOf(['en', 'zh'])
|
37
|
+
locale: PropTypes.oneOf(['en', 'zh']),
|
38
|
+
chainId: PropTypes.string
|
39
|
+
};
|
40
|
+
const DEFAULT_CHAIN_ID = 'xenon-2020-01-15';
|
41
|
+
const CHAIN_ID_MAP = {
|
42
|
+
'main.abtnetwork.io': DEFAULT_CHAIN_ID,
|
43
|
+
'beta.abtnetwork.io': 'beta'
|
22
44
|
};
|
23
45
|
const getFontColor = (did, didMotifInfo, isEthDid) => {
|
24
46
|
if (isEthDid) {
|
@@ -52,8 +74,30 @@ const getAvatarSize = (didMotifInfo, isEthDid, size) => {
|
|
52
74
|
const DID = /*#__PURE__*/forwardRef(({
|
53
75
|
did,
|
54
76
|
showAvatar,
|
77
|
+
showQrcode,
|
78
|
+
chainId,
|
79
|
+
locale,
|
55
80
|
...rest
|
56
81
|
}, ref) => {
|
82
|
+
if (!translations[locale]) {
|
83
|
+
// eslint-disable-next-line no-param-reassign
|
84
|
+
locale = 'en';
|
85
|
+
}
|
86
|
+
try {
|
87
|
+
if (!chainId) {
|
88
|
+
const chainHostUrl = window?.blocklet?.CHAIN_HOST;
|
89
|
+
if (chainHostUrl) {
|
90
|
+
const chainHost = new URL(chainHostUrl).hostname;
|
91
|
+
if (chainHost) {
|
92
|
+
// eslint-disable-next-line no-param-reassign
|
93
|
+
chainId = CHAIN_ID_MAP[chainHost];
|
94
|
+
}
|
95
|
+
}
|
96
|
+
}
|
97
|
+
} catch {
|
98
|
+
console.warn('Failed to parse chainHost');
|
99
|
+
}
|
100
|
+
const [open, setOpen] = useState(false);
|
57
101
|
const isEthDid = isEthereumDid(did);
|
58
102
|
const didMotifInfo = isEthDid ? undefined : getDIDMotifInfo(did);
|
59
103
|
const fontSize = getFontSize(rest.size);
|
@@ -82,11 +126,67 @@ const DID = /*#__PURE__*/forwardRef(({
|
|
82
126
|
blockiesPadding: false,
|
83
127
|
className: "did-address-avatar"
|
84
128
|
}, "avatar")];
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
129
|
+
const closeQrCode = useMemoizedFn(() => {
|
130
|
+
setOpen(false);
|
131
|
+
});
|
132
|
+
const openQrCode = useMemoizedFn(() => {
|
133
|
+
setOpen(true);
|
134
|
+
});
|
135
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
136
|
+
children: [/*#__PURE__*/_jsx(Address, {
|
137
|
+
ref: ref,
|
138
|
+
locale: locale,
|
139
|
+
...rest,
|
140
|
+
prepend: prepend,
|
141
|
+
append: showQrcode ? /*#__PURE__*/_jsx(Box, {
|
142
|
+
component: Icon,
|
143
|
+
icon: IconQrCode,
|
144
|
+
onClick: openQrCode,
|
145
|
+
sx: {
|
146
|
+
cursor: 'pointer',
|
147
|
+
ml: rest.copyable ? 0.5 : 0,
|
148
|
+
color: 'grey.500'
|
149
|
+
}
|
150
|
+
}) : null,
|
151
|
+
children: did
|
152
|
+
}), /*#__PURE__*/_jsxs(Dialog, {
|
153
|
+
open: open,
|
154
|
+
onClose: closeQrCode,
|
155
|
+
maxWidth: "sm",
|
156
|
+
children: [/*#__PURE__*/_jsx(DialogTitle, {
|
157
|
+
align: "center",
|
158
|
+
children: /*#__PURE__*/_jsx(Box, {
|
159
|
+
display: "inline-block",
|
160
|
+
pt: 1.5,
|
161
|
+
fontSize: {
|
162
|
+
xs: 13,
|
163
|
+
sm: 'inherit'
|
164
|
+
},
|
165
|
+
component: "span",
|
166
|
+
children: translations[locale].scanQrcode
|
167
|
+
})
|
168
|
+
}), /*#__PURE__*/_jsxs(DialogContent, {
|
169
|
+
align: "center",
|
170
|
+
children: [/*#__PURE__*/_jsx(QRCode
|
171
|
+
// eslint-disable-next-line max-len
|
172
|
+
, {
|
173
|
+
value: `abt://abtwallet.io/i?did=did:abt:${did}&action=didRecognize&chainID=${chainId || DEFAULT_CHAIN_ID}`,
|
174
|
+
size: 256,
|
175
|
+
renderAs: "svg",
|
176
|
+
level: "M"
|
177
|
+
}), /*#__PURE__*/_jsx(Box, {
|
178
|
+
sx: {
|
179
|
+
marginTop: 1,
|
180
|
+
textAlign: 'center'
|
181
|
+
},
|
182
|
+
children: /*#__PURE__*/_jsx(Address, {
|
183
|
+
copyable: true,
|
184
|
+
locale: locale,
|
185
|
+
children: did
|
186
|
+
})
|
187
|
+
})]
|
188
|
+
})]
|
189
|
+
})]
|
90
190
|
});
|
91
191
|
});
|
92
192
|
export default DID;
|
@@ -98,10 +198,12 @@ DID.defaultProps = {
|
|
98
198
|
responsive: true,
|
99
199
|
showCopyButtonInTooltip: false,
|
100
200
|
showAvatar: true,
|
201
|
+
showQrcode: false,
|
101
202
|
inline: false,
|
102
203
|
append: null,
|
103
204
|
compact: false,
|
104
205
|
startChars: 6,
|
105
206
|
endChars: 6,
|
106
|
-
locale: 'en'
|
207
|
+
locale: 'en',
|
208
|
+
chainId: ''
|
107
209
|
};
|
package/lib/DID/index.js
CHANGED
@@ -4,17 +4,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.default = void 0;
|
7
|
-
var _react =
|
7
|
+
var _react = require("react");
|
8
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
9
9
|
var _didMotif = require("@arcblock/did-motif");
|
10
|
+
var _qrcode = _interopRequireDefault(require("qrcode.react"));
|
11
|
+
var _react2 = require("@iconify/react");
|
12
|
+
var _qrCodeRounded = _interopRequireDefault(require("@iconify-icons/material-symbols/qr-code-rounded"));
|
13
|
+
var _material = require("@mui/material");
|
14
|
+
var _ahooks = require("ahooks");
|
10
15
|
var _Address = _interopRequireDefault(require("../Address"));
|
11
16
|
var _Avatar = _interopRequireDefault(require("../Avatar"));
|
12
17
|
var _Util = require("../Util");
|
13
18
|
var _jsxRuntime = require("react/jsx-runtime");
|
14
|
-
const _excluded = ["did", "showAvatar"];
|
19
|
+
const _excluded = ["did", "showAvatar", "showQrcode", "chainId", "locale"];
|
15
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
16
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
17
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
18
21
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
19
22
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
20
23
|
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; }
|
@@ -22,6 +25,14 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
22
25
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
23
26
|
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; }
|
24
27
|
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; }
|
28
|
+
const translations = {
|
29
|
+
en: {
|
30
|
+
scanQrcode: 'Scan with DID Wallet to transfer token to here'
|
31
|
+
},
|
32
|
+
zh: {
|
33
|
+
scanQrcode: '扫描此二维码,用 DID 钱包转账'
|
34
|
+
}
|
35
|
+
};
|
25
36
|
const DIDPropTypes = {
|
26
37
|
did: _propTypes.default.string.isRequired,
|
27
38
|
size: _propTypes.default.number,
|
@@ -30,12 +41,19 @@ const DIDPropTypes = {
|
|
30
41
|
responsive: _propTypes.default.bool,
|
31
42
|
showCopyButtonInTooltip: _propTypes.default.bool,
|
32
43
|
showAvatar: _propTypes.default.bool,
|
44
|
+
showQrcode: _propTypes.default.bool,
|
33
45
|
inline: _propTypes.default.bool,
|
34
46
|
append: _propTypes.default.any,
|
35
47
|
compact: _propTypes.default.bool,
|
36
48
|
startChars: _propTypes.default.number,
|
37
49
|
endChars: _propTypes.default.number,
|
38
|
-
locale: _propTypes.default.oneOf(['en', 'zh'])
|
50
|
+
locale: _propTypes.default.oneOf(['en', 'zh']),
|
51
|
+
chainId: _propTypes.default.string
|
52
|
+
};
|
53
|
+
const DEFAULT_CHAIN_ID = 'xenon-2020-01-15';
|
54
|
+
const CHAIN_ID_MAP = {
|
55
|
+
'main.abtnetwork.io': DEFAULT_CHAIN_ID,
|
56
|
+
'beta.abtnetwork.io': 'beta'
|
39
57
|
};
|
40
58
|
const getFontColor = (did, didMotifInfo, isEthDid) => {
|
41
59
|
if (isEthDid) {
|
@@ -69,9 +87,32 @@ const getAvatarSize = (didMotifInfo, isEthDid, size) => {
|
|
69
87
|
const DID = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
|
70
88
|
let {
|
71
89
|
did,
|
72
|
-
showAvatar
|
90
|
+
showAvatar,
|
91
|
+
showQrcode,
|
92
|
+
chainId,
|
93
|
+
locale
|
73
94
|
} = _ref,
|
74
95
|
rest = _objectWithoutProperties(_ref, _excluded);
|
96
|
+
if (!translations[locale]) {
|
97
|
+
// eslint-disable-next-line no-param-reassign
|
98
|
+
locale = 'en';
|
99
|
+
}
|
100
|
+
try {
|
101
|
+
if (!chainId) {
|
102
|
+
var _window, _window$blocklet;
|
103
|
+
const chainHostUrl = (_window = window) === null || _window === void 0 ? void 0 : (_window$blocklet = _window.blocklet) === null || _window$blocklet === void 0 ? void 0 : _window$blocklet.CHAIN_HOST;
|
104
|
+
if (chainHostUrl) {
|
105
|
+
const chainHost = new URL(chainHostUrl).hostname;
|
106
|
+
if (chainHost) {
|
107
|
+
// eslint-disable-next-line no-param-reassign
|
108
|
+
chainId = CHAIN_ID_MAP[chainHost];
|
109
|
+
}
|
110
|
+
}
|
111
|
+
}
|
112
|
+
} catch (_unused) {
|
113
|
+
console.warn('Failed to parse chainHost');
|
114
|
+
}
|
115
|
+
const [open, setOpen] = (0, _react.useState)(false);
|
75
116
|
const isEthDid = (0, _Util.isEthereumDid)(did);
|
76
117
|
const didMotifInfo = isEthDid ? undefined : (0, _didMotif.getDIDMotifInfo)(did);
|
77
118
|
const fontSize = (0, _Util.getFontSize)(rest.size);
|
@@ -100,12 +141,68 @@ const DID = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
|
|
100
141
|
blockiesPadding: false,
|
101
142
|
className: "did-address-avatar"
|
102
143
|
}, "avatar")];
|
103
|
-
|
104
|
-
|
105
|
-
}
|
106
|
-
|
107
|
-
|
108
|
-
})
|
144
|
+
const closeQrCode = (0, _ahooks.useMemoizedFn)(() => {
|
145
|
+
setOpen(false);
|
146
|
+
});
|
147
|
+
const openQrCode = (0, _ahooks.useMemoizedFn)(() => {
|
148
|
+
setOpen(true);
|
149
|
+
});
|
150
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
151
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Address.default, _objectSpread(_objectSpread({
|
152
|
+
ref: ref,
|
153
|
+
locale: locale
|
154
|
+
}, rest), {}, {
|
155
|
+
prepend: prepend,
|
156
|
+
append: showQrcode ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, {
|
157
|
+
component: _react2.Icon,
|
158
|
+
icon: _qrCodeRounded.default,
|
159
|
+
onClick: openQrCode,
|
160
|
+
sx: {
|
161
|
+
cursor: 'pointer',
|
162
|
+
ml: rest.copyable ? 0.5 : 0,
|
163
|
+
color: 'grey.500'
|
164
|
+
}
|
165
|
+
}) : null,
|
166
|
+
children: did
|
167
|
+
})), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Dialog, {
|
168
|
+
open: open,
|
169
|
+
onClose: closeQrCode,
|
170
|
+
maxWidth: "sm",
|
171
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.DialogTitle, {
|
172
|
+
align: "center",
|
173
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, {
|
174
|
+
display: "inline-block",
|
175
|
+
pt: 1.5,
|
176
|
+
fontSize: {
|
177
|
+
xs: 13,
|
178
|
+
sm: 'inherit'
|
179
|
+
},
|
180
|
+
component: "span",
|
181
|
+
children: translations[locale].scanQrcode
|
182
|
+
})
|
183
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.DialogContent, {
|
184
|
+
align: "center",
|
185
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_qrcode.default
|
186
|
+
// eslint-disable-next-line max-len
|
187
|
+
, {
|
188
|
+
value: "abt://abtwallet.io/i?did=did:abt:".concat(did, "&action=didRecognize&chainID=").concat(chainId || DEFAULT_CHAIN_ID),
|
189
|
+
size: 256,
|
190
|
+
renderAs: "svg",
|
191
|
+
level: "M"
|
192
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, {
|
193
|
+
sx: {
|
194
|
+
marginTop: 1,
|
195
|
+
textAlign: 'center'
|
196
|
+
},
|
197
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Address.default, {
|
198
|
+
copyable: true,
|
199
|
+
locale: locale,
|
200
|
+
children: did
|
201
|
+
})
|
202
|
+
})]
|
203
|
+
})]
|
204
|
+
})]
|
205
|
+
});
|
109
206
|
});
|
110
207
|
var _default = exports.default = DID;
|
111
208
|
DID.propTypes = DIDPropTypes;
|
@@ -116,10 +213,12 @@ DID.defaultProps = {
|
|
116
213
|
responsive: true,
|
117
214
|
showCopyButtonInTooltip: false,
|
118
215
|
showAvatar: true,
|
216
|
+
showQrcode: false,
|
119
217
|
inline: false,
|
120
218
|
append: null,
|
121
219
|
compact: false,
|
122
220
|
startChars: 6,
|
123
221
|
endChars: 6,
|
124
|
-
locale: 'en'
|
222
|
+
locale: 'en',
|
223
|
+
chainId: ''
|
125
224
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@arcblock/ux",
|
3
|
-
"version": "2.9.
|
3
|
+
"version": "2.9.50",
|
4
4
|
"description": "Common used react components for arcblock products",
|
5
5
|
"keywords": [
|
6
6
|
"react",
|
@@ -358,12 +358,12 @@
|
|
358
358
|
"@mui/material": "^5.15.0",
|
359
359
|
"react": ">=18.2.0"
|
360
360
|
},
|
361
|
-
"gitHead": "
|
361
|
+
"gitHead": "6e3bcb0e1a2a80b56a17ca055c44da8396b46273",
|
362
362
|
"dependencies": {
|
363
363
|
"@arcblock/did-motif": "^1.1.13",
|
364
|
-
"@arcblock/icons": "^2.9.
|
365
|
-
"@arcblock/nft-display": "^2.9.
|
366
|
-
"@arcblock/react-hooks": "^2.9.
|
364
|
+
"@arcblock/icons": "^2.9.50",
|
365
|
+
"@arcblock/nft-display": "^2.9.50",
|
366
|
+
"@arcblock/react-hooks": "^2.9.50",
|
367
367
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
368
368
|
"@emotion/react": "^11.10.4",
|
369
369
|
"@emotion/styled": "^11.10.4",
|
@@ -392,6 +392,7 @@
|
|
392
392
|
"mui-datatables": "^4.3.0",
|
393
393
|
"notistack": "^2.0.5",
|
394
394
|
"pako": "^2.1.0",
|
395
|
+
"qrcode.react": "^3.1.0",
|
395
396
|
"react-cookie-consent": "^6.4.1",
|
396
397
|
"react-error-boundary": "^3.1.4",
|
397
398
|
"react-helmet": "^6.1.0",
|
package/src/DID/index.jsx
CHANGED
@@ -1,12 +1,26 @@
|
|
1
|
-
import
|
1
|
+
import { forwardRef, useState } from 'react';
|
2
2
|
import PropTypes from 'prop-types';
|
3
3
|
import { getDIDMotifInfo } from '@arcblock/did-motif';
|
4
|
+
import QRCode from 'qrcode.react';
|
5
|
+
import { Icon } from '@iconify/react';
|
6
|
+
import IconQrCode from '@iconify-icons/material-symbols/qr-code-rounded';
|
7
|
+
import { Box, Dialog, DialogContent, DialogTitle } from '@mui/material';
|
8
|
+
import { useMemoizedFn } from 'ahooks';
|
4
9
|
|
5
10
|
import Address from '../Address';
|
6
11
|
import Avatar from '../Avatar';
|
7
12
|
|
8
13
|
import { isEthereumDid, getFontSize, getDIDColor } from '../Util';
|
9
14
|
|
15
|
+
const translations = {
|
16
|
+
en: {
|
17
|
+
scanQrcode: 'Scan with DID Wallet to transfer token to here',
|
18
|
+
},
|
19
|
+
zh: {
|
20
|
+
scanQrcode: '扫描此二维码,用 DID 钱包转账',
|
21
|
+
},
|
22
|
+
};
|
23
|
+
|
10
24
|
const DIDPropTypes = {
|
11
25
|
did: PropTypes.string.isRequired,
|
12
26
|
size: PropTypes.number,
|
@@ -15,12 +29,21 @@ const DIDPropTypes = {
|
|
15
29
|
responsive: PropTypes.bool,
|
16
30
|
showCopyButtonInTooltip: PropTypes.bool,
|
17
31
|
showAvatar: PropTypes.bool,
|
32
|
+
showQrcode: PropTypes.bool,
|
18
33
|
inline: PropTypes.bool,
|
19
34
|
append: PropTypes.any,
|
20
35
|
compact: PropTypes.bool,
|
21
36
|
startChars: PropTypes.number,
|
22
37
|
endChars: PropTypes.number,
|
23
38
|
locale: PropTypes.oneOf(['en', 'zh']),
|
39
|
+
chainId: PropTypes.string,
|
40
|
+
};
|
41
|
+
|
42
|
+
const DEFAULT_CHAIN_ID = 'xenon-2020-01-15';
|
43
|
+
|
44
|
+
const CHAIN_ID_MAP = {
|
45
|
+
'main.abtnetwork.io': DEFAULT_CHAIN_ID,
|
46
|
+
'beta.abtnetwork.io': 'beta',
|
24
47
|
};
|
25
48
|
|
26
49
|
const getFontColor = (did, didMotifInfo, isEthDid) => {
|
@@ -53,7 +76,27 @@ const getAvatarSize = (didMotifInfo, isEthDid, size) => {
|
|
53
76
|
/**
|
54
77
|
* @type React.ForwardRefRenderFunction<HTMLElement, typeof DIDPropTypes>
|
55
78
|
*/
|
56
|
-
const DID = forwardRef(({ did, showAvatar, ...rest }, ref) => {
|
79
|
+
const DID = forwardRef(({ did, showAvatar, showQrcode, chainId, locale, ...rest }, ref) => {
|
80
|
+
if (!translations[locale]) {
|
81
|
+
// eslint-disable-next-line no-param-reassign
|
82
|
+
locale = 'en';
|
83
|
+
}
|
84
|
+
|
85
|
+
try {
|
86
|
+
if (!chainId) {
|
87
|
+
const chainHostUrl = window?.blocklet?.CHAIN_HOST;
|
88
|
+
if (chainHostUrl) {
|
89
|
+
const chainHost = new URL(chainHostUrl).hostname;
|
90
|
+
if (chainHost) {
|
91
|
+
// eslint-disable-next-line no-param-reassign
|
92
|
+
chainId = CHAIN_ID_MAP[chainHost];
|
93
|
+
}
|
94
|
+
}
|
95
|
+
}
|
96
|
+
} catch {
|
97
|
+
console.warn('Failed to parse chainHost');
|
98
|
+
}
|
99
|
+
const [open, setOpen] = useState(false);
|
57
100
|
const isEthDid = isEthereumDid(did);
|
58
101
|
const didMotifInfo = isEthDid ? undefined : getDIDMotifInfo(did);
|
59
102
|
const fontSize = getFontSize(rest.size);
|
@@ -75,11 +118,59 @@ const DID = forwardRef(({ did, showAvatar, ...rest }, ref) => {
|
|
75
118
|
/>
|
76
119
|
),
|
77
120
|
];
|
121
|
+
const closeQrCode = useMemoizedFn(() => {
|
122
|
+
setOpen(false);
|
123
|
+
});
|
124
|
+
const openQrCode = useMemoizedFn(() => {
|
125
|
+
setOpen(true);
|
126
|
+
});
|
78
127
|
|
79
128
|
return (
|
80
|
-
|
81
|
-
|
82
|
-
|
129
|
+
<>
|
130
|
+
<Address
|
131
|
+
ref={ref}
|
132
|
+
locale={locale}
|
133
|
+
{...rest}
|
134
|
+
prepend={prepend}
|
135
|
+
append={
|
136
|
+
showQrcode ? (
|
137
|
+
<Box
|
138
|
+
component={Icon}
|
139
|
+
icon={IconQrCode}
|
140
|
+
onClick={openQrCode}
|
141
|
+
sx={{
|
142
|
+
cursor: 'pointer',
|
143
|
+
ml: rest.copyable ? 0.5 : 0,
|
144
|
+
color: 'grey.500',
|
145
|
+
}}
|
146
|
+
/>
|
147
|
+
) : null
|
148
|
+
}>
|
149
|
+
{did}
|
150
|
+
</Address>
|
151
|
+
|
152
|
+
<Dialog open={open} onClose={closeQrCode} maxWidth="sm">
|
153
|
+
<DialogTitle align="center">
|
154
|
+
<Box display="inline-block" pt={1.5} fontSize={{ xs: 13, sm: 'inherit' }} component="span">
|
155
|
+
{translations[locale].scanQrcode}
|
156
|
+
</Box>
|
157
|
+
</DialogTitle>
|
158
|
+
<DialogContent align="center">
|
159
|
+
<QRCode
|
160
|
+
// eslint-disable-next-line max-len
|
161
|
+
value={`abt://abtwallet.io/i?did=did:abt:${did}&action=didRecognize&chainID=${chainId || DEFAULT_CHAIN_ID}`}
|
162
|
+
size={256}
|
163
|
+
renderAs="svg"
|
164
|
+
level="M"
|
165
|
+
/>
|
166
|
+
<Box sx={{ marginTop: 1, textAlign: 'center' }}>
|
167
|
+
<Address copyable locale={locale}>
|
168
|
+
{did}
|
169
|
+
</Address>
|
170
|
+
</Box>
|
171
|
+
</DialogContent>
|
172
|
+
</Dialog>
|
173
|
+
</>
|
83
174
|
);
|
84
175
|
});
|
85
176
|
|
@@ -94,10 +185,12 @@ DID.defaultProps = {
|
|
94
185
|
responsive: true,
|
95
186
|
showCopyButtonInTooltip: false,
|
96
187
|
showAvatar: true,
|
188
|
+
showQrcode: false,
|
97
189
|
inline: false,
|
98
190
|
append: null,
|
99
191
|
compact: false,
|
100
192
|
startChars: 6,
|
101
193
|
endChars: 6,
|
102
194
|
locale: 'en',
|
195
|
+
chainId: '',
|
103
196
|
};
|