Skip to content

Commit

Permalink
[vault-test]: improves, add new fillGaps
Browse files Browse the repository at this point in the history
  • Loading branch information
dfkadyr committed Jan 17, 2024
1 parent 38d632c commit f02cabe
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,22 +252,27 @@ Daily rewards for the user who has made a deposit in the vault. With the help of
#### Arguments:
| Name | Type | Type | Description |
|------|----------|-------------|---------|
|------|----------|-------------|---|
| vaultAddress | `string` | **Require** | - |
| userAddress | `string` | **Require** | - |
| dateFrom | `number` | **Require** | Time to start |
| dateTo | `number` | Time to end |
| dateTo | `number` | **Optional** | Time to end |
| fillGaps | `boolean` | **Optional** | To fill in all the days, or not |
#### Returns:
```ts
type UserReward = {
sumRewards: number
dailyRewards: number
date: number
sumRewards: string
dailyRewards: string
dailyRewardsEur: string
dailyRewardsGbp: string
dailyRewardsUsd: string
}

type Output = {
days: Record<number, UserReward>
days: Record<number, UserReward> | []
}
```
Expand Down
4 changes: 2 additions & 2 deletions src/graphql/backend/vault/userRewardsQuery.graphql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
query UserRewards($user: String!, $vaultAddress: String!, $dateFrom: DateAsTimestamp!, $dateTo: DateAsTimestamp) {
userRewards(user: $user, vaultAddress: $vaultAddress, dateFrom: $dateFrom, dateTo: $dateTo) {
query UserRewards($user: String!, $vaultAddress: String!, $dateFrom: DateAsTimestamp!, $dateTo: DateAsTimestamp, $fillGaps: Boolean = true) {
userRewards(user: $user, vaultAddress: $vaultAddress, dateFrom: $dateFrom, dateTo: $dateTo, fillGaps: $fillGaps) {
date
sumRewards
dailyRewards
Expand Down
18 changes: 10 additions & 8 deletions src/methods/vault/requests/getUserRewards/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,29 @@ type GetUserRewardsInput = {
options: StakeWise.Options
userAddress: UserRewardsQueryVariables['user']
vaultAddress: UserRewardsQueryVariables['vaultAddress']
dateFrom: number
dateTo?: number
dateFrom: string
dateTo?: string
fillGaps?: boolean
}

const getUserRewards = async (input: GetUserRewardsInput) => {
const { options, vaultAddress, userAddress, dateFrom, dateTo } = input
const { options, vaultAddress, userAddress, dateFrom, dateTo, fillGaps } = input

validateArgs.address({ vaultAddress, userAddress })
validateArgs.number({ dateFrom })
validateArgs.string({ dateFrom })

if (dateTo) {
validateArgs.number({ dateTo })
validateArgs.string({ dateTo })
}

const data = await graphql.backend.vault.fetchUserRewardsQuery<ModifyUserReward>({
url: apiUrls.getBackendUrl(options),
variables: {
vaultAddress: vaultAddress.toLowerCase(),
dateTo,
dateFrom,
fillGaps,
user: userAddress.toLowerCase(),
dateFrom: String(dateFrom),
dateTo: dateTo ? String(dateTo) : null,
vaultAddress: vaultAddress.toLowerCase(),
} as UserRewardsQueryVariables,
modifyResult: modifyUserRewards,
})
Expand Down

0 comments on commit f02cabe

Please sign in to comment.