Skip to content

Commit

Permalink
fix: fees calculations, styles fix
Browse files Browse the repository at this point in the history
  • Loading branch information
damnnou committed Mar 14, 2024
1 parent b2e4c7f commit 120fac5
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 32 deletions.
39 changes: 30 additions & 9 deletions src/components/farming/ActiveFarming/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,19 @@ const ActiveFarming = ({
<CardInfo
additional={
!isSameReward
? `${formattedRewardEarned.toFixed(2)} ${
farming.rewardToken.symbol
} + ${formattedBonusRewardEarned.toFixed(
2
)} ${farming.bonusRewardToken?.symbol}`
? `${
formattedRewardEarned.toFixed(2) ===
'0.00'
? '<0.01'
: formattedRewardEarned.toFixed(2)
} ${farming.rewardToken.symbol} + ${
formattedBonusRewardEarned.toFixed(2) ===
'0.00'
? '<0.01'
: formattedBonusRewardEarned.toFixed(
2
)
} ${farming.bonusRewardToken?.symbol}`
: ''
}
className="w-full"
Expand Down Expand Up @@ -202,7 +210,14 @@ const ActiveFarming = ({
currency={rewardTokenCurrency}
/>
<p>
{`${rewardRatePerDay.toFixed(2)} ${
{`${
rewardRatePerDay.toFixed(2) ===
'0.00'
? '<0.01'
: rewardRatePerDay.toFixed(
2
)
} ${
farming.rewardToken.symbol
} / day`}
</p>
Expand All @@ -217,9 +232,15 @@ const ActiveFarming = ({
}
/>
<p>
{`${bonusRewardRatePerDay.toFixed(
2
)} ${
{`${
bonusRewardRatePerDay.toFixed(
2
) === '0.00'
? '<0.01'
: bonusRewardRatePerDay.toFixed(
2
)
} ${
farming.bonusRewardToken
?.symbol
} / day`}
Expand Down
12 changes: 1 addition & 11 deletions src/hooks/farming/useActiveFarming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export function useActiveFarming({
if (!rewardToken) return;
if (!bonusRewardToken) return;
if (!activeFarming || !rewardToken.token) {
console.log('Active farming not found');
console.debug('Active farming not found');
setFarmingInfo(null);
return;
}
Expand All @@ -78,16 +78,6 @@ export function useActiveFarming({
});
}, [farmings, rewardToken, bonusRewardToken, poolInfo, activeFarming]);

useEffect(() => {
if (!farmingInfo) return;
console.log('Active Farming - ', farmingInfo);
}, [farmingInfo]);

useEffect(() => {
if (!deposits) return;
console.log('Positions - ', deposits.deposits);
}, [deposits]);

return {
farmingInfo,
deposits,
Expand Down
7 changes: 1 addition & 6 deletions src/hooks/farming/useClosedFarmings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
SinglePoolQuery,
useEternalFarmingsQuery,
} from '@/graphql/generated/graphql';
import { useEffect, useMemo, useState } from 'react';
import { useMemo, useState } from 'react';
import { Address } from 'viem';
import { useClients } from '../graphql/useClients';

Expand Down Expand Up @@ -37,11 +37,6 @@ export function useClosedFarmings({
}
}, [initialData]);

useEffect(() => {
if (!closedFarmings) return;
console.log('closedFarmings', closedFarmings);
}, [closedFarmings]);

return {
closedFarmings,
isLoading,
Expand Down
13 changes: 7 additions & 6 deletions src/pages/Pool/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const PoolPage = () => {
});

const { data: bundles } = useNativePriceQuery();
const nativePrice = bundles?.bundles[0].maticPriceUSD;

const { farmingInfo, deposits, isFarmingLoading, areDepositsLoading } =
useActiveFarming({
Expand Down Expand Up @@ -95,7 +96,6 @@ const PoolPage = () => {

useEffect(() => {
async function getPositionsAPRs() {
const nativePrice = bundles?.bundles[0].maticPriceUSD;
const aprs = await Promise.all(
filteredPositions.map(({ position }) =>
getPositionAPR(
Expand All @@ -120,16 +120,17 @@ const PoolPage = () => {
getPositionsAPRs();
}, [filteredPositions, poolInfo, poolId, poolFeeData, bundles]);

// should be reusable
const formatLiquidityUSD = (position: Position) => {
if (!poolInfo?.pool) return 0;

const amount0USD =
Number(position.amount0.toSignificant()) *
Number(poolInfo.pool.token1Price);
(Number(poolInfo.pool.token0.derivedMatic) *
(Number(nativePrice) || 0));
const amount1USD =
Number(position.amount1.toSignificant()) *
Number(poolInfo.pool.token0Price);
(Number(poolInfo.pool.token1.derivedMatic) *
(Number(nativePrice) || 0));

return amount0USD + amount1USD;
};
Expand All @@ -139,11 +140,11 @@ const PoolPage = () => {

const fees0USD = positionsFees[idx][0]
? Number(positionsFees[idx][0].toSignificant()) *
Number(poolInfo.pool.token0Price)
(Number(poolInfo.pool.token0.derivedMatic) * Number(nativePrice))
: 0;
const fees1USD = positionsFees[idx][1]
? Number(positionsFees[idx][1].toSignificant()) *
Number(poolInfo.pool.token1Price)
(Number(poolInfo.pool.token1.derivedMatic) * Number(nativePrice))
: 0;

return fees0USD + fees1USD;
Expand Down

0 comments on commit 120fac5

Please sign in to comment.