import React, { useState, useCallback } from 'react' import styled from 'styled-components' import { Button, Text, Link, Flex, Checkbox, Message } from '@pancakeswap/uikit' import Card from 'components/Card' import { AutoColumn } from 'components/Layout/Column' import { RowBetween, RowFixed } from 'components/Layout/Row' import useTheme from 'hooks/useTheme' import { ListLogo } from 'components/Logo' import { TokenList } from '@uniswap/token-lists' import { useDispatch } from 'react-redux' import { AppDispatch } from 'state' import useFetchListCallback from 'hooks/useFetchListCallback' import { removeList, enableList } from 'state/lists/actions' import { useAllLists } from 'state/lists/hooks' import { useTranslation } from 'contexts/Localization' interface ImportProps { listURL: string list: TokenList onImport: () => void } const Wrapper = styled.div` position: relative; width: 100%; ` const TextDot = styled.div` height: 3px; width: 3px; background-color: ${({ theme }) => theme.colors.text}; border-radius: 50%; ` function ImportList({ listURL, list, onImport }: ImportProps) { const { theme } = useTheme() const dispatch = useDispatch() const { t } = useTranslation() // user must accept const [confirmed, setConfirmed] = useState(false) const lists = useAllLists() const fetchList = useFetchListCallback() // monitor is list is loading const adding = Boolean(lists[listURL]?.loadingRequestId) const [addError, setAddError] = useState(null) const handleAddList = useCallback(() => { if (adding) return setAddError(null) fetchList(listURL) .then(() => { dispatch(enableList(listURL)) onImport() }) .catch((error) => { setAddError(error.message) dispatch(removeList(listURL)) }) }, [adding, dispatch, fetchList, listURL, onImport]) return ( {list.logoURI && } {list.name} {list.tokens.length} tokens {listURL} {t('Import at your own risk')} {t( 'By adding this list you are implicitly trusting that the data is correct. Anyone can create a list, including creating fake versions of existing lists and lists that claim to represent projects that do not have one.', )} {typeof 'If you purchase a token from this list, you may not be able to sell it back.'} setConfirmed(!confirmed)} scale="sm" /> {t('I understand')} {addError ? ( {addError} ) : null} ) } export default ImportList