From c753d150a14c715cc280962b137f9056c202272e Mon Sep 17 00:00:00 2001 From: bartosz-lipinski <264380+bartosz-lipinski@users.noreply.github.com> Date: Thu, 3 Dec 2020 22:54:23 -0600 Subject: [PATCH] feat: add market stats --- src/components/RepayInput/index.tsx | 4 +- src/views/home/index.tsx | 64 +++++++++++++++++++++-------- src/views/home/itemStyle.less | 5 +-- 3 files changed, 52 insertions(+), 21 deletions(-) diff --git a/src/components/RepayInput/index.tsx b/src/components/RepayInput/index.tsx index f9815c1..72b9594 100644 --- a/src/components/RepayInput/index.tsx +++ b/src/components/RepayInput/index.tsx @@ -52,7 +52,7 @@ export const RepayInput = (props: { }, [collateralReserveMint]); const name = useTokenName(repayReserve?.info.liquidityMint); - const { accounts: fromAccounts, balance, balanceLamports } = useUserBalance( + const { accounts: fromAccounts } = useUserBalance( repayReserve.info.liquidityMint ); @@ -118,7 +118,6 @@ export const RepayInput = (props: { value, borrowAmount, borrowAmountLamports, - balanceLamports, type, connection, wallet, @@ -127,6 +126,7 @@ export const RepayInput = (props: { repayReserve, fromAccounts, obligationAccount, + setValue, ]); const bodyStyle: React.CSSProperties = { diff --git a/src/views/home/index.tsx b/src/views/home/index.tsx index 52955a7..b72a79f 100644 --- a/src/views/home/index.tsx +++ b/src/views/home/index.tsx @@ -1,48 +1,59 @@ import { MintInfo } from "@solana/spl-token"; +import { Card, Col, Row, Statistic } from "antd"; import React, { useEffect, useState } from "react"; import { LABELS } from "../../constants"; import { cache, ParsedAccount } from "../../contexts/accounts"; import { useMarkets } from "../../contexts/market"; import { useLendingReserves } from "../../hooks"; import { reserveMarketCap } from "../../models"; -import { formatUSD, fromLamports } from "../../utils/utils"; +import { fromLamports, wadToLamports } from "../../utils/utils"; import { LendingReserveItem } from "./item"; import "./itemStyle.less"; export const HomeView = () => { const { reserveAccounts } = useLendingReserves(); const [totalMarketSize, setTotalMarketSize] = useState(0); + const [totalBorrowed, setTotalBorrowed] = useState(0); const { marketEmitter, midPriceInUSD } = useMarkets(); useEffect(() => { - const refreshTotalMarketSize = () => { - const total = reserveAccounts.reduce((result, item) => { + const refreshTotal = () => { + let totalSize = 0; + let borrowed = 0; + + reserveAccounts.forEach((item) => { const marketCapLamports = reserveMarketCap(item.info); + const localCache = cache; - const mint = localCache.get( + const liquidityMint = localCache.get( item.info.liquidityMint.toBase58() ) as ParsedAccount; - if (!mint) { - return result; + if (!liquidityMint) { + return; } const marketCap = - fromLamports(marketCapLamports, mint?.info) * - midPriceInUSD(mint?.pubkey.toBase58()); + fromLamports(marketCapLamports, liquidityMint?.info) * + midPriceInUSD(liquidityMint?.pubkey.toBase58()); - return result + marketCap; - }, 0); + totalSize = totalSize + marketCap; - setTotalMarketSize(total); + borrowed = borrowed + fromLamports( + wadToLamports(item.info?.borrowedLiquidityWad).toNumber(), + liquidityMint.info); + }); + + setTotalMarketSize(totalSize); + setTotalBorrowed(borrowed); }; const dispose = marketEmitter.onMarket(() => { - refreshTotalMarketSize(); + refreshTotal(); }); - refreshTotalMarketSize(); + refreshTotal(); return () => { dispose(); @@ -51,9 +62,30 @@ export const HomeView = () => { return (
-

- Current market size: {formatUSD.format(totalMarketSize)} -

+ + + + + + + + + + + + +
{LABELS.TABLE_TITLE_ASSET}
diff --git a/src/views/home/itemStyle.less b/src/views/home/itemStyle.less index 74b2bff..278a44b 100644 --- a/src/views/home/itemStyle.less +++ b/src/views/home/itemStyle.less @@ -27,7 +27,6 @@ } } -.home-market-size { - text-align: right; - margin-right: 20px; +.home-info-row { + margin-bottom: 10px; } \ No newline at end of file