@@ -11,7 +11,6 @@ import { tables, useDrizzle } from './drizzle'
1111import { handleValidatorLogo } from './logo'
1212import { defaultValidatorJSON } from './schemas'
1313import { getUnlistedActiveValidatorAddresses , isKnownValidatorProfile } from './validator-listing'
14- import { stripInternalValidatorFields } from './validator-public'
1514
1615export const getStoredValidatorsId = ( ) => useDrizzle ( ) . select ( { id : tables . validators . id } ) . from ( tables . validators ) . execute ( ) . then ( r => r . map ( v => v . id ) )
1716export const getStoredValidatorsAddress = ( ) => useDrizzle ( ) . select ( { address : tables . validators . address } ) . from ( tables . validators ) . execute ( ) . then ( r => r . map ( v => v . address ) )
@@ -39,6 +38,13 @@ async function selectValidatorsWithListState(filters: SQLWrapper[] = []) {
3938 : await query . execute ( )
4039}
4140
41+ export function filterVisibleValidators < T extends { isListed : boolean | null , name : string } > ( validators : T [ ] , onlyKnown : boolean ) : T [ ] {
42+ if ( ! onlyKnown )
43+ return validators
44+
45+ return validators . filter ( isKnownValidatorProfile )
46+ }
47+
4248export async function getStoredValidatorsListState ( ) {
4349 return useDrizzle ( )
4450 . select ( { address : tables . validators . address , isListed : tables . validators . isListed } )
@@ -137,7 +143,7 @@ export async function markValidatorsAsUnlisted(addresses: string[]) {
137143export type FetchValidatorsOptions = MainQuerySchema & { epochNumber : number }
138144
139145export async function fetchValidators ( _event : H3Event , params : FetchValidatorsOptions ) : Result < FetchedValidator [ ] > {
140- const { 'payout-type' : payoutType , 'only-known' : onlyKnown = false , 'with-identicons' : withIdenticons , epochNumber } = params
146+ const { 'payout-type' : payoutType , 'only-known' : onlyKnown = true , 'with-identicons' : withIdenticons , epochNumber } = params
141147
142148 // Add safety check for epochNumber
143149 if ( epochNumber === null || epochNumber === undefined || ! Number . isInteger ( epochNumber ) ) {
@@ -152,7 +158,7 @@ export async function fetchValidators(_event: H3Event, params: FetchValidatorsOp
152158 try {
153159 const dbValidators = await selectValidatorsWithListState ( filters )
154160
155- const visibleValidators = onlyKnown ? dbValidators . filter ( isKnownValidatorProfile ) : dbValidators
161+ const visibleValidators = filterVisibleValidators ( dbValidators , onlyKnown )
156162 const validatorIds = visibleValidators . map ( v => v . id )
157163 if ( validatorIds . length === 0 )
158164 return [ true , undefined , [ ] ]
@@ -219,8 +225,7 @@ export async function fetchValidators(_event: H3Event, params: FetchValidatorsOp
219225 const activityByValidatorId = new Map ( activityRows . map ( row => [ row . validatorId , row ] ) )
220226
221227 const validators = visibleValidators . map ( ( validator ) => {
222- const { logo, hasDefaultLogo } = validator
223- const rest = stripInternalValidatorFields ( validator )
228+ const { logo, hasDefaultLogo, contact : _contact , isListed, ...rest } = validator
224229 const scoreRow = scoresByValidatorId . get ( validator . id )
225230 const activityRow = activityByValidatorId . get ( validator . id )
226231
@@ -243,6 +248,7 @@ export async function fetchValidators(_event: H3Event, params: FetchValidatorsOp
243248
244249 return {
245250 ...rest ,
251+ isListed,
246252 score,
247253 hasDefaultLogo,
248254 logo : withIdenticons === false && hasDefaultLogo ? undefined : logo ,
@@ -278,7 +284,7 @@ export const cachedFetchValidators = defineCachedFunction((_event: H3Event, para
278284} )
279285
280286export interface FetchValidatorOptions { address : string , range : Range }
281- export type FetchedValidatorDetails = Omit < Validator , 'isListed' > & { activity : Activity [ ] , scores : Score [ ] , score ?: Score }
287+ export type FetchedValidatorDetails = Validator & { activity : Activity [ ] , scores : Score [ ] , score ?: Score }
282288
283289export async function fetchValidator ( _event : H3Event , params : FetchValidatorOptions ) : Result < FetchedValidatorDetails > {
284290 const { address, range : { fromEpoch, toEpoch } } = params
@@ -321,8 +327,7 @@ export async function fetchValidator(_event: H3Event, params: FetchValidatorOpti
321327 ) )
322328 . execute ( )
323329
324- const publicValidator = stripInternalValidatorFields ( validator )
325- return [ true , undefined , { ...publicValidator , scores, activity, score } ]
330+ return [ true , undefined , { ...validator , scores, activity, score } ]
326331 }
327332 catch ( error ) {
328333 consola . error ( `Error fetching validator ${ address } : ${ error } ` )
0 commit comments