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