1- import { useContext , useEffect , useMemo , useState , useCallback } from 'react' ;
1+ import { useContext , useEffect , useMemo , useState , useCallback } from 'react'
22
3- import { useRegisterActions , Action } from 'kbar' ;
4- import { useRouter } from 'next/router' ;
5- import Select , { OnChangeValue , components } from 'react-select' ;
3+ import { useRegisterActions , Action } from 'kbar'
4+ import { useRouter } from 'next/router'
5+ import Select , { OnChangeValue , components } from 'react-select'
66
7- import { EthereumContext } from 'context/ethereumContext' ;
7+ import { EthereumContext } from 'context/ethereumContext'
88
9- import { CURRENT_FORK } from 'util/constants' ;
10- import { toKeyIndex } from 'util/string' ;
9+ import { CURRENT_FORK } from 'util/constants'
10+ import { toKeyIndex } from 'util/string'
1111
12- import { Icon , Label } from 'components/ui' ;
12+ import { Icon , Label } from 'components/ui'
1313
14- const useBuildForkActions = ( forkOptions : any [ ] , handleForkChange : { ( option : any ) : void ; ( arg0 : any ) : any ; } ) => {
14+ interface ForkOption {
15+ label : string ;
16+ }
17+
18+
19+ type HandleForkChange = ( option : ForkOption ) => void ;
20+
21+
22+ const useBuildForkActions = (
23+ forkOptions : ForkOption [ ] ,
24+ handleForkChange : HandleForkChange
25+ ) => {
1526 return useMemo ( ( ) => {
1627 const forkIds = forkOptions . map ( ( option , index ) => toKeyIndex ( 'fork' , index ) ) ;
1728
@@ -41,36 +52,37 @@ const useBuildForkActions = (forkOptions: any[], handleForkChange: { (option: an
4152
4253
4354
55+
4456const ChainOption = ( props : any ) => {
45- const { data, children } = props ;
46- const isCurrent = data . value === CURRENT_FORK ;
57+ const { data, children } = props
58+ const isCurrent = data . value === CURRENT_FORK
4759
4860 return (
4961 < components . Option { ...props } >
5062 { children }
5163 { isCurrent && < Label > Live</ Label > }
5264 </ components . Option >
53- ) ;
54- } ;
65+ )
66+ }
5567
5668const ChainSelector = ( ) => {
57- const { forks, selectedFork, onForkChange } = useContext ( EthereumContext ) ;
58- const [ forkValue , setForkValue ] = useState ( null ) ;
59- const router = useRouter ( ) ;
69+ const { forks, selectedFork, onForkChange } = useContext ( EthereumContext )
70+ const [ forkValue , setForkValue ] = useState ( null )
71+ const router = useRouter ( )
6072
61- const forkOptions = useMemo ( ( ) => forks . map ( ( fork ) => ( { value : fork . name , label : fork . name } ) ) , [ forks ] ) ;
73+ const forkOptions = useMemo ( ( ) => forks . map ( ( fork ) => ( { value : fork . name , label : fork . name } ) ) , [ forks ] )
6274
6375 const handleForkChange = useCallback ( ( option : OnChangeValue < any , any > ) => {
64- setForkValue ( option ) ;
65- onForkChange ( option . value ) ;
76+ setForkValue ( option )
77+ onForkChange ( option . value )
6678
67- router . query . fork = option . value ;
68- router . push ( router ) ;
69- } , [ onForkChange , router ] ) ;
79+ router . query . fork = option . value
80+ router . push ( router )
81+ } , [ onForkChange , router ] )
7082
71- const actions = useBuildForkActions ( forkOptions , handleForkChange ) ;
83+ const actions = useBuildForkActions ( forkOptions , handleForkChange )
7284
73- useRegisterActions ( actions , [ actions ] ) ;
85+ useRegisterActions ( actions , [ actions ] )
7486
7587 return (
7688 < div className = "flex justify-end items-center rounded" >
@@ -89,8 +101,8 @@ const ChainSelector = () => {
89101 </ div >
90102 ) }
91103 </ div >
92- ) ;
93- } ;
104+ )
105+ }
94106
95107
96- export default ChainSelector ;
108+ export default ChainSelector
0 commit comments