From b2d99ca07f5709621d1c4a4d83212bfd108c52f3 Mon Sep 17 00:00:00 2001 From: sebipap Date: Thu, 28 Sep 2023 17:12:24 -0300 Subject: [PATCH] =?UTF-8?q?=E2=9A=B0=EF=B8=8F=20remove=20unused=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/getEXA/AssetSelector.tsx | 97 ----------------------------- hooks/useSocketChains.ts | 93 --------------------------- 2 files changed, 190 deletions(-) delete mode 100644 components/getEXA/AssetSelector.tsx delete mode 100644 hooks/useSocketChains.ts diff --git a/components/getEXA/AssetSelector.tsx b/components/getEXA/AssetSelector.tsx deleted file mode 100644 index 835e7f0d0..000000000 --- a/components/getEXA/AssetSelector.tsx +++ /dev/null @@ -1,97 +0,0 @@ -import React, { memo } from 'react'; -import { useTranslation } from 'react-i18next'; - -import DropdownMenu from 'components/DropdownMenu'; -import { Asset } from 'types/Bridge'; -import { optimism } from 'wagmi/chains'; -import { Box, Skeleton, Typography } from '@mui/material'; -import Image from 'next/image'; -import useBalance from 'hooks/useBalance'; -import formatNumber from 'utils/formatNumber'; -import { useGetEXA } from 'contexts/GetEXAContext'; -import useSocketAssets from 'hooks/useSocketAssets'; - -type AssetOptionProps = { - asset?: Asset; - option?: boolean; - optionSize?: number; - selectedSize?: number; - chainId: number; -}; - -function AssetOption({ asset, option = false, optionSize = 17, selectedSize = 14, chainId }: AssetOptionProps) { - const size = option ? optionSize : selectedSize; - const balance = useBalance(asset?.symbol, asset?.address as `0x${string}`, true, chainId); - - if (!asset) { - return ; - } - - return ( - - {asset.logoURI && ( - {asset.symbol} - )} - <> - {option ? ( - <> - - - - {asset.name} - - - {asset.symbol} - - - - - {balance && Number(balance) ? formatNumber(balance) : ''} - - - ) : ( - - {asset.symbol} - - )} - - - ); -} - -function AssetSelector() { - const { t } = useTranslation(); - const { setAsset, asset, chain } = useGetEXA(); - const assets = useSocketAssets(); - - if (!assets) return null; - - return ( - } - renderOption={(o: Asset) => } - data-testid="modal-asset-selector" - /> - ); -} - -export default memo(AssetSelector); diff --git a/hooks/useSocketChains.ts b/hooks/useSocketChains.ts deleted file mode 100644 index 6022dd2c7..000000000 --- a/hooks/useSocketChains.ts +++ /dev/null @@ -1,93 +0,0 @@ -import { useState, useCallback, useEffect } from 'react'; -import { AssetBalance, NATIVE_TOKEN_ADDRESS } from 'types/Bridge'; -import { useWeb3 } from './useWeb3'; -import { socketRequest } from 'utils/socket'; -import usePrices from './usePrices'; -import useBalance from './useBalance'; -import { Hex } from 'viem'; -import VELO_ from '@exactly/protocol/deployments/optimism/VELO.json' assert { type: 'json' }; -import useVELO from './useVELO'; - -export const ETH = { - chainId: 10, - address: NATIVE_TOKEN_ADDRESS, - name: 'Ether', - symbol: 'ETH', - decimals: 18, - chainAgnosticId: null, - icon: '/img/assets/WETH.svg', - logoURI: '/img/assets/WETH.svg', - amount: 0, - usdAmount: 0, -} satisfies AssetBalance; - -const VELO = { - chainId: 10, - address: VELO_.address as Hex, - name: 'Velodrome', - symbol: 'VELO', - decimals: 18, - chainAgnosticId: null, - icon: 'https://velodrome.finance/velodrome.svg', - logoURI: 'https://velodrome.finance/velodrome.svg', - amount: null, - usdAmount: null, -} satisfies Omit & { amount: null; usdAmount: null }; - -export default (disableFetch?: boolean) => { - const [assets, setAssets] = useState([ETH]); - const { walletAddress, chain } = useWeb3(); - const prices = usePrices(); - const veloBalance = useBalance(VELO.symbol, VELO.address, true); - const { veloPrice } = useVELO(); - - const fetchAssets = useCallback(async () => { - if (!walletAddress || !process.env.NEXT_PUBLIC_SOCKET_API_KEY || disableFetch) return; - - const result = await socketRequest[]>('balances', { userAddress: walletAddress }); - - if (result.length === 0) { - return setAssets([ETH]); - } - - setAssets( - [...result, VELO] - .filter(({ chainId }) => chainId === chain.id) - .map((asset) => { - const price = prices[asset.address.toLowerCase() as Hex]; - const amount = asset.amount ?? Number(veloBalance); - return { - ...asset, - amount, - usdAmount: price ? amount * (Number(price) / 1e18) : undefined, - ...(asset.symbol === 'ETH' - ? { - name: 'Ether', - icon: '/img/assets/WETH.svg', - logoURI: '/img/assets/WETH.svg', - } - : asset.symbol === 'VELO' - ? { - usdAmount: veloPrice ? amount * veloPrice : undefined, - } - : {}), - }; - }) - .sort((a, b) => - a.usdAmount === undefined && b.usdAmount === undefined - ? a.symbol.localeCompare(b.symbol) - : a.usdAmount === undefined - ? 1 - : b.usdAmount === undefined - ? -1 - : b.usdAmount - a.usdAmount, - ), - ); - }, [chain.id, disableFetch, prices, veloBalance, veloPrice, walletAddress]); - - useEffect(() => { - fetchAssets(); - }, [fetchAssets]); - - return assets; -};