import { Currency, DEV, JSBI, TokenAmount } from 'moonbeamswap' import React, { useCallback, useEffect, useState } from 'react' import { Plus } from 'react-feather' import { Text } from 'rebass' import { ButtonDropdownLight } from '../../components/Button' import { LightCard } from '../../components/Card' import { AutoColumn, ColumnCenter } from '../../components/Column' import CurrencyLogo from '../../components/CurrencyLogo' import { FindPoolTabs } from '../../components/NavigationTabs' import { MinimalPositionCard } from '../../components/PositionCard' import Row from '../../components/Row' import CurrencySearchModal from '../../components/SearchModal/CurrencySearchModal' import { PairState, usePair } from '../../data/Reserves' import { useActiveWeb3React } from '../../hooks' import { usePairAdder } from '../../state/user/hooks' import { useTokenBalance } from '../../state/wallet/hooks' import { StyledInternalLink } from '../../theme' import { currencyId } from '../../utils/currencyId' import AppBody from '../AppBody' import { Dots } from '../Pool/styleds' enum Fields { TOKEN0 = 0, TOKEN1 = 1 } export default function PoolFinder() { const { account } = useActiveWeb3React() const [showSearch, setShowSearch] = useState(false) const [activeField, setActiveField] = useState(Fields.TOKEN1) const [currency0, setCurrency0] = useState(DEV) const [currency1, setCurrency1] = useState(null) const [pairState, pair] = usePair(currency0 ?? undefined, currency1 ?? undefined) const addPair = usePairAdder() useEffect(() => { if (pair) { addPair(pair) } }, [pair, addPair]) const validPairNoLiquidity: boolean = pairState === PairState.NOT_EXISTS || Boolean( pairState === PairState.EXISTS && pair && JSBI.equal(pair.reserve0.raw, JSBI.BigInt(0)) && JSBI.equal(pair.reserve1.raw, JSBI.BigInt(0)) ) const position: TokenAmount | undefined = useTokenBalance(account ?? undefined, pair?.liquidityToken) const hasPosition = Boolean(position && JSBI.greaterThan(position.raw, JSBI.BigInt(0))) const handleCurrencySelect = useCallback( (currency: Currency) => { if (activeField === Fields.TOKEN0) { setCurrency0(currency) } else { setCurrency1(currency) } }, [activeField] ) const handleSearchDismiss = useCallback(() => { setShowSearch(false) }, [setShowSearch]) const prerequisiteMessage = ( {!account ? 'Connect to a wallet to find pools' : 'Select a token to find your liquidity.'} ) return ( { setShowSearch(true) setActiveField(Fields.TOKEN0) }} > {currency0 ? ( {currency0.symbol} ) : ( Select a Token )} { setShowSearch(true) setActiveField(Fields.TOKEN1) }} > {currency1 ? ( {currency1.symbol} ) : ( Select a Token )} {hasPosition && ( Pool Found! )} {currency0 && currency1 ? ( pairState === PairState.EXISTS ? ( hasPosition && pair ? ( ) : ( You don’t have liquidity in this pool yet. Add liquidity. ) ) : validPairNoLiquidity ? ( No pool found. Create pool. ) : pairState === PairState.INVALID ? ( Invalid pair. ) : pairState === PairState.LOADING ? ( Loading ) : null ) : ( prerequisiteMessage )} ) }