Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Metroxe committed Dec 12, 2023
2 parents 87d8641 + 5c56954 commit b61c02e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
26 changes: 19 additions & 7 deletions apps/sentry-client-desktop/src/features/keys/HasKeys.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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[],
Expand All @@ -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) {
Expand Down Expand Up @@ -309,19 +312,28 @@ export function HasKeys({combinedOwners, combinedLicensesMap, statusMap, isWalle
<div className="flex items-center gap-2 font-semibold">
<XaiLogo/>
<div>
{earnedEsxaiBalance ? (
{singleWalletBalance ? (
<div className={`flex gap-1 items-end`}>
<p className="text-3xl">
{ethers.formatEther(
earnedEsxaiBalance.reduce((acc, item) => acc + item.esXaiBalance, BigInt(0))
)}
{ethers.formatEther(singleWalletBalance.esXaiBalance)}
</p>
</div>
) : (
<p className="text-3xl">
Loading...
</p>
earnedEsxaiBalance ? (
<div className={`flex gap-1 items-end`}>
<p className="text-3xl">
{ethers.formatEther(
earnedEsxaiBalance.reduce((acc, item) => acc + item.esXaiBalance, BigInt(0))
)}
</p>
</div>
) : (
<p className="text-3xl">
Loading...
</p>
)
)}

</div>

</div>
Expand Down
26 changes: 26 additions & 0 deletions apps/sentry-client-desktop/src/hooks/useGetSingleWalletBalance.ts
Original file line number Diff line number Diff line change
@@ -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,
});
}

0 comments on commit b61c02e

Please sign in to comment.