import React, { useState, useCallback } from "react"; import styled from "styled-components/macro"; import { TYPE, CloseIcon } from "../../theme"; import Card from "../Card"; import { AutoColumn } from "../Column"; import { RowBetween, RowFixed, AutoRow } from "../Row"; import { ArrowLeft, AlertTriangle } from "react-feather"; import useTheme from "../../hooks/useTheme"; import { transparentize } from "polished"; import { ButtonPrimary } from "../Button"; import { SectionBreak } from "../order/styleds"; import { ExternalLink } from "../../theme/components"; import ListLogo from "../ListLogo"; import { PaddedColumn, Checkbox, TextDot } from "./styleds"; 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/glists/actions"; import { CurrencyModalView } from "./CurrencySearchModal"; import { useAllLists } from "../../state/glists/hooks"; import { useWeb3 } from "../../web3"; const Wrapper = styled.div` position: relative; width: 100%; overflow: auto; `; interface ImportProps { listURL: string; list: TokenList; onDismiss: () => void; setModalView: (view: CurrencyModalView) => void; } export function ImportList({ listURL, list, setModalView, onDismiss, }: ImportProps) { const theme = useTheme(); const { library } = useWeb3(); const dispatch = useDispatch(); // 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; if (!library) return; setAddError(null); fetchList(library, listURL) .then(() => { // turn list on dispatch(enableList(listURL)); // go back to lists setModalView(CurrencyModalView.manage); }) .catch((error) => { setAddError(error.message); dispatch(removeList(listURL)); }); }, [adding, dispatch, fetchList, listURL, setModalView, library]); return ( setModalView(CurrencyModalView.manage)} /> Import List {list.logoURI && ( )} {list.name} {list.tokens.length} tokens {listURL} Import at your own risk{" "} 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. If you purchase a token from this list, you may not be able to sell it back. setConfirmed(!confirmed)} > setConfirmed(!confirmed)} /> I understand Import {addError ? ( {addError} ) : null} {/* */} ); }