Skip to content

Commit

Permalink
detail optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
xieqian committed Mar 23, 2024
1 parent 0632cf1 commit 90be7cd
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 13 deletions.
3 changes: 1 addition & 2 deletions components/Header/stats/apy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export const APY = () => {
const { weightedNetLiquidity, hasNegativeNetLiquidity, assets } = useNonFarmedAssets();
const totalApy = netAPY + netLiquidityAPY;
const amount = `${totalApy.toLocaleString(undefined, APY_FORMAT)}%`;
const [showTooltip, setShowTooltip] = useState(false);
const showLabels = netAPY > 0 || netLiquidityAPY > 0;
const { averageSupplyApy, averageBorrowedApy } = useAverageAPY();
const apyLabels = [
Expand Down Expand Up @@ -56,7 +55,7 @@ export const APY = () => {
titleTooltip="Net APY = Daily Total Profit / Your Net Liquidity * 365 days"
amount={amount}
tooltip={tooltip}
labels={apyLabels}
labels={showLabels ? apyLabels : []}
/>
</div>
</div>
Expand Down
10 changes: 7 additions & 3 deletions components/Header/stats/rewards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ export const UserDailyRewards = () => {
],
[
{
value: `-${toInternationalCurrencySystem_usd(baseBorrowedUsdDaily)}`,
value: `${
baseBorrowedUsdDaily > 0
? `-${toInternationalCurrencySystem_usd(baseBorrowedUsdDaily)}`
: "$0"
}`,
text: "Borrow Interest",
},
],
Expand All @@ -74,7 +78,7 @@ export const UserDailyRewards = () => {
<IconMore allRewards={allRewards} />
</div>
}
labels={rewardsLabels}
labels={totalUsdDaily !== 0 ? rewardsLabels : []}
/>
</div>
);
Expand Down Expand Up @@ -139,7 +143,7 @@ const IncentiveMore = ({ farmSuppliedUsdDaily, farmBorrowedUsdDaily, farmNetTvlU
setShowTooltip(!showTooltip);
}}
>
<div className="w-[22px] h-[22px] rounded-3xl bg-dark-100 flex items-center justify-center z-50 cursor-pointer">
<div className="w-[22px] h-[22px] rounded-3xl bg-dark-100 flex items-center justify-center z-50 cursor-pointer mr-8">
<svg
width="12"
height="4"
Expand Down
6 changes: 2 additions & 4 deletions redux/selectors/getAccountRewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,7 @@ export const getDailyAmount = (
const asset = assets.data[tokenId];
const assetDecimals = asset.metadata.decimals + asset.config.extra_decimals;
const balance = Number(shrinkToken(assetData.balance, assetDecimals));
const dailyAmount = asset.price?.usd
? new Decimal(balance).mul(assetData.apr).div(asset.price?.usd).div(365).toNumber()
: 0;
const dailyAmount = new Decimal(balance).mul(assetData.apr).div(365).toNumber();
return { [tokenId]: dailyAmount };
});
};
Expand Down Expand Up @@ -165,7 +163,7 @@ export const getIncentiveDailyAmount = (
);
const dailyAmount =
totalBoostedShares > 0 ? (boostedShares / totalBoostedShares) * totalRewardsPerDay : 0;
result[rewardTokenId] = new Decimal(result[rewardTokenId] || 0) // TODO
result[rewardTokenId] = new Decimal(result[rewardTokenId] || 0)
.plus(dailyAmount)
.toNumber();
});
Expand Down
4 changes: 2 additions & 2 deletions redux/selectors/getAverageAPY.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export const getAverageAPY = createSelector(
const [gainBorrowed, totalBorrowed] = getGains(account.portfolio, assets, "borrowed");
const suplyGains = gainCollateral + gainSupplied;
const supplyTotals = totalCollateral + totalSupplied;
const averageSupplyApy = (suplyGains / supplyTotals) * 100;
const averageBorrowedApy = (gainBorrowed / totalBorrowed) * 100;
const averageSupplyApy = supplyTotals > 0 ? (suplyGains / supplyTotals) * 100 : 0;
const averageBorrowedApy = totalBorrowed > 0 ? (gainBorrowed / totalBorrowed) * 100 : 0;
return { averageSupplyApy, averageBorrowedApy };
},
);
2 changes: 1 addition & 1 deletion redux/selectors/getAverageBorrowedRewardApy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,6 @@ export const getAverageBorrowedRewardApy = () =>
},
[0, 0],
);
return dailyTotalBorrowProfit > 0 ? (dailyTotalBorrowProfit / totalBorrow) * 365 * 100 : 0;
return totalBorrow > 0 ? (dailyTotalBorrowProfit / totalBorrow) * 365 * 100 : 0;
},
);
5 changes: 4 additions & 1 deletion redux/selectors/getAverageNetRewardApy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,7 @@ export const getNetGains = (

return [balanceUSD * (netTvlMultiplier ? 1 : 0), apr];
})
.reduce(([gain, sum], [balance, apr]) => [gain + balance * apr, sum + balance], [0, 0]);
.reduce(
([gain, sum], [balanceUSD, apr]) => [gain + balanceUSD * apr, sum + balanceUSD],
[0, 0],
);

0 comments on commit 90be7cd

Please sign in to comment.