From 94a15d37a9f4873935af05d939bb43f735be80bf Mon Sep 17 00:00:00 2001 From: Chase Moran Date: Mon, 27 Dec 2021 12:59:37 -0500 Subject: [PATCH] bridge_ui: added avax nft tvl stats --- bridge_ui/src/components/Stats/NFTStats.tsx | 5 +- bridge_ui/src/hooks/useNFTTVL.ts | 51 ++++++++++++++++++++- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/bridge_ui/src/components/Stats/NFTStats.tsx b/bridge_ui/src/components/Stats/NFTStats.tsx index c7605208..663216e4 100644 --- a/bridge_ui/src/components/Stats/NFTStats.tsx +++ b/bridge_ui/src/components/Stats/NFTStats.tsx @@ -9,6 +9,7 @@ import numeral from "numeral"; import { useCallback, useEffect, useMemo, useState } from "react"; import useNFTTVL from "../../hooks/useNFTTVL"; import { + BETA_CHAINS, CHAINS_WITH_NFT_SUPPORT, getNFTBridgeAddressForChain, } from "../../utils/consts"; @@ -134,7 +135,9 @@ const NFTStats: React.FC = () => { const data = useMemo(() => { const output: any[] = []; if (nftTVL.data && !nftTVL.isFetching) { - CHAINS_WITH_NFT_SUPPORT.forEach((chain) => { + CHAINS_WITH_NFT_SUPPORT.filter( + (chain) => !BETA_CHAINS.find((x) => x === chain.id) + ).forEach((chain) => { output.push({ nfts: nftTVL?.data?.filter((x) => x.chainId === chain.id), chainName: chain.name, diff --git a/bridge_ui/src/hooks/useNFTTVL.ts b/bridge_ui/src/hooks/useNFTTVL.ts index 4082325a..cab80502 100644 --- a/bridge_ui/src/hooks/useNFTTVL.ts +++ b/bridge_ui/src/hooks/useNFTTVL.ts @@ -1,5 +1,6 @@ import { ChainId, + CHAIN_ID_AVAX, CHAIN_ID_BSC, CHAIN_ID_ETH, CHAIN_ID_POLYGON, @@ -129,6 +130,10 @@ const useNFTTVL = (): DataWrapper => { useState(false); const [polygonCovalentError, setPolygonCovalentError] = useState(""); + const [avaxCovalentData, setAvaxCovalentData] = useState(undefined); + const [avaxCovalentIsLoading, setAvaxCovalentIsLoading] = useState(false); + const [avaxCovalentError, setAvaxCovalentError] = useState(""); + const [solanaCustodyTokens, setSolanaCustodyTokens] = useState< { pubkey: PublicKey; account: AccountInfo }[] | undefined >(undefined); @@ -166,6 +171,11 @@ const useNFTTVL = (): DataWrapper => { [polygonCovalentData] ); + const avaxTVL = useMemo( + () => calcEvmTVL(avaxCovalentData, CHAIN_ID_AVAX), + [avaxCovalentData] + ); + useEffect(() => { let cancelled = false; setEthCovalentIsLoading(true); @@ -250,6 +260,34 @@ const useNFTTVL = (): DataWrapper => { ); }, []); + useEffect(() => { + let cancelled = false; + setAvaxCovalentIsLoading(true); + axios + .get( + COVALENT_GET_TOKENS_URL( + CHAIN_ID_AVAX, + getNFTBridgeAddressForChain(CHAIN_ID_AVAX), + true, + false + ) + ) + .then( + (results) => { + if (!cancelled) { + setAvaxCovalentData(results.data); + setAvaxCovalentIsLoading(false); + } + }, + (error) => { + if (!cancelled) { + setAvaxCovalentError("Unable to retrieve Polygon TVL."); + setAvaxCovalentIsLoading(false); + } + } + ); + }, []); + useEffect(() => { let cancelled = false; const connection = new Connection(SOLANA_HOST, "confirmed"); @@ -277,18 +315,26 @@ const useNFTTVL = (): DataWrapper => { }, []); return useMemo(() => { - const tvlArray = [...ethTVL, ...bscTVL, ...polygonTVL, ...solanaTVL]; + const tvlArray = [ + ...ethTVL, + ...bscTVL, + ...polygonTVL, + ...avaxTVL, + ...solanaTVL, + ]; return { isFetching: ethCovalentIsLoading || bscCovalentIsLoading || polygonCovalentIsLoading || + avaxCovalentIsLoading || solanaCustodyTokensLoading, error: ethCovalentError || bscCovalentError || polygonCovalentError || + avaxCovalentError || solanaCustodyTokensError, receivedAt: null, data: tvlArray, @@ -306,6 +352,9 @@ const useNFTTVL = (): DataWrapper => { solanaTVL, solanaCustodyTokensError, solanaCustodyTokensLoading, + avaxTVL, + avaxCovalentIsLoading, + avaxCovalentError, ]); };