Skip to content

Commit e73dbb0

Browse files
committed
add vault shares on ui
1 parent ce0eec3 commit e73dbb0

3 files changed

Lines changed: 31 additions & 8 deletions

File tree

frontend/app/layout.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import "./globals.css";
44
const inter = Inter({ subsets: ["latin"] });
55

66
export const metadata = {
7-
title: "Create Next App",
8-
description: "Generated by create next app",
7+
title: "Torch",
8+
description: "Torch Vault",
99
};
1010

1111
export default function RootLayout({ children }) {

frontend/app/vault/page.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Button } from "@/components/ui/button"
66
import { Input } from "@/components/ui/input"
77
import {Nav} from "@/components/component/nav";
88
// import { useSearchParams } from 'next/navigation'
9-
import {deposit, withdraw, wethAllowance, wethbalance, approveWeth, getTvlOfWstheth} from "../../web3Functions/erc4626Vault"
9+
import {susdeVaultSharesOf, deposit, withdraw, wethAllowance, wethbalance, approveWeth, getTvlOfSUSDE} from "../../web3Functions/erc4626Vault"
1010
import {getConnectedWalletAddress} from "../../web3Functions/wallet"
1111
import React, { Suspense, useEffect, useState } from "react";
1212
import {ethers} from "ethers"
@@ -146,7 +146,7 @@ export default function Game() {
146146
const signer = await provider.getSigner();
147147

148148
const address = await signer.getAddress();
149-
const val = await getTvlOfWstheth(provider)
149+
const val = await getTvlOfSUSDE(provider)
150150
console.log("TVL ", val )
151151
setTVL(val)
152152
}
@@ -158,6 +158,25 @@ export default function Game() {
158158
return () => clearInterval(intervalId); // Cleanup function to clear the interval
159159
}, []);
160160

161+
const [vaultShares, setVaultShares] = React.useState("0");
162+
163+
React.useEffect(() => {
164+
const checkVaultShares = async () => {
165+
const provider = new ethers.providers.Web3Provider(window.ethereum);
166+
const signer = await provider.getSigner();
167+
168+
const address = await signer.getAddress();
169+
const shares = await susdeVaultSharesOf(provider, address);
170+
setVaultShares(shares);
171+
}
172+
173+
checkVaultShares(); // Initial check
174+
175+
const intervalId = setInterval(checkVaultShares, 3000); // Check every 3 seconds
176+
177+
return () => clearInterval(intervalId); // Cleanup
178+
}, []);
179+
161180
return (
162181
(<div className="flex flex-col min-h-[100dvh] bg-background">
163182
<Nav/>
@@ -196,6 +215,10 @@ export default function Game() {
196215
<p className="text-muted-foreground">Your Balance</p>
197216
<p className="text-2xl font-bold">{parseFloat(wethBal).toFixed(2)} sUSDe</p>
198217
</div>
218+
<div>
219+
<p className="text-muted-foreground">Your Vault Shares</p>
220+
<p className="text-2xl font-bold">{parseFloat(vaultShares).toFixed(2)} sUSDeV</p>
221+
</div>
199222
<div className="flex gap-2">
200223
<Input type="number" placeholder="Amount"
201224
value={amount}

frontend/web3Functions/erc4626Vault.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,28 +67,28 @@ export async function approveWeth(signer, toAddress, amount) {
6767

6868
/////////// GET FUNCTIONS
6969

70-
export async function getTvlOfWstheth(provider) {
70+
export async function getTvlOfSUSDE(provider) {
7171
try {
7272
// Create a new instance of the contract
7373
const contract = new ethers.Contract(ethAddress.susdeVault, erc4626vaultAbi, provider);
7474

7575
const bal = await contract.getVaultsActualBalance();
7676
return ethers.utils.formatEther(bal.toString())
7777
} catch (error) {
78-
console.error('Error getTvlOfWstheth: ', error);
78+
console.error('Error getTvlOfSUSDE: ', error);
7979
return "0"
8080
}
8181
}
8282

83-
export async function wstethVaultSharesOf(provider, address) {
83+
export async function susdeVaultSharesOf(provider, address) {
8484
try {
8585
// Create a new instance of the contract
8686
const contract = new ethers.Contract(ethAddress.susdeVault, erc4626vaultAbi, provider);
8787

8888
const bal = await contract.balanceOf(address);
8989
return ethers.utils.formatEther(bal.toString())
9090
} catch (error) {
91-
console.error('Error wstethVaultSharesOf: ', error);
91+
console.error('Error susdeVaultSharesOf: ', error);
9292
return "0"
9393
}
9494
}

0 commit comments

Comments
 (0)