Skip to content

Commit

Permalink
fix displaying rewards
Browse files Browse the repository at this point in the history
  • Loading branch information
DonFungible committed Feb 25, 2025
1 parent e100da4 commit 37be2f5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
6 changes: 1 addition & 5 deletions src/app/delegations/[delegatorEvmAddr]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,7 @@ function OverviewCard({ delegatorAddr }: { delegatorAddr: Address }) {

<DataRow
title="Total Rewards Earned"
value={
isRewardsPending || !rewards
? '-'
: `${Number(formatEther(rewards.accumulatedRewards, 'gwei')).toFixed(2)} IP`
}
value={!rewards ? '-' : `${Number(rewards.accumulatedRewards).toFixed(2)} IP`}
tooltipInfo="The total IP rewards earned from staking on validators"
/>
</section>
Expand Down
11 changes: 5 additions & 6 deletions src/lib/services/api/delegatorApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,17 @@ export async function getDelegatorRewards(params: GetDelegatorRewardsParams): Pr

const rewards = response.data.msg

if (rewards.amount.includes('e')) {
const [mantissa, exponent] = rewards.amount.split('e')
const exp = parseInt(exponent)
const value = parseFloat(mantissa) * Math.pow(10, exp)
if (!rewards.amount) {
return {
accumulatedRewards: BigInt(formatEther(BigInt(Math.floor(value)), 'gwei')),
accumulatedRewards: '0',
lastUpdateHeight: rewards.last_update_height,
}
}

const accumulatedRewards = formatEther(BigInt(rewards.amount), 'gwei')

return {
accumulatedRewards: BigInt(formatEther(BigInt(rewards.amount), 'gwei')),
accumulatedRewards: accumulatedRewards,
lastUpdateHeight: rewards.last_update_height,
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/types/delegatorApiTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export type GetDelegatorRewardsApiResponse = {
}

export type GetDelegatorRewardsResponse = {
accumulatedRewards: bigint
accumulatedRewards: string
lastUpdateHeight: number
}

Expand Down

0 comments on commit 37be2f5

Please sign in to comment.