import { useState } from "react"; import { Info } from "@rimble/icons"; import { Box, Button, Input, Flash, Flex, Tooltip } from "rimble-ui"; import { H5, H6 } from "../layouts/LayoutComponents"; import { getNftIdentifiersFromUrl } from "../../utils"; import { baseColors, colors } from "../../themes"; import { StyledTabbedInput } from "./"; import { SearchIcon } from "./Icons"; export interface NftSearchBoxProps { onSearch(value: string, id: string): void; } export const NftSearchBox: React.FunctionComponent = (props) => { const urlParams = new URLSearchParams(window.location.search); const contract = urlParams.get("contract"); const tokenId = urlParams.get("tokenId"); const [contractAddress, setContractAddress] = useState(contract || ""); const [token, setToken] = useState(tokenId || ""); const [search, setSearch] = useState(""); const [error, setError] = useState(""); function onKeyDown(event: any) { if (event.code === "Enter") { props.onSearch(contractAddress, token); } } function onSearchChanged(val: string) { setError(""); setSearch(val); const nftIdentifiers = getNftIdentifiersFromUrl(val); setContractAddress(nftIdentifiers.contractAddress); setToken(nftIdentifiers.tokenId); setError(nftIdentifiers.error); } function onTrySearch() { if (!error) { props.onSearch(contractAddress, token); } } return ( <> onSearchChanged(event.target.value)} onKeyDown={(event: any) => onKeyDown(event)} placeholder="Enter NFT URL" required type="text" value={search} /> onTrySearch()} style={{ position: "absolute", top: 10, right: 5, zIndex: 9 }}> {error && {error}}
Or search by
NFT Contract Address
setContractAddress(event.target.value)} onKeyDown={(event: any) => onKeyDown(event)} placeholder="Enter NFT contract address" required type="text" value={contractAddress} width="100%" />
NFT Token ID
setToken(event.target.value)} onKeyDown={(event: any) => onKeyDown(event)} placeholder="Enter NFT token ID" required type="text" value={token} width="100%" mr={3} />
); };