Skip to content

Commit

Permalink
Merge pull request #779 from hats-finance/fix/apy
Browse files Browse the repository at this point in the history
fixed apy bug
  • Loading branch information
fonstack authored Nov 26, 2024
2 parents ccd6d14 + 7ac6e6a commit 5da7ff6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
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 });
}

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

0 comments on commit 5da7ff6

Please sign in to comment.