Skip to content

Commit

Permalink
fix: my dashboard no rewards (#652)
Browse files Browse the repository at this point in the history
  • Loading branch information
haydencleary authored Nov 18, 2024
1 parent 1009875 commit 4538c3c
Showing 1 changed file with 41 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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 (
<div className="grid min-h-[150px] grid-cols-1 gap-2 tablet:grid-cols-2 desktop:grid-cols-3">
Expand All @@ -37,28 +74,6 @@ export function BudgetAvailableCards() {
return null;
}

const rewardPendingAmount = {
totalUsdEquivalent: data.stats[0].totalRewarded.totalUsdEquivalent - data.stats[0].totalPaid.totalUsdEquivalent,
totalPerCurrency: data.stats[0].totalRewarded.totalPerCurrency
?.map(rewarded => {
const paid = data.stats[0].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),
};

function openPanel(
panelType: PanelContributorType,
total: { totalUsdEquivalent: number; totalPerCurrency?: DetailedTotalMoneyTotalPerCurrency[] }
Expand All @@ -75,9 +90,9 @@ export function BudgetAvailableCards() {
<div className="grid min-h-[150px] grid-cols-1 gap-2 tablet:grid-cols-2 desktop:grid-cols-3">
<FinancialCardItem
title="myDashboard:budgetAvailable.rewarded.title"
total={data.stats[0].totalRewarded}
total={firstStat?.totalRewarded ?? fallback}
color="gradient"
onClick={() => openPanel("rewardedAmount", data.stats[0].totalRewarded)}
onClick={() => openPanel("rewardedAmount", firstStat?.totalRewarded)}
/>

<FinancialCardItem
Expand All @@ -89,9 +104,9 @@ export function BudgetAvailableCards() {

<FinancialCardItem
title="myDashboard:budgetAvailable.paid.title"
total={data.stats[0].totalPaid}
total={firstStat?.totalPaid ?? fallback}
color="grey"
onClick={() => openPanel("rewardPaid", data.stats[0].totalPaid)}
onClick={() => openPanel("rewardPaid", firstStat?.totalPaid)}
/>
</div>
);
Expand Down

0 comments on commit 4538c3c

Please sign in to comment.