Skip to content

Commit

Permalink
update balance component
Browse files Browse the repository at this point in the history
  • Loading branch information
arjanjohan committed Sep 21, 2024
1 parent 888c6cb commit 16f9fa3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/nextjs/app/bio/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ const OnchainBio: NextPage = () => {
<div className="flex items-center flex-col flex-grow">
<div className="flex flex-col items-center bg-base-100 border-base-300 border shadow-md shadow-secondary rounded-3xl p-6 mt-8 w-full max-w-lg">
<div className="text-xl">Your Onchain Bio</div>
{/* TODO: Add address and balance here */}
</div>
<div className="flex flex-col space-y-4 bg-base-100 border-base-300 border shadow-md shadow-secondary rounded-3xl p-6 mt-8 w-full max-w-lg">
<div className="flex items-center ml-2">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
import { useEffect, useState } from "react";
import { useWallet } from "@aptos-labs/wallet-adapter-react";
import { useAptosClient } from "~~/hooks/scaffold-move";
import { useTargetNetwork } from "~~/hooks/scaffold-move/useTargetNetwork";

export const useGetAccountNativeBalance = (address: string) => {
export const useGetAccountNativeBalance = (address?: string) => {
const [balance, setBalance] = useState<number | null>(null);
const [loading, setLoading] = useState<boolean>(true);
const [error, setError] = useState<boolean>(false);

const network = useTargetNetwork();
const aptosClient = useAptosClient(network.targetNetwork.id);
const { account } = useWallet();

useEffect(() => {
if (!address) return;
const accountAddress = address || account?.address;
if (!accountAddress) return;

const fetchBalance = async () => {
setLoading(true);
setError(false);

try {
const result = await aptosClient.getAccountAPTAmount({ accountAddress: address });
const result = await aptosClient.getAccountAPTAmount({ accountAddress });
setBalance(result);
} catch (e) {
setError(true);
Expand All @@ -28,7 +31,7 @@ export const useGetAccountNativeBalance = (address: string) => {
};

fetchBalance();
}, [address, aptosClient]);
}, [address, account, aptosClient]);

return { balance, loading, error };
};

0 comments on commit 16f9fa3

Please sign in to comment.