Skip to content

Commit

Permalink
show dyad balance
Browse files Browse the repository at this point in the history
  • Loading branch information
shafu0x committed Oct 7, 2022
1 parent 78f3777 commit 66cfd90
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
22 changes: 21 additions & 1 deletion src/components/layout/Navbar.jsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,40 @@
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();
const { disconnect } = useDisconnect();
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 (
<div className="flex justify-around items-center mt-8 mb-8">
{/* <div>tvl: {formatUSD(getTVL())}</div> */}
<div>tvl: {formatUSD(tvl)}</div>
<div>dNFT floor: {formatUSD(dNFTfloor())}</div>
<div>dyad balance: {formatUSD(balanceOf, true)}</div>
<a className="text-5xl font-bold" href="/">
dyad
</a>
Expand Down
9 changes: 7 additions & 2 deletions src/utils/currency.js
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down

1 comment on commit 66cfd90

@vercel
Copy link

@vercel vercel bot commented on 66cfd90 Oct 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.