1
1
import React from 'react' ;
2
2
import { Text } from '../Text/Loadable' ;
3
3
import { Link } from '../Link/Loadable' ;
4
- import { WithTranslation , withTranslation } from 'react-i18next' ;
4
+ import { WithTranslation , withTranslation , Translation } from 'react-i18next' ;
5
5
import { translations } from 'locales/i18n' ;
6
6
import styled from 'styled-components/macro' ;
7
7
import {
@@ -14,7 +14,7 @@ import {
14
14
isPosAddress ,
15
15
getUrl ,
16
16
} from 'utils' ;
17
- import { AlertTriangle , File } from '@zeit-ui/react-icons' ;
17
+ import { AlertTriangle , File , Bookmark } from '@zeit-ui/react-icons' ;
18
18
import ContractIcon from 'images/contract-icon.png' ;
19
19
import isMeIcon from 'images/me.png' ;
20
20
import InternalContractIcon from 'images/internal-contract-icon.png' ;
@@ -27,6 +27,8 @@ import {
27
27
} from 'utils/constants' ;
28
28
import { monospaceFont } from 'styles/variable' ;
29
29
import SDK from 'js-conflux-sdk/dist/js-conflux-sdk.umd.min.js' ;
30
+ import { useGlobalData } from 'utils/hooks/useGlobal' ;
31
+ import { LOCALSTORAGE_KEYS_MAP } from 'utils/constants' ;
30
32
31
33
interface Props {
32
34
value : string ; // address value
@@ -37,10 +39,10 @@ interface Props {
37
39
link ?: boolean ; // add link to address, default true
38
40
isMe ?: boolean ; // when `address === portal selected address`, set isMe to true to add special tag, default false
39
41
suffixAddressSize ?: number ; // suffix address size, default is 8
40
- prefixFloat ?: boolean ; // prefix icon float or take up space, default false
41
42
showIcon ?: boolean ; // whether show contract icon, default true
42
43
verify ?: boolean ; // show verified contract icon or unverified contract icon
43
44
isEspaceAddress ?: boolean ; // check the address if is a eSpace hex address, if yes, link to https://evm.confluxscan.net/address/{hex_address}
45
+ showLabeled ?: boolean ;
44
46
}
45
47
46
48
const defaultPCMaxWidth = 138 ;
@@ -51,6 +53,32 @@ const defaultPCSuffixAddressSize =
51
53
const defaultPCSuffixPosAddressSize = 10 ;
52
54
const defaultMobileSuffixAddressSize = 4 ;
53
55
56
+ const getAddressLabelInfo = label => {
57
+ if ( label ) {
58
+ return {
59
+ label,
60
+ icon : (
61
+ < IconWrapper >
62
+ < Text
63
+ span
64
+ hoverValue = {
65
+ < Translation >
66
+ { t => t ( translations . profile . tip . label ) }
67
+ </ Translation >
68
+ }
69
+ >
70
+ < Bookmark color = "var(--theme-color-gray2)" size = { 16 } />
71
+ </ Text >
72
+ </ IconWrapper >
73
+ ) ,
74
+ } ;
75
+ }
76
+ return {
77
+ label : '' ,
78
+ icon : null ,
79
+ } ;
80
+ } ;
81
+
54
82
// ≈ 2.5 ms
55
83
const RenderAddress = ( {
56
84
cfxAddress,
@@ -66,10 +94,11 @@ const RenderAddress = ({
66
94
prefix = null ,
67
95
suffix = null ,
68
96
type = 'pow' ,
97
+ addressLabel = '' ,
69
98
} : any ) => {
70
99
const aftercontent =
71
100
type === 'pow'
72
- ? cfxAddress && ! isFull && ! alias
101
+ ? cfxAddress && ! isFull && ! addressLabel && ! alias
73
102
? cfxAddress . substr ( - suffixSize )
74
103
: ''
75
104
: '' ;
@@ -101,7 +130,7 @@ const RenderAddress = ({
101
130
alias = { alias }
102
131
aftercontent = { aftercontent }
103
132
>
104
- < span > { content || alias || cfxAddress } </ span >
133
+ < span > { content || addressLabel || alias || cfxAddress } </ span >
105
134
</ LinkWrapper >
106
135
) ;
107
136
}
@@ -113,15 +142,42 @@ const RenderAddress = ({
113
142
alias = { alias }
114
143
aftercontent = { aftercontent }
115
144
>
116
- < span > { content || alias || cfxAddress } </ span >
145
+ < span > { content || addressLabel || alias || cfxAddress } </ span >
117
146
</ PlainWrapper >
118
147
) ;
119
148
}
120
149
121
150
return (
122
151
< AddressWrapper >
123
152
{ prefix }
124
- < Text span hoverValue = { hoverValue || cfxAddress } >
153
+ < Text
154
+ span
155
+ hoverValue = {
156
+ < >
157
+ { addressLabel ? (
158
+ < >
159
+ < span >
160
+ < Translation >
161
+ { t => t ( translations . profile . address . myNameTag ) }
162
+ </ Translation >
163
+ </ span >
164
+ { addressLabel }
165
+ </ >
166
+ ) : null }
167
+ < div > { hoverValue || cfxAddress } </ div >
168
+ { addressLabel && alias ? (
169
+ < >
170
+ < span >
171
+ < Translation >
172
+ { t => t ( translations . profile . address . publicNameTag ) }
173
+ </ Translation >
174
+ </ span >
175
+ { alias }
176
+ </ >
177
+ ) : null }
178
+ </ >
179
+ }
180
+ >
125
181
{ text }
126
182
</ Text >
127
183
{ suffix }
@@ -142,12 +198,14 @@ export const AddressContainer = withTranslation()(
142
198
link = true ,
143
199
isMe = false ,
144
200
suffixAddressSize,
145
- prefixFloat = false ,
146
201
showIcon = true ,
147
202
t,
148
203
verify = false ,
149
204
isEspaceAddress,
205
+ showLabeled = true ,
150
206
} : Props & WithTranslation ) => {
207
+ const [ globalData = { } ] = useGlobalData ( ) ;
208
+
151
209
const suffixSize =
152
210
suffixAddressSize ||
153
211
( window . innerWidth <= sizes . m
@@ -161,18 +219,33 @@ export const AddressContainer = withTranslation()(
161
219
) ;
162
220
163
221
if ( contractCreated ) {
222
+ let addressLabel : React . ReactNode = null ,
223
+ addressLabelIcon : React . ReactNode = null ;
224
+
225
+ if ( showLabeled ) {
226
+ const { label, icon } = getAddressLabelInfo (
227
+ globalData [ LOCALSTORAGE_KEYS_MAP . addressLabel ] [
228
+ formatAddress ( contractCreated )
229
+ ] ,
230
+ ) ;
231
+
232
+ addressLabel = label ;
233
+ addressLabelIcon = icon ;
234
+ }
235
+
164
236
return RenderAddress ( {
165
237
cfxAddress : '' ,
166
- alias,
238
+ alias : alias || txtContractCreation ,
239
+ addressLabel,
167
240
hoverValue : formatAddress ( contractCreated ) ,
168
241
hrefAddress : formatAddress ( contractCreated ) ,
169
- content : txtContractCreation ,
170
242
link,
171
243
isFull,
172
244
maxWidth : 160 ,
173
245
suffixSize,
174
246
prefix : (
175
- < IconWrapper className = { prefixFloat ? 'float' : '' } >
247
+ < IconWrapper >
248
+ { addressLabelIcon }
176
249
< Text span hoverValue = { txtContractCreation } >
177
250
< img src = { ContractIcon } alt = { txtContractCreation } />
178
251
</ Text >
@@ -216,7 +289,7 @@ export const AddressContainer = withTranslation()(
216
289
maxWidth,
217
290
suffixSize : 0 ,
218
291
prefix : (
219
- < IconWrapper className = { prefixFloat ? 'float' : '' } >
292
+ < IconWrapper >
220
293
< Text span hoverValue = { tip } >
221
294
< File size = { 16 } color = "#17B38A" />
222
295
</ Text >
@@ -239,7 +312,7 @@ export const AddressContainer = withTranslation()(
239
312
suffixSize,
240
313
style : { color : '#e00909' } ,
241
314
prefix : (
242
- < IconWrapper className = { prefixFloat ? 'float' : '' } >
315
+ < IconWrapper >
243
316
< Text span hoverValue = { tip } >
244
317
< AlertTriangle size = { 16 } color = "#e00909" />
245
318
</ Text >
@@ -259,6 +332,19 @@ export const AddressContainer = withTranslation()(
259
332
alias = t ( translations . general . zeroAddress ) ;
260
333
}
261
334
335
+ let addressLabel : React . ReactNode = null ,
336
+ addressLabelIcon : React . ReactNode = null ;
337
+ if ( showLabeled ) {
338
+ const { label, icon } = getAddressLabelInfo (
339
+ globalData [ LOCALSTORAGE_KEYS_MAP . addressLabel ] [
340
+ formatAddress ( cfxAddress )
341
+ ] ,
342
+ ) ;
343
+
344
+ addressLabel = label ;
345
+ addressLabelIcon = icon ;
346
+ }
347
+
262
348
if ( isContractAddress ( cfxAddress ) || isInnerContractAddress ( cfxAddress ) ) {
263
349
const typeText = t (
264
350
isInnerContractAddress ( cfxAddress )
@@ -270,16 +356,14 @@ export const AddressContainer = withTranslation()(
270
356
return RenderAddress ( {
271
357
cfxAddress,
272
358
alias,
359
+ addressLabel,
273
360
link,
274
361
isFull,
275
362
maxWidth,
276
363
suffixSize,
277
364
prefix : showIcon ? (
278
- < IconWrapper
279
- className = { `${ isFull ? 'icon' : '' } ${
280
- prefixFloat ? 'float' : ''
281
- } `}
282
- >
365
+ < IconWrapper className = { `${ isFull ? 'icon' : '' } ` } >
366
+ { addressLabelIcon }
283
367
< Text span hoverValue = { typeText } >
284
368
< ImgWrapper >
285
369
{ isInnerContractAddress ( cfxAddress ) ? (
@@ -307,12 +391,13 @@ export const AddressContainer = withTranslation()(
307
391
return RenderAddress ( {
308
392
cfxAddress,
309
393
alias,
394
+ addressLabel,
310
395
link,
311
396
isFull,
312
397
maxWidth,
313
398
suffixSize,
314
399
suffix : (
315
- < IconWrapper className = { prefixFloat ? 'float' : '' } >
400
+ < IconWrapper >
316
401
< img
317
402
src = { isMeIcon }
318
403
alt = "is me"
@@ -330,10 +415,12 @@ export const AddressContainer = withTranslation()(
330
415
return RenderAddress ( {
331
416
cfxAddress,
332
417
alias,
418
+ addressLabel,
333
419
link,
334
420
isFull,
335
421
maxWidth,
336
422
suffixSize,
423
+ prefix : addressLabelIcon ,
337
424
} ) ;
338
425
} ,
339
426
) ,
@@ -349,7 +436,6 @@ export const PoSAddressContainer = withTranslation()(
349
436
link = true ,
350
437
isMe = false ,
351
438
suffixAddressSize,
352
- prefixFloat = false ,
353
439
t,
354
440
} : Props & WithTranslation ) => {
355
441
const suffixSize =
@@ -378,7 +464,7 @@ export const PoSAddressContainer = withTranslation()(
378
464
suffixSize,
379
465
style : { color : '#e00909' } ,
380
466
prefix : (
381
- < IconWrapper className = { prefixFloat ? 'float' : '' } >
467
+ < IconWrapper >
382
468
< Text span hoverValue = { tip } >
383
469
< AlertTriangle size = { 16 } color = "#e00909" />
384
470
</ Text >
@@ -403,7 +489,7 @@ export const PoSAddressContainer = withTranslation()(
403
489
maxWidth,
404
490
suffixSize,
405
491
suffix : (
406
- < IconWrapper className = { prefixFloat ? 'float' : '' } >
492
+ < IconWrapper >
407
493
< img
408
494
src = { isMeIcon }
409
495
alt = "is me"
@@ -458,10 +544,6 @@ const IconWrapper = styled.span`
458
544
margin-right: 2px;
459
545
flex-shrink: 0;
460
546
461
- &.float {
462
- margin-left: -18px;
463
- }
464
-
465
547
svg {
466
548
vertical-align: bottom;
467
549
margin-bottom: 4px;
@@ -487,7 +569,7 @@ const addressStyle = (props: any) => `
487
569
display: inline-flex !important;
488
570
flex-wrap: nowrap;
489
571
max-width: ${
490
- props . maxwidth || ( props . alias ? 180 : defaultPCMaxWidth )
572
+ props . maxwidth || ( props . alias ? 160 : defaultPCMaxWidth )
491
573
} px !important;
492
574
outline: none;
493
575
@@ -500,7 +582,7 @@ const addressStyle = (props: any) => `
500
582
501
583
${ media . m } {
502
584
max-width: ${
503
- props . maxwidth || ( props . alias ? 160 : defaultMobileMaxWidth )
585
+ props . maxwidth || ( props . alias ? 140 : defaultMobileMaxWidth )
504
586
} px !important;
505
587
}
506
588
0 commit comments