Skip to content

Commit

Permalink
fix: useAngleRewardsMultipleChains
Browse files Browse the repository at this point in the history
  • Loading branch information
0xMasayoshi committed Mar 28, 2024
1 parent d90d35c commit 785d377
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ChainId } from 'sushi/chain'

import { useAllPrices } from '../prices'
import { angleRewardsQueryFn, angleRewardsSelect } from './useAngleRewards'
import { angleRewardsMultipleValidator } from './validator'

interface UseAngleRewardsParams {
chainIds: ChainId[]
Expand All @@ -19,19 +20,24 @@ export const useAngleRewardsMultipleChains = ({
queryKey: ['getAngleRewardsMultiple', { chainIds, account, prices }],
queryFn: async () => {
if (account && prices) {
const res = await angleRewardsQueryFn({ chainIds, account })
const res = await Promise.all(
chainIds.map((chainId) =>
angleRewardsQueryFn({ chainIds: [chainId], account }),
),
)
const parsed = angleRewardsMultipleValidator.parse(res)

return Object.entries(res)
.map(([key, value]) => {
return parsed
.map((el, i) => {
const data = angleRewardsSelect({
chainId: +key as ChainId,
data: value,
prices: prices[key],
chainId: chainIds[i]!,
data: el[chainIds[i]!],
prices: prices[chainIds[i]!],
})

return data
? {
chainId: +key as ChainId,
chainId: chainIds[i]!,
...data,
}
: null
Expand Down
2 changes: 2 additions & 0 deletions packages/react-query/src/hooks/rewards/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ export const angleRewardsValidator = z.record(
}),
)

export const angleRewardsMultipleValidator = z.array(angleRewardsValidator)

export const angleRewardTokensValidator = z.object({
validRewardTokens: z
.array(
Expand Down

0 comments on commit 785d377

Please sign in to comment.