Skip to content

Commit

Permalink
Merge pull request #1673 from oasisprotocol/mz/validator-names-fix
Browse files Browse the repository at this point in the history
Set API limit when fetching data for named validators
  • Loading branch information
buberdds authored Jan 7, 2025
2 parents 37bf98b + 991ecf9 commit 1fa52e9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
1 change: 1 addition & 0 deletions .changelog/1673.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Set API limit when fetching data for named validators
47 changes: 26 additions & 21 deletions src/oasis-nexus/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { getRPCAccountBalances } from '../app/utils/getRPCAccountBalances'
import { toChecksumAddress } from '@ethereumjs/util'
import { fromBaseUnits } from '../app/utils/number-utils'
import { getConsensusTransactionAmount, getConsensusTransactionToAddress } from '../app/utils/transaction'
import { API_MAX_TOTAL_COUNT } from '../app/config'

export * from './generated/api'
export type { RuntimeEvmBalance as Token } from './generated/api'
Expand Down Expand Up @@ -1120,28 +1121,32 @@ export type ValidatorAddressNameMap = { [oasisAddress: string]: string | undefin
export const useGetConsensusValidatorsAddressNameMap: typeof generated.useGetConsensusValidators<
AxiosResponse<ValidatorAddressNameMap>
> = (network, params?, options?) => {
return generated.useGetConsensusValidators(network, params, {
...options,
query: {
staleTime: options?.query?.staleTime ?? 5 * 60 * 1000, // Defaults to 5 minutes
...options?.query,
},
request: {
...options?.request,
transformResponse: [
...arrayify(axios.defaults.transformResponse),
(data: generated.ValidatorList, headers, status) => {
if (status !== 200) return data
const validators: ValidatorAddressNameMap = {}
data.validators.forEach(validator => {
validators[validator.entity_address] = validator.media?.name
})
return validators
},
...arrayify(options?.request?.transformResponse),
],
return generated.useGetConsensusValidators(
network,
{ limit: API_MAX_TOTAL_COUNT, ...params },
{
...options,
query: {
staleTime: options?.query?.staleTime ?? 5 * 60 * 1000, // Defaults to 5 minutes
...options?.query,
},
request: {
...options?.request,
transformResponse: [
...arrayify(axios.defaults.transformResponse),
(data: generated.ValidatorList, headers, status) => {
if (status !== 200) return data
const validators: ValidatorAddressNameMap = {}
data.validators.forEach(validator => {
validators[validator.entity_address] = validator.media?.name
})
return validators
},
...arrayify(options?.request?.transformResponse),
],
},
},
})
)
}

export const useGetConsensusValidators: typeof generated.useGetConsensusValidators = (
Expand Down

0 comments on commit 1fa52e9

Please sign in to comment.