utils#isTokensOnList TypeScript Examples

The following examples show how to use utils#isTokensOnList. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CurrencyList.tsx    From interface-v2 with GNU General Public License v3.0 4 votes vote down vote up
CurrencyList: React.FC<CurrencyListProps> = ({
  currencies,
  height,
  selectedCurrency,
  onCurrencySelect,
  otherCurrency,
  showETH,
  fixedListRef,
}) => {
  const itemData = useMemo(
    () => (showETH ? [Token.ETHER, ...currencies] : currencies),
    [currencies, showETH],
  );
  const selectedTokenList = useSelectedTokenList();
  const isOnSelectedList = isTokensOnList(selectedTokenList, itemData);

  const Row = useCallback(
    ({ data, index, style }) => {
      const currency: Token = data[index];
      const isSelected = Boolean(
        selectedCurrency && currencyEquals(selectedCurrency, currency),
      );
      const otherSelected = Boolean(
        otherCurrency && currencyEquals(otherCurrency, currency),
      );
      const handleSelect = () => onCurrencySelect(currency);
      return index < itemData.length ? (
        <CurrencyRow
          style={style}
          currency={currency}
          isSelected={isSelected}
          onSelect={handleSelect}
          otherSelected={otherSelected}
          isOnSelectedList={isOnSelectedList[index]}
        />
      ) : (
        <Box />
      );
    },
    [
      onCurrencySelect,
      otherCurrency,
      selectedCurrency,
      itemData,
      isOnSelectedList,
    ],
  );

  const itemKey = useCallback((index: number, data: typeof itemData) => {
    const currency = data[index];
    return currency instanceof Token
      ? currency.address
      : currency === ETHER
      ? 'ETHER'
      : '';
  }, []);

  return (
    <FixedSizeList
      ref={fixedListRef as any}
      height={height}
      width='100%'
      itemData={itemData}
      itemCount={itemData.length + 1}
      itemSize={56}
      itemKey={itemKey}
    >
      {Row}
    </FixedSizeList>
  );
}