File tree Expand file tree Collapse file tree 3 files changed +35
-6
lines changed
packages/components/src/components/Address Expand file tree Collapse file tree 3 files changed +35
-6
lines changed Original file line number Diff line number Diff line change @@ -9,15 +9,22 @@ export default {
9
9
component : Address ,
10
10
} ;
11
11
12
- export const Default = ( ) => < Address value = 'testaddress.eth' /> ;
12
+ export const Default = ( ) => < Address value = 'testaddress.eth' shortened = { false } /> ;
13
13
14
- const AddressUsingProvider = ( ) => {
14
+ export const DefaultShortenedWithENS = ( ) => < Address value = 'testaddress.eth' shortened = { true } /> ;
15
+
16
+ export const DefaultShortenedWithHexAddress = ( ) => (
17
+ < Address value = '0x7Be8076f4EA4A4AD08075C2508e481d6C946D12b' shortened = { true } />
18
+ ) ;
19
+
20
+ const AddressUsingProvider = ( { shortened } ) => {
15
21
const { connected, connectWallet, connection } = useWallet ( ) ;
16
22
17
23
return (
18
24
< >
19
25
< Address
20
26
value = { connected ? connection . ens || connection . userAddress || '' : 'Not connected' }
27
+ shortened = { shortened }
21
28
/>
22
29
< Button onClick = { connectWallet } > Connect wallet</ Button >
23
30
</ >
@@ -26,6 +33,12 @@ const AddressUsingProvider = () => {
26
33
27
34
export const WithWallet = ( ) => (
28
35
< Provider network = { NETWORKS . rinkeby } >
29
- < AddressUsingProvider />
36
+ < AddressUsingProvider shortened = { false } />
37
+ </ Provider >
38
+ ) ;
39
+
40
+ export const WithWalletShortened = ( ) => (
41
+ < Provider network = { NETWORKS . rinkeby } >
42
+ < AddressUsingProvider shortened = { true } />
30
43
</ Provider >
31
44
) ;
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ import { Address } from './Address';
5
5
6
6
describe ( 'Address' , ( ) => {
7
7
it ( 'renders without throwing' , ( ) => {
8
- const { container } = render ( < Address value = " taylorswift.eth" /> ) ;
8
+ const { container } = render ( < Address value = ' taylorswift.eth' shortened = { false } /> ) ;
9
9
expect ( container ) . toBeInTheDocument ( ) ;
10
10
} ) ;
11
11
} ) ;
Original file line number Diff line number Diff line change @@ -6,11 +6,27 @@ export interface AddressProps {
6
6
* The address to display
7
7
*/
8
8
value : string ;
9
+ /**
10
+ * boolean to shorten the address if addresses does not resolve to an ENS name
11
+ */
12
+ shortened : boolean ;
9
13
}
10
14
11
15
/**
12
16
* A component to display an address
13
17
*/
14
- export const Address : React . FC < AddressProps > = ( { value } ) => {
15
- return < Input value = { value } /> ;
18
+ export const Address : React . FC < AddressProps > = ( { value, shortened } ) => {
19
+ if ( shortened ) {
20
+ if ( value . includes ( '.eth' ) ) {
21
+ return < Input value = { value } /> ;
22
+ } else if ( value === '' || value === 'Not connected' ) {
23
+ return < Input value = { value } /> ;
24
+ } else {
25
+ let address : string ;
26
+ address = `${ value . substring ( 0 , 4 ) } ...${ value . substring ( value . length - 4 ) } ` ;
27
+ return < Input value = { address . toLowerCase ( ) } /> ;
28
+ }
29
+ } else {
30
+ return < Input value = { value } /> ;
31
+ }
16
32
} ;
You can’t perform that action at this time.
0 commit comments