Skip to content

Commit

Permalink
chore: adding one extra field in the UI to facilitate the understandi…
Browse files Browse the repository at this point in the history
…ng in the demo
  • Loading branch information
pasviegas committed Jan 18, 2024
1 parent a245672 commit 4d27a9f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
23 changes: 20 additions & 3 deletions packages/app/src/app/(protected)/dashboard/lending.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { IconCopy } from '@tabler/icons';
import { format, isAfter, isBefore, parseISO } from 'date-fns';
import _ from 'lodash';
import { useEffect, useState } from 'react';
import { parseEther } from 'viem';
import { formatEther, parseEther } from 'viem';
import { waitForTransactionReceipt } from 'viem/actions';
import { Address, useAccount, useContractRead, useContractWrite, useWalletClient } from 'wagmi';
import { z } from 'zod';
Expand Down Expand Up @@ -50,6 +50,14 @@ function Vault(props: VaultProps) {
enabled: !!props.data.address && !!props.address,
});

const { data: vaultTotalAssets } = useContractRead({
address: props.data.address as Address,
abi: ERC4626__factory.abi,
functionName: 'totalAssets',
watch: true,
enabled: !!props.data.address,
});

const form = useForm({
validate: zodResolver(schema),
initialValues: {
Expand Down Expand Up @@ -131,7 +139,7 @@ function Vault(props: VaultProps) {

<Group position="apart" mt="xl" mb="xs">
<Text size="sm" color="gray">
Opens
Vault Opens
</Text>
<Text size="sm" color="gray">
{format(opens, 'MM/dd/yyyy HH:mm')}
Expand All @@ -140,13 +148,22 @@ function Vault(props: VaultProps) {

<Group position="apart" mt="md" mb="xs">
<Text size="sm" color="gray">
Closes
Vault Closes
</Text>
<Text size="sm" color="gray">
{format(closes, 'MM/dd/yyyy HH:mm')}
</Text>
</Group>

<Group position="apart" mt="md" mb="xs">
<Text size="sm" color="gray">
Vault Total Deposits
</Text>
<Text size="sm" color="gray">
{vaultTotalAssets ? formatEther(vaultTotalAssets) : '0'} USDC
</Text>
</Group>

<Group position="apart" mt="md" mb="xs">
<Text size="sm" color="gray">
Vault Balance
Expand Down
4 changes: 2 additions & 2 deletions scripts/bob/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ export const main = () => {
const mintTx = await usdc.mint(bobSigner.address, parseEther('1000'));
await mintTx.wait();

const approveTx = await usdc.approve(vaultAddress, parseEther('1'));
const approveTx = await usdc.approve(vaultAddress, parseEther('1000'));
await approveTx.wait();
console.log('Bob: gives the approval to the vault to swap it`s USDC. - OK');

// console.log('Bob: deposits his USDC in the vault.');
const vault = CredbullVault__factory.connect(vaultAddress, bobSigner);
const depositTx = await vault.deposit(parseEther('1'), bobSigner.address, { gasLimit: 10000000 });
const depositTx = await vault.deposit(parseEther('1000'), bobSigner.address, { gasLimit: 10000000 });
await depositTx.wait();
console.log('Bob: deposits his USDC in the vault. - OK');

Expand Down

0 comments on commit 4d27a9f

Please sign in to comment.