1
- import {
2
- FormControl ,
3
- FormErrorMessage ,
4
- Input ,
5
- InputGroup ,
6
- InputRightElement ,
7
- } from '@chakra-ui/react' ;
1
+ import { Box , Flex , FormControl , FormErrorMessage , Text } from '@chakra-ui/react' ;
8
2
import { CopyIcon , CheckIcon } from '@chakra-ui/icons' ;
9
3
import React , { useState , useEffect } from 'react' ;
10
4
@@ -23,38 +17,26 @@ export interface AddressProps {
23
17
shortened ?: boolean ;
24
18
}
25
19
26
- interface EventTarget {
27
- value : string ;
28
- }
29
-
30
- interface SyntheticEvent {
31
- currentTarget : EventTarget ;
32
- }
33
-
34
20
/**
35
21
* A component to display an address
36
22
*/
37
23
export const Address : React . FC < AddressProps > = ( { value, copiable = false , shortened = false } ) => {
38
24
const [ error , setError ] = useState < null | string > ( null ) ;
39
25
const [ copied , setCopied ] = useState < boolean > ( false ) ;
40
26
let feedbackTimeOut : ReturnType < typeof setTimeout > ;
41
- let displayAddress : string ;
27
+ let displayAddress : string = value ;
42
28
43
29
if ( shortened ) {
44
- if ( value . includes ( '.eth' ) ) {
45
- displayAddress = value ;
46
- } else if ( value === '' || value === 'Not connected' ) {
30
+ if ( value . includes ( '.eth' ) || value === '' || value === 'Not connected' ) {
47
31
displayAddress = value ;
48
32
} else {
49
33
displayAddress = `${ value . substring ( 0 , 4 ) } ...${ value . substring (
50
34
value . length - 4
51
35
) } `. toLowerCase ( ) ;
52
36
}
53
- } else {
54
- displayAddress = value ;
55
37
}
56
38
57
- const handleClick = async ( event : SyntheticEvent ) : Promise < void > => {
39
+ const handleClick = async ( ) : Promise < void > => {
58
40
if ( copiable && value ) {
59
41
try {
60
42
await navigator . clipboard . writeText ( value ) ;
@@ -76,20 +58,19 @@ export const Address: React.FC<AddressProps> = ({ value, copiable = false, short
76
58
77
59
return (
78
60
< FormControl isInvalid = { ! ! error } >
79
- < InputGroup >
61
+ < Flex
62
+ data-testid = 'address-container'
63
+ alignItems = 'center'
64
+ cursor = { copiable ? 'pointer' : 'initial' }
65
+ onClick = { handleClick }
66
+ >
67
+ < Text > { displayAddress } </ Text >
80
68
{ copiable && (
81
- < InputRightElement
82
- pointerEvents = 'none'
83
- children = { copied ? < CheckIcon color = 'green.500' /> : < CopyIcon color = 'gray.300' /> }
84
- />
69
+ < Box ml = 'auto' >
70
+ { copied ? < CheckIcon color = 'green.500' /> : < CopyIcon color = 'gray.300' /> }
71
+ </ Box >
85
72
) }
86
- < Input
87
- onClick = { handleClick }
88
- value = { displayAddress }
89
- cursor = { copiable ? 'pointer' : 'initial' }
90
- readOnly
91
- />
92
- </ InputGroup >
73
+ </ Flex >
93
74
< FormErrorMessage > { error } </ FormErrorMessage >
94
75
</ FormControl >
95
76
) ;
0 commit comments