Skip to content

Commit

Permalink
Update PNL to use new data. (#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
peiman3 authored Mar 4, 2025
1 parent ecb1a83 commit 1fd3588
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 24 deletions.
9 changes: 2 additions & 7 deletions liquidity/lib/StatsTotalPnl/StatsTotalPnl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ export function StatsTotalPnl() {
}
}, [rewards, rewardsTokenPrices, snxPrice]);

const totalClaimedRewardsValue = React.useMemo(
() => (claimedRewards || []).reduce((result, reward) => result.add(reward.amount_usd), wei(0)),
[claimedRewards]
);

const { data: liquidityPositions, isPending: isPendingLiquidityPositions } =
useLiquidityPositions({
accountId: params.accountId,
Expand Down Expand Up @@ -95,8 +90,8 @@ export function StatsTotalPnl() {
)
}
value={
totalDebt && totalRewardsValue && claimedRewards ? (
<PnlAmount debt={totalDebt.sub(totalRewardsValue).sub(totalClaimedRewardsValue)} />
totalDebt && totalRewardsValue && claimedRewards !== undefined ? (
<PnlAmount debt={totalDebt.sub(totalRewardsValue).sub(claimedRewards)} />
) : null
}
label={
Expand Down
21 changes: 4 additions & 17 deletions liquidity/lib/useClaimedRewards/useClaimedRewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,22 @@ import { getClaimedRewardsURL } from '@snx-v3/constants';
import { useNetwork } from '@snx-v3/useBlockchain';
import { useQuery } from '@tanstack/react-query';

export type ClaimedReward = {
ts: string;
pool_id: number;
collateral_type: string;
account_id: string;
reward_type: string;
distributor: string;
token_symbol: string;
amount: string;
price: string;
amount_usd: string;
};

export function useClaimedRewards(accountId: string | undefined) {
const { network } = useNetwork();

return useQuery({
queryKey: ['claimed-rewards', network?.id, accountId],
queryKey: ['claimed-reward', network?.id, accountId],
queryFn: async () => {
try {
const response = await fetch(getClaimedRewardsURL(network?.id) + `?accountId=${accountId}`);
const data: ClaimedReward[] = await response.json();
const totalAmountUsd: string = await response.json();

return data;
return totalAmountUsd;
} catch (error) {
return;
}
},
staleTime: 600000,
staleTime: 300_000,
enabled: Boolean(network?.id && accountId),
});
}

0 comments on commit 1fd3588

Please sign in to comment.