import c from "classnames" ; import { useRecoilValue } from "recoil" ; import { Dictionary } from "ramda" ; import { AccAddress } from "@terra-money/terra.js" ; import format from "../scripts/format" ; import { Whitelist } from "../store/WhitelistStore" ; import { Contracts } from "../store/ContractStore" ; import Finder from "./Finder" ; import s from "./Address.module.scss" ; type Prop = { address : string ; hideIcon ? : boolean ; truncate ? : boolean ; className ? : string ; } ; const formatAccAddress = ( address , whitelist , contracts , hideIcon ? , truncate ? , className ? ) => { const token = whitelist ?. [ address ] ; const contract = contracts ?. [ address ] ; const renderAddress = truncate ? format . truncate ( address , [ 8 , 8 ] ) : address ; const isLPtoken = contract ?. name ?. includes ( "LP" ) ; const contractName = contract ? isLPtoken ? contract . name : `(${ contract . name } Contract)` : undefined ; const names = token ?. symbol || contractName ; const showProtocolName = ! token ?. symbol && ! isLPtoken && contractName ; return ( < div className = { c ( s . wrapper , className ) } > { names ? ( < > { showProtocolName && ( < span className = { s . protocol } > { contract . protocol } < /span>)} < Finder q = "address" v = { address } children = { names } / > { hideIcon ? undefined : ( < img src = { token ?. icon || contract ?. icon } alt = { token ?. symbol || contract ?. name } className = { s . icon } / > ) } < />) : (<Finder q="address" v={address} children={renderAddress}/ > ) } < /div>); } ; const formatValidatorAddress = ( address , truncate ? , className ? ) => { const renderAddress = truncate ? format . truncate ( address , [ 8 , 8 ] ) : address ; return ( < div className = { c ( s . wrapper , className ) } > < Finder q = "validator" v = { address } children = { renderAddress } / > < /div>); } ; const Address = ( { address , hideIcon , truncate , className } ) => { const whitelist = useRecoilValue ( Whitelist ) ; const contracts = useRecoilValue ( Contracts ) ; if ( AccAddress . validate ( address ) ) { return formatAccAddress ( address , whitelist , contracts , hideIcon , truncate , className ) ; } else { return formatValidatorAddress ( address , truncate , className ) ; } } ; export default Address ;