import { diffTokenLists, TokenList } from '@uniswap/token-lists' import React, { useCallback, useMemo } from 'react' import ReactGA from 'react-ga' import { useDispatch } from 'react-redux' import { Text } from 'rebass' import { AppDispatch } from '../../state' import { useRemovePopup } from '../../state/application/hooks' import { acceptListUpdate } from '../../state/lists/actions' import { TYPE } from '../../theme' import listVersionLabel from '../../utils/listVersionLabel' import { ButtonSecondary } from '../Button' import { AutoColumn } from '../Column' import { AutoRow } from '../Row' export default function ListUpdatePopup({ popKey, listUrl, oldList, newList, auto }: { popKey: string listUrl: string oldList: TokenList newList: TokenList auto: boolean }) { const removePopup = useRemovePopup() const removeThisPopup = useCallback(() => removePopup(popKey), [popKey, removePopup]) const dispatch = useDispatch() const handleAcceptUpdate = useCallback(() => { if (auto) return ReactGA.event({ category: 'Lists', action: 'Update List from Popup', label: listUrl }) dispatch(acceptListUpdate(listUrl)) removeThisPopup() }, [auto, dispatch, listUrl, removeThisPopup]) const { added: tokensAdded, changed: tokensChanged, removed: tokensRemoved } = useMemo(() => { return diffTokenLists(oldList.tokens, newList.tokens) }, [newList.tokens, oldList.tokens]) const numTokensChanged = useMemo( () => Object.keys(tokensChanged).reduce((memo, chainId: any) => memo + Object.keys(tokensChanged[chainId]).length, 0), [tokensChanged] ) return ( {auto ? ( The token list "{oldList.name}" has been updated to{' '} {listVersionLabel(newList.version)}. ) : ( <>
An update is available for the token list "{oldList.name}" ( {listVersionLabel(oldList.version)} to {listVersionLabel(newList.version)}).
    {tokensAdded.length > 0 ? (
  • {tokensAdded.map((token, i) => ( {token.symbol} {i === tokensAdded.length - 1 ? null : ', '} ))}{' '} added
  • ) : null} {tokensRemoved.length > 0 ? (
  • {tokensRemoved.map((token, i) => ( {token.symbol} {i === tokensRemoved.length - 1 ? null : ', '} ))}{' '} removed
  • ) : null} {numTokensChanged > 0 ?
  • {numTokensChanged} tokens updated
  • : null}
Accept update
Dismiss
)}
) }