diff --git a/app/dashboard/Home.tsx b/app/dashboard/Home.tsx
index 692e9ec..9398b3f 100644
--- a/app/dashboard/Home.tsx
+++ b/app/dashboard/Home.tsx
@@ -1,11 +1,11 @@
import { useEffect, useMemo, useState } from "react";
import Button from "@/components/ui/Button";
-import { buildSubMenuItems, evmDecimals, signDataMessage } from "@/lib/helpers";
+import { evmDecimals, signDataMessage } from "@/lib/helpers";
import { useAppDispatch, useAppSelector } from "@/store/store";
import { BalanceStateType, fetchUsdPrice, selectBalanceSlice } from "@/store/balanceSlice";
import { useAccount, useBalance, useBlockNumber, useSignMessage } from "wagmi";
import { fuse } from "wagmi/chains";
-import { checkIsActivated, fetchSponsorIdBalance, fetchSponsoredTransactions, generateSecretApiKey, selectOperatorSlice, setIsContactDetailsModalOpen, setIsRollSecretKeyModalOpen, setIsTopupAccountModalOpen, setIsWithdrawModalOpen, validateOperator, withRefreshToken } from "@/store/operatorSlice";
+import { OperatorStateType, checkIsActivated, fetchSponsorIdBalance, fetchSponsoredTransactions, fetchTokenBalances, generateSecretApiKey, selectOperatorSlice, setIsContactDetailsModalOpen, setIsRollSecretKeyModalOpen, setIsTopupAccountModalOpen, setIsWithdrawModalOpen, validateOperator, withRefreshToken } from "@/store/operatorSlice";
import TopupAccountModal from "@/components/dashboard/TopupAccountModal";
import Image from "next/image";
import copy from "@/assets/copy-black.svg";
@@ -31,7 +31,7 @@ import hide from "@/assets/hide.svg";
import { formatUnits } from "viem";
import { SignMessageVariables } from "wagmi/query";
import contactSupport from "@/assets/contact-support.svg";
-
+import { useRouter } from "next/navigation";
type CreateOperatorWalletProps = {
isValidated: boolean;
signMessage: (variables: SignMessageVariables) => void;
@@ -48,7 +48,7 @@ type OperatorAccountBalanceProps = {
chain: any;
balanceSlice: BalanceStateType;
balance: any;
- isActivated: boolean;
+ operatorSlice: OperatorStateType;
dispatch: ThunkDispatch
& Dispatch;
}
@@ -125,12 +125,12 @@ const ConnectEoaWallet = () => {
)
}
-const OperatorAccountBalance = ({ chain, balanceSlice, balance, isActivated, dispatch }: OperatorAccountBalanceProps) => {
+const OperatorAccountBalance = ({ chain, balanceSlice, balance, operatorSlice, dispatch }: OperatorAccountBalanceProps) => {
useEffect(() => {
const fiveSecondInMillisecond = 5000;
const intervalId = setInterval(() => {
- if (isActivated) {
+ if (operatorSlice.isActivated) {
dispatch(withRefreshToken(() => dispatch(fetchSponsoredTransactions())));
} else {
dispatch(withRefreshToken(() => dispatch(checkIsActivated())));
@@ -140,7 +140,13 @@ const OperatorAccountBalance = ({ chain, balanceSlice, balance, isActivated, dis
return () => {
clearInterval(intervalId);
}
- }, [dispatch, isActivated])
+ }, [dispatch, operatorSlice.isActivated])
+
+ useEffect(() => {
+ if (operatorSlice.operator.user.smartWalletAddress) {
+ dispatch(fetchTokenBalances({ address: operatorSlice.operator.user.smartWalletAddress }));
+ }
+ }, [dispatch, operatorSlice.operator.user.smartWalletAddress])
return (
@@ -160,24 +166,15 @@ const OperatorAccountBalance = ({ chain, balanceSlice, balance, isActivated, dis
-
- {(chain && chain.id === fuse.id) ?
- new Intl.NumberFormat().format(
- parseFloat(formatUnits(balance?.value ?? BigInt(0), balance?.decimals ?? evmDecimals) ?? "0")
- ) :
- 0
- } FUSE
-
- {balanceSlice.isUsdPriceLoading ?
-
:
-
+ {operatorSlice.isFetchingTokenBalances || balanceSlice.isUsdPriceLoading ?
+ :
+
${(chain && chain.id === fuse.id) ?
new Intl.NumberFormat().format(
- parseFloat((parseFloat(formatUnits(balance?.value ?? BigInt(0), balance?.decimals ?? evmDecimals) ?? "0.00") * balanceSlice.price).toString())
+ (parseFloat(balance?.formatted ?? "0") * balanceSlice.price) + operatorSlice.totalTokenBalance
) :
- "0.00"
- }
-
+ "0.00"}
+
}