diff --git a/apps/sentry-client-desktop/src/features/keys/HasKeys.tsx b/apps/sentry-client-desktop/src/features/keys/HasKeys.tsx index 220a92f54..d5c6f78cc 100644 --- a/apps/sentry-client-desktop/src/features/keys/HasKeys.tsx +++ b/apps/sentry-client-desktop/src/features/keys/HasKeys.tsx @@ -22,6 +22,7 @@ import {accruingStateAtom} from "@/hooks/useAccruingInfo"; import {ethers} from "ethers"; import {BiLoaderAlt} from "react-icons/bi"; import {useGetWalletBalance} from "@/hooks/useGetWalletBalance"; +import {useGetSingleWalletBalance} from "@/hooks/useGetSingleWalletBalance"; interface HasKeysProps { combinedOwners: string[], @@ -43,6 +44,8 @@ export function HasKeys({combinedOwners, combinedLicensesMap, statusMap, isWalle const {isLoading: isOperatorLoading, publicKey: operatorAddress} = useOperator(); const {startRuntime, sentryRunning} = useOperatorRuntime(); const {data: earnedEsxaiBalance} = useGetWalletBalance(combinedOwners); + const {data: singleWalletBalance} = useGetSingleWalletBalance(selectedWallet); + function startAssignment() { if (!isOperatorLoading) { @@ -309,19 +312,28 @@ export function HasKeys({combinedOwners, combinedLicensesMap, statusMap, isWalle
- {earnedEsxaiBalance ? ( + {singleWalletBalance ? (

- {ethers.formatEther( - earnedEsxaiBalance.reduce((acc, item) => acc + item.esXaiBalance, BigInt(0)) - )} + {ethers.formatEther(singleWalletBalance.esXaiBalance)}

) : ( -

- Loading... -

+ earnedEsxaiBalance ? ( +
+

+ {ethers.formatEther( + earnedEsxaiBalance.reduce((acc, item) => acc + item.esXaiBalance, BigInt(0)) + )} +

+
+ ) : ( +

+ Loading... +

+ ) )} +
diff --git a/apps/sentry-client-desktop/src/hooks/useGetSingleWalletBalance.ts b/apps/sentry-client-desktop/src/hooks/useGetSingleWalletBalance.ts new file mode 100644 index 000000000..84956312b --- /dev/null +++ b/apps/sentry-client-desktop/src/hooks/useGetSingleWalletBalance.ts @@ -0,0 +1,26 @@ +import { useQuery } from "react-query"; +import { getBalances } from "@sentry/core"; + +export function useGetSingleWalletBalance(address: string | null) { + return useQuery({ + queryKey: ["get-single-balance", address], + queryFn: async () => { + if (!address) { + // Handle the case where the address is not provided (or is null) + return null; + } + + const result = await getBalances([address], (address, xaiBalance, esXaiBalance) => { + return { + address, + xaiBalance, + esXaiBalance, + }; + }); + + return result ? result[0] : null; // Return the first result (single wallet) or null if no result + }, + staleTime: Infinity, + cacheTime: Infinity, + }); +}