Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed apy bug #779

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/web/src/hooks/vaults/useVaultApy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const useVaultApy = (vault?: IVault): IVaultApy[] => {
vault.amountsInfo?.depositedAmount ? +vault.amountsInfo.depositedAmount.tokens : 0
);

apys.push({ rewardController: controller, apy });
if (!isNaN(apy)) apys.push({ rewardController: controller, apy });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Replace unsafe isNaN with Number.isNaN

The global isNaN() function attempts type coercion which can lead to unexpected results. Use Number.isNaN() instead for strict NaN checking.

Apply this change:

-        if (!isNaN(apy)) apys.push({ rewardController: controller, apy });
+        if (!Number.isNaN(apy)) apys.push({ rewardController: controller, apy });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (!isNaN(apy)) apys.push({ rewardController: controller, apy });
if (!Number.isNaN(apy)) apys.push({ rewardController: controller, apy });
🧰 Tools
🪛 Biome (1.9.4)

[error] 59-59: isNaN is unsafe. It attempts a type coercion. Use Number.isNaN instead.

See the MDN documentation for more details.
Unsafe fix: Use Number.isNaN instead.

(lint/suspicious/noGlobalIsNan)

}

setVaultApys(apys);
Expand Down Expand Up @@ -87,7 +87,7 @@ function calculateAPY(
// Calculate the APY
// Note: vaultTokenStaked should be the total value of tokens staked in the vault
// in the same currency as tokenPrice for an accurate APY calculation
const apy = (annualRewardValue / vaultTokenStaked) * 100;
const apy = vaultTokenStaked > 0 ? (annualRewardValue / vaultTokenStaked) * 100 : 0;

return apy > 100 ? +apy.toFixed(0) : +apy.toFixed(2);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const VaultAsset = ({ vault }: VaultAssetProps) => {
const { isShowing: isShowingDepositModal, show: showDepositModal, hide: hideDepositModal } = useModal();

const vaultApy = useVaultApy(vault);
console.log(vaultApy);

const isAudit = vault.description && vault.description["project-metadata"].type === "audit";
const depositsDisabled = !vault.committeeCheckedIn || vault.depositPause;
Expand Down
Loading