diff --git a/src/components/layout/Navbar.jsx b/src/components/layout/Navbar.jsx index c74819f..f482409 100644 --- a/src/components/layout/Navbar.jsx +++ b/src/components/layout/Navbar.jsx @@ -1,8 +1,11 @@ -import { useAccount, useConnect, useDisconnect } from "wagmi"; +import { useAccount, useConnect, useContractRead, useDisconnect } from "wagmi"; import { dNFTfloor } from "../../utils/stats"; import { formatUSD } from "../../utils/currency"; import { addressSummary } from "../../utils/address"; +import dyadABI from "../../consts/abi/dNFTABI.json"; import Button from "../Button"; +import { useState } from "react"; +import { CONTRACT_DYAD } from "../../consts/contract"; export const NavBar = ({ tvl }) => { const { address } = useAccount(); @@ -10,11 +13,28 @@ export const NavBar = ({ tvl }) => { const { connect, connectors, error, isLoading, pendingConnector } = useConnect(); + const [balanceOf, setBalanceOf] = useState(0); + + const {} = useContractRead({ + addressOrName: CONTRACT_DYAD, + contractInterface: dyadABI, + functionName: "balanceOf", + args: [address], + onSuccess: (data) => { + console.log("balanceOf", data); + setBalanceOf(parseInt(data._hex) / 10 ** 18); + }, + onError: (e) => { + console.log("balanceOf", e); + }, + }); + return (
{/*
tvl: {formatUSD(getTVL())}
*/}
tvl: {formatUSD(tvl)}
dNFT floor: {formatUSD(dNFTfloor())}
+
dyad balance: {formatUSD(balanceOf, true)}
dyad diff --git a/src/utils/currency.js b/src/utils/currency.js index fff4888..0f80bd5 100644 --- a/src/utils/currency.js +++ b/src/utils/currency.js @@ -1,11 +1,16 @@ import { useEffect, useState } from "react"; -export function formatUSD(amount) { +export function formatUSD(amount, removeDollarSign = false) { // format with commas - return amount.toLocaleString("en-US", { + amount = amount.toLocaleString("en-US", { style: "currency", currency: "USD", }); + + if (removeDollarSign) { + amount = amount.slice(1); + } + return amount; } export function useEthPrice() {