@arcblock/ux 2.10.44 → 2.10.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/DID/index.js +45 -27
- package/package.json +5 -5
- package/src/DID/index.tsx +48 -21
package/lib/DID/index.js
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { getDIDMotifInfo } from '@arcblock/did-motif';
|
|
3
|
-
import
|
|
3
|
+
import { types } from '@ocap/mcrypto';
|
|
4
|
+
import QRCode from 'qrcode.react';
|
|
4
5
|
import { Icon } from '@iconify/react';
|
|
5
|
-
import
|
|
6
|
+
import IconQrCode from '@iconify-icons/material-symbols/qr-code-rounded';
|
|
7
|
+
import { Box, Dialog, DialogContent, Typography } from '@mui/material';
|
|
6
8
|
import { useCreation, useMemoizedFn } from 'ahooks';
|
|
7
|
-
import QRCode from 'qrcode.react';
|
|
8
9
|
import React, { forwardRef, useImperativeHandle, useRef, useState } from 'react';
|
|
9
10
|
import Address from '../Address';
|
|
10
11
|
import Avatar from '../Avatar';
|
|
11
12
|
import { temp as colors } from '../Colors';
|
|
12
13
|
import { DID_PREFIX } from '../Util/constant';
|
|
13
14
|
import { translate } from '../Locale/util';
|
|
14
|
-
import { getDIDColor,
|
|
15
|
+
import { getDIDColor, isEthereumDid } from '../Util';
|
|
15
16
|
const translations = {
|
|
16
17
|
en: {
|
|
17
|
-
scanQrcode: 'Scan with DID Wallet to
|
|
18
|
+
scanQrcode: 'Scan with DID Wallet to view this {role}',
|
|
18
19
|
download: 'Download',
|
|
19
20
|
downloadTips: "Don't have DID Wallet ?"
|
|
20
21
|
},
|
|
21
22
|
zh: {
|
|
22
|
-
scanQrcode: '
|
|
23
|
+
scanQrcode: '使用 DID Wallet 扫码查看该 {role}',
|
|
23
24
|
download: '下载',
|
|
24
25
|
downloadTips: '没有 DID Wallet ?'
|
|
25
26
|
}
|
|
@@ -45,6 +46,16 @@ const isSquareMotif = roleType => {
|
|
|
45
46
|
};
|
|
46
47
|
return !roles[roleType];
|
|
47
48
|
};
|
|
49
|
+
const getRoleName = roleType => {
|
|
50
|
+
const [roleName] = Object.entries(types.RoleType).find(item => item[1] === roleType) || [];
|
|
51
|
+
if (roleName) {
|
|
52
|
+
// UpperCase first word, example:
|
|
53
|
+
// ROLE_ACCOUNT -> Account
|
|
54
|
+
// ROLE_APPLICATION -> Application
|
|
55
|
+
return roleName.toLowerCase().replace(/role_(\S)/g, (_, $1) => $1.toUpperCase());
|
|
56
|
+
}
|
|
57
|
+
return 'Address';
|
|
58
|
+
};
|
|
48
59
|
const getAvatarSize = (didMotifInfo, isEthDid, size) => {
|
|
49
60
|
if (isEthDid) {
|
|
50
61
|
return size * 0.75;
|
|
@@ -104,24 +115,19 @@ const DID = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
104
115
|
const [open, setOpen] = useState(false);
|
|
105
116
|
const isEthDid = isEthereumDid(did);
|
|
106
117
|
const didMotifInfo = isEthDid ? undefined : getDIDMotifInfo(did);
|
|
107
|
-
const
|
|
108
|
-
const prepend = [/*#__PURE__*/_jsx("span", {
|
|
118
|
+
const getPrepend = avatarSize => [/*#__PURE__*/_jsx("span", {
|
|
109
119
|
style: {
|
|
110
120
|
flex: '0 0 auto',
|
|
111
|
-
fontSize,
|
|
112
121
|
color: getFontColor(did, didMotifInfo, isEthDid)
|
|
113
122
|
},
|
|
114
123
|
children: "DID:"
|
|
115
124
|
}, "prefix-did"), /*#__PURE__*/_jsx("span", {
|
|
116
125
|
className: "did-address-text",
|
|
117
|
-
style: {
|
|
118
|
-
fontSize
|
|
119
|
-
},
|
|
120
126
|
children: "ABT:"
|
|
121
127
|
}, "prefix-abt"), showAvatar && /*#__PURE__*/_jsx(Avatar, {
|
|
122
128
|
src: "",
|
|
123
129
|
did: did,
|
|
124
|
-
size: getAvatarSize(didMotifInfo, isEthDid,
|
|
130
|
+
size: getAvatarSize(didMotifInfo, isEthDid, avatarSize || 18),
|
|
125
131
|
style: {
|
|
126
132
|
display: 'inline-flex',
|
|
127
133
|
alignItems: 'center',
|
|
@@ -179,7 +185,7 @@ const DID = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
179
185
|
content: `${DID_PREFIX}${did}`,
|
|
180
186
|
...rest,
|
|
181
187
|
ref: addressRef,
|
|
182
|
-
prepend:
|
|
188
|
+
prepend: getPrepend(rest.size),
|
|
183
189
|
append: /*#__PURE__*/_jsxs(_Fragment, {
|
|
184
190
|
children: [showQrcode ? /*#__PURE__*/_jsx(Box, {
|
|
185
191
|
id: "did-qrcode-button",
|
|
@@ -195,20 +201,31 @@ const DID = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
195
201
|
}) : null, rest.append]
|
|
196
202
|
}),
|
|
197
203
|
children: did
|
|
198
|
-
}), /*#__PURE__*/
|
|
204
|
+
}), /*#__PURE__*/_jsx(Dialog, {
|
|
199
205
|
open: open,
|
|
200
206
|
onClose: closeQrCode,
|
|
201
207
|
maxWidth: "sm",
|
|
202
|
-
|
|
208
|
+
PaperProps: {
|
|
209
|
+
sx: {
|
|
210
|
+
boxShadow: 'none',
|
|
211
|
+
borderRadius: '12px'
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
children: /*#__PURE__*/_jsxs(DialogContent, {
|
|
203
215
|
align: "center",
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
216
|
+
sx: {
|
|
217
|
+
p: 3
|
|
218
|
+
},
|
|
219
|
+
children: [/*#__PURE__*/_jsx(Typography, {
|
|
220
|
+
sx: {
|
|
221
|
+
mb: 2,
|
|
222
|
+
fontWeight: 500,
|
|
223
|
+
fontSize: 18
|
|
224
|
+
},
|
|
225
|
+
children: t('scanQrcode', {
|
|
226
|
+
role: getRoleName(didMotifInfo?.roleType)
|
|
227
|
+
})
|
|
228
|
+
}), /*#__PURE__*/_jsx(QRCode
|
|
212
229
|
// eslint-disable-next-line max-len
|
|
213
230
|
, {
|
|
214
231
|
value: `abt://abtwallet.io/i?did=${DID_PREFIX}${did}&action=didRecognize&chainID=${chainId || DEFAULT_CHAIN_ID}`,
|
|
@@ -217,14 +234,15 @@ const DID = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
217
234
|
level: "M"
|
|
218
235
|
}), /*#__PURE__*/_jsx(Box, {
|
|
219
236
|
sx: {
|
|
220
|
-
|
|
237
|
+
mt: 1.5,
|
|
221
238
|
textAlign: 'center'
|
|
222
239
|
},
|
|
223
240
|
children: /*#__PURE__*/_jsx(Address, {
|
|
224
241
|
locale: locale,
|
|
225
242
|
content: `${DID_PREFIX}${did}`,
|
|
226
|
-
prepend:
|
|
243
|
+
prepend: getPrepend(16),
|
|
227
244
|
...rest,
|
|
245
|
+
size: 16,
|
|
228
246
|
copyable: true,
|
|
229
247
|
children: did
|
|
230
248
|
})
|
|
@@ -237,7 +255,7 @@ const DID = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
237
255
|
},
|
|
238
256
|
children: downloadTips
|
|
239
257
|
})]
|
|
240
|
-
})
|
|
258
|
+
})
|
|
241
259
|
})]
|
|
242
260
|
});
|
|
243
261
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcblock/ux",
|
|
3
|
-
"version": "2.10.
|
|
3
|
+
"version": "2.10.45",
|
|
4
4
|
"description": "Common used react components for arcblock products",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -64,12 +64,12 @@
|
|
|
64
64
|
"react": ">=18.2.0",
|
|
65
65
|
"react-router-dom": ">=6.22.3"
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "f4387cd434dcdf0bab88973b014575613dcb3611",
|
|
68
68
|
"dependencies": {
|
|
69
69
|
"@arcblock/did-motif": "^1.1.13",
|
|
70
|
-
"@arcblock/icons": "^2.10.
|
|
71
|
-
"@arcblock/nft-display": "^2.10.
|
|
72
|
-
"@arcblock/react-hooks": "^2.10.
|
|
70
|
+
"@arcblock/icons": "^2.10.45",
|
|
71
|
+
"@arcblock/nft-display": "^2.10.45",
|
|
72
|
+
"@arcblock/react-hooks": "^2.10.45",
|
|
73
73
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
|
74
74
|
"@fontsource/inter": "^5.0.16",
|
|
75
75
|
"@fontsource/ubuntu-mono": "^5.0.18",
|
package/src/DID/index.tsx
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { getDIDMotifInfo } from '@arcblock/did-motif';
|
|
2
|
-
import
|
|
2
|
+
import { types } from '@ocap/mcrypto';
|
|
3
|
+
import QRCode from 'qrcode.react';
|
|
3
4
|
import { Icon } from '@iconify/react';
|
|
4
|
-
import
|
|
5
|
+
import IconQrCode from '@iconify-icons/material-symbols/qr-code-rounded';
|
|
6
|
+
import { Box, Dialog, DialogContent, Typography } from '@mui/material';
|
|
5
7
|
import { useCreation, useMemoizedFn } from 'ahooks';
|
|
6
|
-
import QRCode from 'qrcode.react';
|
|
7
8
|
import React, { forwardRef, useImperativeHandle, useRef, useState } from 'react';
|
|
8
9
|
|
|
9
10
|
import Address, { IDidAddressWrapper } from '../Address';
|
|
@@ -13,16 +14,16 @@ import { DID_PREFIX } from '../Util/constant';
|
|
|
13
14
|
|
|
14
15
|
import { HTMLDidAddressElement } from '../Address/did-address';
|
|
15
16
|
import { translate } from '../Locale/util';
|
|
16
|
-
import { getDIDColor,
|
|
17
|
+
import { getDIDColor, isEthereumDid } from '../Util';
|
|
17
18
|
|
|
18
19
|
const translations = {
|
|
19
20
|
en: {
|
|
20
|
-
scanQrcode: 'Scan with DID Wallet to
|
|
21
|
+
scanQrcode: 'Scan with DID Wallet to view this {role}',
|
|
21
22
|
download: 'Download',
|
|
22
23
|
downloadTips: "Don't have DID Wallet ?",
|
|
23
24
|
},
|
|
24
25
|
zh: {
|
|
25
|
-
scanQrcode: '
|
|
26
|
+
scanQrcode: '使用 DID Wallet 扫码查看该 {role}',
|
|
26
27
|
download: '下载',
|
|
27
28
|
downloadTips: '没有 DID Wallet ?',
|
|
28
29
|
},
|
|
@@ -70,6 +71,19 @@ const isSquareMotif = (roleType: number) => {
|
|
|
70
71
|
return !roles[roleType];
|
|
71
72
|
};
|
|
72
73
|
|
|
74
|
+
const getRoleName = (roleType: number) => {
|
|
75
|
+
const [roleName] = Object.entries(types.RoleType).find((item) => item[1] === roleType) || [];
|
|
76
|
+
|
|
77
|
+
if (roleName) {
|
|
78
|
+
// UpperCase first word, example:
|
|
79
|
+
// ROLE_ACCOUNT -> Account
|
|
80
|
+
// ROLE_APPLICATION -> Application
|
|
81
|
+
return roleName.toLowerCase().replace(/role_(\S)/g, (_, $1) => $1.toUpperCase());
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return 'Address';
|
|
85
|
+
};
|
|
86
|
+
|
|
73
87
|
const getAvatarSize = (didMotifInfo: any, isEthDid: boolean, size: number) => {
|
|
74
88
|
if (isEthDid) {
|
|
75
89
|
return size * 0.75;
|
|
@@ -139,12 +153,12 @@ const DID = forwardRef<HTMLDIDElement, IDIDPropTypes>((props, ref) => {
|
|
|
139
153
|
const [open, setOpen] = useState(false);
|
|
140
154
|
const isEthDid = isEthereumDid(did);
|
|
141
155
|
const didMotifInfo = isEthDid ? undefined : getDIDMotifInfo(did);
|
|
142
|
-
|
|
143
|
-
const
|
|
144
|
-
<span key="prefix-did" style={{ flex: '0 0 auto',
|
|
156
|
+
|
|
157
|
+
const getPrepend = (avatarSize: number) => [
|
|
158
|
+
<span key="prefix-did" style={{ flex: '0 0 auto', color: getFontColor(did, didMotifInfo, isEthDid) }}>
|
|
145
159
|
DID:
|
|
146
160
|
</span>,
|
|
147
|
-
<span key="prefix-abt" className="did-address-text"
|
|
161
|
+
<span key="prefix-abt" className="did-address-text">
|
|
148
162
|
ABT:
|
|
149
163
|
</span>,
|
|
150
164
|
showAvatar && (
|
|
@@ -152,7 +166,7 @@ const DID = forwardRef<HTMLDIDElement, IDIDPropTypes>((props, ref) => {
|
|
|
152
166
|
key="avatar"
|
|
153
167
|
src=""
|
|
154
168
|
did={did}
|
|
155
|
-
size={getAvatarSize(didMotifInfo, isEthDid,
|
|
169
|
+
size={getAvatarSize(didMotifInfo, isEthDid, avatarSize || 18)}
|
|
156
170
|
style={{ display: 'inline-flex', alignItems: 'center', marginLeft: 2, marginRight: 4 }}
|
|
157
171
|
blockiesPadding={false}
|
|
158
172
|
className="did-address-avatar"
|
|
@@ -218,7 +232,7 @@ const DID = forwardRef<HTMLDIDElement, IDIDPropTypes>((props, ref) => {
|
|
|
218
232
|
content={`${DID_PREFIX}${did}`}
|
|
219
233
|
{...rest}
|
|
220
234
|
ref={addressRef}
|
|
221
|
-
prepend={
|
|
235
|
+
prepend={getPrepend(rest.size)}
|
|
222
236
|
append={
|
|
223
237
|
<>
|
|
224
238
|
{showQrcode ? (
|
|
@@ -241,14 +255,21 @@ const DID = forwardRef<HTMLDIDElement, IDIDPropTypes>((props, ref) => {
|
|
|
241
255
|
{did}
|
|
242
256
|
</Address>
|
|
243
257
|
|
|
244
|
-
<Dialog
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
258
|
+
<Dialog
|
|
259
|
+
open={open}
|
|
260
|
+
onClose={closeQrCode}
|
|
261
|
+
maxWidth="sm"
|
|
262
|
+
PaperProps={{
|
|
263
|
+
sx: {
|
|
264
|
+
boxShadow: 'none',
|
|
265
|
+
borderRadius: '12px',
|
|
266
|
+
},
|
|
267
|
+
}}>
|
|
250
268
|
{/* @ts-ignore */}
|
|
251
|
-
<DialogContent align=
|
|
269
|
+
<DialogContent align="center" sx={{ p: 3 }}>
|
|
270
|
+
<Typography sx={{ mb: 2, fontWeight: 500, fontSize: 18 }}>
|
|
271
|
+
{t('scanQrcode', { role: getRoleName(didMotifInfo?.roleType) })}
|
|
272
|
+
</Typography>
|
|
252
273
|
<QRCode
|
|
253
274
|
// eslint-disable-next-line max-len
|
|
254
275
|
value={`abt://abtwallet.io/i?did=${DID_PREFIX}${did}&action=didRecognize&chainID=${
|
|
@@ -258,8 +279,14 @@ const DID = forwardRef<HTMLDIDElement, IDIDPropTypes>((props, ref) => {
|
|
|
258
279
|
renderAs="svg"
|
|
259
280
|
level="M"
|
|
260
281
|
/>
|
|
261
|
-
<Box sx={{
|
|
262
|
-
<Address
|
|
282
|
+
<Box sx={{ mt: 1.5, textAlign: 'center' }}>
|
|
283
|
+
<Address
|
|
284
|
+
locale={locale}
|
|
285
|
+
content={`${DID_PREFIX}${did}`}
|
|
286
|
+
prepend={getPrepend(16)}
|
|
287
|
+
{...rest}
|
|
288
|
+
size={16}
|
|
289
|
+
copyable>
|
|
263
290
|
{did}
|
|
264
291
|
</Address>
|
|
265
292
|
</Box>
|