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

[rewards-chart] update rewards request #51

Merged
merged 2 commits into from
Dec 15, 2023
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ Daily rewards for the user who has made a deposit in the vault. With the help of

```ts
type UserReward = {
rewards: number
sumRewards: number
dailyRewards: number
}

type Output = {
Expand Down
5 changes: 3 additions & 2 deletions src/graphql/backend/vault/userRewardsQuery.graphql
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
query UserRewards($user: String!, $vaultAddress: String!, $dateFrom: date_as_timestamp!) {
userRewards(user: $user, vaultAddress: $vaultAddress, dateFrom: $dateFrom) {
date,
sumRewards,
date
sumRewards
dailyRewards
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ describe('modifyUserReward and modifyUserRewards functions', () => {
{
date: '1694908800',
sumRewards: '344379922475148628745',
dailyRewards: '344379922475148628745',
},
{
date: '1694995200',
sumRewards: '344382187878289278175',
dailyRewards: '0',
},
],
}
Expand All @@ -22,18 +24,21 @@ describe('modifyUserReward and modifyUserRewards functions', () => {
const result = modifyUserReward(userReward)

expect(result).toEqual({
rewards: 344.37992247514865,
sumRewards: 344.37992247514865,
dailyRewards: 344.37992247514865,
})
})

it('should correctly modify multiple rewards', () => {
const expectedResult = {
days: {
1694908800: {
rewards: 344.37992247514865,
sumRewards: 344.37992247514865,
dailyRewards: 344.37992247514865,
},
1694995200: {
rewards: 344.3821878782893,
sumRewards: 344.3821878782893,
dailyRewards: 0,
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import type { UserRewardsQueryPayload } from '../../../../graphql/backend/vault'


export const modifyUserReward = (reward: Omit<UserRewardsQueryPayload['userRewards'][number], 'date'>) => {
const totalRewards = String(reward.sumRewards) || '0'
const sumRewards = String(reward.sumRewards) || '0'
const dailyRewards = String(reward.dailyRewards) || '0'

return {
rewards: Number(formatEther(totalRewards)),
sumRewards: Number(formatEther(sumRewards)),
dailyRewards: Number(formatEther(dailyRewards)),
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/methods/vault/requests/getUserRewards/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
type UserReward = {
rewards: number
sumRewards: number
dailyRewards: number
}

export type ModifyUserReward = {
Expand Down
Loading