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

fix: rewards tab #623

Merged
merged 1 commit into from
Jan 15, 2025
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 apps/vaults-v3/components/details/RewardsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ export function RewardsTab(props: {currentVault: TYDaemonVault; hasStakingReward
toBigInt(vaultData.stakedBalanceOf.raw) === 0n ? undefined : (
<Counter
value={Number(vaultData.stakedBalanceOf.normalized)}
decimals={18}
decimals={vaultData.stakingDecimals || 18}
/>
)
}
Expand Down Expand Up @@ -538,7 +538,7 @@ export function RewardsTab(props: {currentVault: TYDaemonVault; hasStakingReward
toBigInt(vaultData.stakedEarned.raw) === 0n ? undefined : (
<Counter
value={Number(vaultData.stakedEarned.normalized)}
decimals={18}
decimals={vaultData.rewardDecimals || 18}
/>
)
}
Expand Down
21 changes: 17 additions & 4 deletions apps/vaults/hooks/useVaultStakingData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ type TStakingInfo = {
address: TAddress;
stakingToken: TAddress;
rewardsToken: TAddress;
rewardDecimals: number | undefined;
stakingDecimals: number | undefined;
totalStaked: TNormalizedBN;
stakedBalanceOf: TNormalizedBN;
stakedEarned: TNormalizedBN;
Expand All @@ -44,6 +46,8 @@ export function useVaultStakingData(props: {currentVault: TYDaemonVault}): {
address: toAddress(props.currentVault.staking.address),
stakingToken: toAddress(''),
rewardsToken: toAddress(''),
rewardDecimals: undefined,
stakingDecimals: undefined,
totalStaked: zeroNormalizedBN,
stakedBalanceOf: zeroNormalizedBN,
stakedEarned: zeroNormalizedBN,
Expand Down Expand Up @@ -273,24 +277,33 @@ export function useVaultStakingData(props: {currentVault: TYDaemonVault}): {
** view of the user's holdings in the vault: we need to know what is the reward token. This
** means we need to retrieve the token's symbol and decimals.
******************************************************************************************/
const rewardResult = await readContracts(retrieveConfig(), {
const decimalsResult = await readContracts(retrieveConfig(), {
contracts: [
{
address: rewardsToken,
abi: erc20Abi,
chainId: props.currentVault.chainID,
functionName: 'decimals'
},
{
address: stakingToken,
abi: erc20Abi,
chainId: props.currentVault.chainID,
functionName: 'decimals'
}
]
});
const rewardDecimals = decodeAsNumber(rewardResult[0]);
const rewardDecimals = decodeAsNumber(decimalsResult[0]);
const stakingDecimals = decodeAsNumber(decimalsResult[1]);

set_vaultData({
address: toAddress(props.currentVault.staking.address),
stakingToken,
rewardsToken,
totalStaked: toNormalizedBN(totalStaked, rewardDecimals),
stakedBalanceOf: toNormalizedBN(balanceOf, rewardDecimals),
rewardDecimals,
stakingDecimals,
totalStaked: toNormalizedBN(totalStaked, stakingDecimals),
stakedBalanceOf: toNormalizedBN(balanceOf, stakingDecimals),
stakedEarned: toNormalizedBN(earned, rewardDecimals),
vaultAllowance: toNormalizedBN(allowance, props.currentVault.decimals),
vaultBalanceOf: toNormalizedBN(vaultBalanceOf, props.currentVault.decimals)
Expand Down
Loading