From 1d3ae6938bfc948e50964376e3870ebb7ba3a4ba Mon Sep 17 00:00:00 2001 From: Evan Gray Date: Fri, 24 Dec 2021 01:28:13 -0500 Subject: [PATCH] bridge_ui: add avax tvl --- .../src/components/Stats/CustodyAddresses.tsx | 7 ++++ bridge_ui/src/hooks/useTVL.ts | 39 +++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/bridge_ui/src/components/Stats/CustodyAddresses.tsx b/bridge_ui/src/components/Stats/CustodyAddresses.tsx index 3235515d..cf6383b3 100644 --- a/bridge_ui/src/components/Stats/CustodyAddresses.tsx +++ b/bridge_ui/src/components/Stats/CustodyAddresses.tsx @@ -1,4 +1,5 @@ import { + CHAIN_ID_AVAX, CHAIN_ID_BSC, CHAIN_ID_ETH, CHAIN_ID_POLYGON, @@ -67,6 +68,12 @@ const CustodyAddresses: React.FC = () => { tokenAddress: getTokenBridgeAddressForChain(CHAIN_ID_POLYGON), nftAddress: getNFTBridgeAddressForChain(CHAIN_ID_POLYGON), }, + { + chainName: "Avalanche", + chainId: CHAIN_ID_AVAX, + tokenAddress: getTokenBridgeAddressForChain(CHAIN_ID_AVAX), + nftAddress: getNFTBridgeAddressForChain(CHAIN_ID_AVAX), + }, ]; }, []); diff --git a/bridge_ui/src/hooks/useTVL.ts b/bridge_ui/src/hooks/useTVL.ts index e181b173..6f8a209c 100644 --- a/bridge_ui/src/hooks/useTVL.ts +++ b/bridge_ui/src/hooks/useTVL.ts @@ -1,5 +1,6 @@ import { ChainId, + CHAIN_ID_AVAX, CHAIN_ID_BSC, CHAIN_ID_ETH, CHAIN_ID_POLYGON, @@ -19,6 +20,7 @@ import axios from "axios"; import { useEffect, useMemo, useState } from "react"; import { DataWrapper } from "../store/helpers"; import { + AVAX_TOKEN_BRIDGE_ADDRESS, BSC_TOKEN_BRIDGE_ADDRESS, CHAINS_BY_ID, COVALENT_GET_TOKENS_URL, @@ -299,6 +301,10 @@ const useTVL = (): 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); @@ -338,6 +344,10 @@ const useTVL = (): DataWrapper => { () => calcEvmTVL(polygonCovalentData, CHAIN_ID_POLYGON), [polygonCovalentData] ); + const avaxTVL = useMemo( + () => calcEvmTVL(avaxCovalentData, CHAIN_ID_AVAX), + [avaxCovalentData] + ); useEffect(() => { let cancelled = false; @@ -412,6 +422,29 @@ const useTVL = (): DataWrapper => { ); }, []); + useEffect(() => { + let cancelled = false; + setAvaxCovalentIsLoading(true); + axios + .get( + COVALENT_GET_TOKENS_URL(CHAIN_ID_AVAX, AVAX_TOKEN_BRIDGE_ADDRESS, false) + ) + .then( + (results) => { + if (!cancelled) { + setAvaxCovalentData(results.data); + setAvaxCovalentIsLoading(false); + } + }, + (error) => { + if (!cancelled) { + setAvaxCovalentError("Unable to retrieve Avax TVL."); + setAvaxCovalentIsLoading(false); + } + } + ); + }, []); + useEffect(() => { let cancelled = false; const connection = new Connection(SOLANA_HOST, "confirmed"); @@ -443,6 +476,7 @@ const useTVL = (): DataWrapper => { ...ethTVL, ...bscTVL, ...polygonTVL, + ...avaxTVL, ...solanaTVL, ...terraTVL, ]; @@ -452,12 +486,14 @@ const useTVL = (): DataWrapper => { ethCovalentIsLoading || bscCovalentIsLoading || polygonCovalentIsLoading || + avaxCovalentIsLoading || solanaCustodyTokensLoading || isTerraLoading, error: ethCovalentError || bscCovalentError || polygonCovalentError || + avaxCovalentError || solanaCustodyTokensError, receivedAt: null, data: tvlArray, @@ -470,6 +506,9 @@ const useTVL = (): DataWrapper => { polygonCovalentError, polygonCovalentIsLoading, polygonTVL, + avaxCovalentError, + avaxCovalentIsLoading, + avaxTVL, ethTVL, bscTVL, solanaTVL,