1
- import { useEffect , useMemo , useState } from " react" ;
2
- import { Chain } from " @chain-registry/v2-types" ;
3
- import { matchSorter } from " match-sorter" ;
1
+ import { useEffect , useMemo , useState } from ' react' ;
2
+ import { Chain } from ' @chain-registry/v2-types' ;
3
+ import { matchSorter } from ' match-sorter' ;
4
4
import {
5
5
Avatar ,
6
6
Box ,
@@ -10,7 +10,7 @@ import {
10
10
Text ,
11
11
ThemeProvider ,
12
12
useTheme ,
13
- } from " @interchain-ui/react" ;
13
+ } from ' @interchain-ui/react' ;
14
14
15
15
export type ChainSelectProps = {
16
16
chains : Chain [ ] ;
@@ -21,33 +21,36 @@ export type ChainSelectProps = {
21
21
export function ChainSelect ( {
22
22
chainName,
23
23
chains = [ ] ,
24
- onChange = ( ) => { } ,
24
+ onChange = ( ) => { } ,
25
25
} : ChainSelectProps ) {
26
26
const { themeClass } = useTheme ( ) ;
27
27
const [ value , setValue ] = useState < string > ( ) ;
28
- const [ input , setInput ] = useState < string > ( "" ) ;
28
+ const [ input , setInput ] = useState < string > ( '' ) ;
29
29
30
30
const cache = useMemo (
31
31
( ) =>
32
32
chains . reduce (
33
- ( cache , chain ) => ( cache [ chain . chainName ] = chain , cache ) ,
34
- { } as Record < string , Chain [ ] [ number ] > ,
33
+ ( cache , chain ) => ( ( cache [ chain . chainName ] = chain ) , cache ) ,
34
+ { } as Record < string , Chain [ ] [ number ] >
35
35
) ,
36
- [ chains ] ,
36
+ [ chains ]
37
37
) ;
38
38
39
- const options = useMemo ( ( ) =>
40
- matchSorter (
41
- chains
42
- . map ( ( chain ) => ( {
43
- logo : chain . logoURIs ?. png || chain . logoURIs ?. svg || "" ,
44
- value : chain . chainName ,
45
- label : chain . prettyName ,
46
- } ) )
47
- . filter ( ( chain ) => chain . value && chain . label ) ,
48
- input ,
49
- { keys : [ "value" , "label" ] } ,
50
- ) , [ chains , input ] ) ;
39
+ const options = useMemo (
40
+ ( ) =>
41
+ matchSorter (
42
+ chains
43
+ . map ( ( chain ) => ( {
44
+ logo : chain . logoURIs ?. png || chain . logoURIs ?. svg || '' ,
45
+ value : chain . chainName ,
46
+ label : chain . prettyName ,
47
+ } ) )
48
+ . filter ( ( chain ) => chain . value && chain . label ) ,
49
+ input ,
50
+ { keys : [ 'value' , 'label' ] }
51
+ ) ,
52
+ [ chains , input ]
53
+ ) ;
51
54
52
55
useEffect ( ( ) => {
53
56
if ( ! chainName ) setValue ( undefined ) ;
@@ -85,23 +88,23 @@ export function ChainSelect({
85
88
setValue ( name ) ;
86
89
if ( cache [ name ] ) {
87
90
onChange ( cache [ name ] . chainName ) ;
91
+ setInput ( cache [ name ] . prettyName || '' ) ;
88
92
}
89
93
}
90
94
} }
91
- inputAddonStart = { value && avatar
92
- ? (
95
+ inputAddonStart = {
96
+ value && avatar ? (
93
97
< Avatar
94
98
name = { value as string }
95
99
getInitials = { ( name ) => name [ 0 ] }
96
100
size = "xs"
97
101
src = { avatar }
98
102
fallbackMode = "bg"
99
103
attributes = { {
100
- paddingX : "$4" ,
104
+ paddingX : '$4' ,
101
105
} }
102
106
/>
103
- )
104
- : (
107
+ ) : (
105
108
< Box
106
109
display = "flex"
107
110
justifyContent = "center"
@@ -110,19 +113,20 @@ export function ChainSelect({
110
113
>
111
114
< Skeleton width = "24px" height = "24px" borderRadius = "$full" />
112
115
</ Box >
113
- ) }
116
+ )
117
+ }
114
118
styleProps = { {
115
119
width : {
116
- mobile : " 100%" ,
117
- mdMobile : " 350px" ,
120
+ mobile : ' 100%' ,
121
+ mdMobile : ' 350px' ,
118
122
} ,
119
123
} }
120
124
>
121
125
{ options . map ( ( option ) => (
122
126
< Combobox . Item key = { option . value } textValue = { option . label } >
123
127
< ChainOption
124
- logo = { option . logo ?? "" }
125
- label = { option . label ?? "" }
128
+ logo = { option . logo ?? '' }
129
+ label = { option . label ?? '' }
126
130
/>
127
131
</ Combobox . Item >
128
132
) ) }
@@ -137,14 +141,14 @@ function ChainOption({ logo, label }: { logo: string; label: string }) {
137
141
< Stack
138
142
direction = "horizontal"
139
143
space = "$4"
140
- attributes = { { alignItems : " center" } }
144
+ attributes = { { alignItems : ' center' } }
141
145
>
142
146
< Avatar
143
147
name = { label }
144
148
getInitials = { ( name ) => name [ 0 ] }
145
149
size = "xs"
146
150
src = { logo }
147
- fallbackMode = "bg "
151
+ fallbackMode = "initials "
148
152
/>
149
153
150
154
< Text fontSize = "$md" fontWeight = "$normal" color = "$text" >
0 commit comments