bridge_ui: added avax nft tvl stats

This commit is contained in:
Chase Moran 2021-12-27 12:59:37 -05:00 committed by Evan Gray
parent 1d3ae6938b
commit 94a15d37a9
2 changed files with 54 additions and 2 deletions

View File

@ -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<any> = () => {
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,

View File

@ -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<NFTTVL[]> => {
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<ParsedAccountData> }[] | undefined
>(undefined);
@ -166,6 +171,11 @@ const useNFTTVL = (): DataWrapper<NFTTVL[]> => {
[polygonCovalentData]
);
const avaxTVL = useMemo(
() => calcEvmTVL(avaxCovalentData, CHAIN_ID_AVAX),
[avaxCovalentData]
);
useEffect(() => {
let cancelled = false;
setEthCovalentIsLoading(true);
@ -250,6 +260,34 @@ const useNFTTVL = (): DataWrapper<NFTTVL[]> => {
);
}, []);
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<NFTTVL[]> => {
}, []);
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<NFTTVL[]> => {
solanaTVL,
solanaCustodyTokensError,
solanaCustodyTokensLoading,
avaxTVL,
avaxCovalentIsLoading,
avaxCovalentError,
]);
};