@ -19,34 +19,41 @@ import { Address } from "./Address";
let timeoutID : any | null = null ;
export interface ISearchItem {
symbol : string ;
name : string ;
type : "erc1155" | "erc20" | "erc721" ;
item : any ;
}
export const SearchInput = ( ) = > {
const [ value , setValue ] = useState ( "" ) ;
const [ readySubmit , setReadySubmit ] = useState ( false ) ;
const [ focus , setFocus ] = useState ( false ) ;
const [ results , setResults ] = useState < any [ ] > ( [ ] ) ;
const [ results , setResults ] = useState < ISearchItem [ ] > ( [ ] ) ;
const themeMode = useThemeMode ( ) ;
const erc20Map = useERC20Pool ( ) ;
const erc721Map = useERC721Pool ( ) ;
const erc1155Map = useERC1155Pool ( ) ;
const dataTest = [
const dataTest : ISearchItem [ ] = [
. . . Object . keys ( erc1155Map ) . map ( ( address ) = > ( {
symbol : erc1155Map [ address ] . symbol ,
name : erc1155Map [ address ] . name ,
type : "erc1155" ,
type : "erc1155" as "erc1155" ,
item : erc1155Map [ address ] ,
} ) ) ,
. . . Object . keys ( erc20Map ) . map ( ( address ) = > ( {
symbol : erc20Map [ address ] . symbol ,
name : erc20Map [ address ] . name ,
type : "erc20" ,
type : "erc20" as "erc20" ,
item : erc20Map [ address ] ,
} ) ) ,
. . . Object . keys ( erc721Map ) . map ( ( address ) = > ( {
symbol : erc721Map [ address ] . symbol ,
name : erc721Map [ address ] . name ,
type : "erc721" ,
type : "erc721" as "erc721" ,
item : erc721Map [ address ] ,
} ) ) ,
] ;
@ -60,9 +67,6 @@ export const SearchInput = () => {
const { value : newValue } = event . target ;
setValue ( newValue ) ;
clearTimeout ( timeoutID ) ;
timeoutID = setTimeout ( ( ) = > setReadySubmit ( true ) , 200 ) ;
} , [ ] ) ;
useEffect ( ( ) = > {
@ -87,7 +91,7 @@ export const SearchInput = () => {
if ( "" + + v === v && + v > 0 ) {
// is block number
history . push ( ` /block/ ${ v } ` ) ;
setValue ( '' )
setValue ( "" ) ;
return ;
}
@ -97,7 +101,7 @@ export const SearchInput = () => {
if ( v . length === 42 && /^0x[a-f0-9]+$/ . test ( v ) ) {
// address
history . push ( ` /address/ ${ v } ` ) ;
setValue ( '' )
setValue ( "" ) ;
return ;
}
@ -106,7 +110,7 @@ export const SearchInput = () => {
const ethAddress = getAddress ( v ) . basicHex ;
history . push ( ` /address/ ${ ethAddress } ` ) ;
setValue ( '' )
setValue ( "" ) ;
return ;
}
@ -130,7 +134,7 @@ export const SearchInput = () => {
return ;
}
history . push ( ` /tx/ ${ v } ` ) ;
setValue ( '' )
setValue ( "" ) ;
} )
. catch ( ) ,
getStakingTransactionByField ( [ 0 , "hash" , v ] ) . then ( ( res ) = > {
@ -139,7 +143,7 @@ export const SearchInput = () => {
}
history . push ( ` /staking-tx/ ${ v } ` ) ;
setValue ( '' )
setValue ( "" ) ;
} ) ,
] ) ;
} catch {
@ -153,14 +157,14 @@ export const SearchInput = () => {
return ;
}
history . push ( ` /block/ ${ v } ` ) ;
setValue ( '' )
setValue ( "" ) ;
} ) ,
getTransactionByField ( [ shard , "hash" , v ] ) . then ( ( res ) = > {
if ( ! res ) {
return ;
}
history . push ( ` /tx/ ${ v } ` ) ;
setValue ( '' )
setValue ( "" ) ;
} ) ,
getStakingTransactionByField ( [ shard , "hash" , v ] ) . then (
( res ) = > {
@ -169,7 +173,7 @@ export const SearchInput = () => {
}
history . push ( ` /staking-tx/ ${ v } ` ) ;
setValue ( '' )
setValue ( "" ) ;
}
) ,
] ) ;
@ -213,11 +217,25 @@ export const SearchInput = () => {
setValue ( "" ) ;
} }
>
< Box
pad = { "xxsmall" }
background = { "backgroundSuccess" }
style = { {
borderRadius : "6px" ,
marginRight : "10px" ,
paddingLeft : "6px" ,
paddingRight : "6px" ,
} }
>
< Text size = { "xsmall" } > { ` H ${ results [ index ] . type
. slice ( 1 )
. toUpperCase ( ) } ` }</Text>
< / Box >
< Text size = { "small" } style = { { paddingRight : "5px" } } >
Name { results [ index ] . name } |
{ results [ index ] . name } |
< / Text >
< Text size = { "small" } style = { { paddingRight : "5px" } } >
Symbol { results [ index ] . symbol } |
{ results [ index ] . symbol } |
< / Text >
< Address
address = { results [ index ] . item . address }
@ -244,9 +262,14 @@ export const SearchInput = () => {
setFocus ( false ) ;
} , 100 ) ;
} }
onPaste = { ( evt ) = > {
clearTimeout ( timeoutID ) ;
timeoutID = setTimeout ( ( ) = > setReadySubmit ( true ) , 200 ) ;
} }
onKeyDown = { ( e ) = > {
if ( e . keyCode === 13 ) {
onChange ( e ) ;
clearTimeout ( timeoutID ) ;
timeoutID = setTimeout ( ( ) = > setReadySubmit ( true ) , 200 ) ;
}
} }
color = "red"