diff --git a/app/my-dashboard/_sections/financial-section/_components/budget-available-cards/budget-available-cards.tsx b/app/my-dashboard/_sections/financial-section/_components/budget-available-cards/budget-available-cards.tsx index 34e6104ec..5718f49bb 100644 --- a/app/my-dashboard/_sections/financial-section/_components/budget-available-cards/budget-available-cards.tsx +++ b/app/my-dashboard/_sections/financial-section/_components/budget-available-cards/budget-available-cards.tsx @@ -1,3 +1,5 @@ +import { useMemo } from "react"; + import { BiReactQueryAdapter } from "@/core/application/react-query-adapter/bi"; import { DetailedTotalMoneyTotalPerCurrency } from "@/core/kernel/money/money.types"; @@ -23,6 +25,41 @@ export function BudgetAvailableCards() { }, }); + const [firstStat] = data?.stats ?? []; + + const fallback = { + totalUsdEquivalent: 0, + totalPerCurrency: [], + }; + + const rewardPendingAmount = useMemo(() => { + if (firstStat) { + return { + totalUsdEquivalent: firstStat.totalRewarded.totalUsdEquivalent - firstStat.totalPaid.totalUsdEquivalent, + totalPerCurrency: firstStat.totalRewarded.totalPerCurrency + ?.map(rewarded => { + const paid = firstStat.totalPaid.totalPerCurrency?.find(p => p.currency.id === rewarded.currency.id) || { + usdEquivalent: 0, + }; + + const pendingUsdEquivalent = (rewarded.usdEquivalent || 0) - (paid.usdEquivalent || 0); + + if (pendingUsdEquivalent !== 0) { + return { + ...rewarded, + usdEquivalent: pendingUsdEquivalent, + }; + } + + return null; + }) + .filter(item => item !== null), + }; + } + + return fallback; + }, [firstStat]); + if (isLoading) { return (