From 124f90eaae1239f826b9e72950190c89f6341864 Mon Sep 17 00:00:00 2001 From: soaresa <10797037+soaresa@users.noreply.github.com> Date: Fri, 8 Nov 2024 08:47:06 -0300 Subject: [PATCH] convert vfn status to enum type --- api/src/ol/models/validator.model.ts | 12 +++++++++--- api/src/ol/validators/validators.service.ts | 17 +++++++++-------- .../modules/interface/Validator.interface.ts | 8 +++++++- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/api/src/ol/models/validator.model.ts b/api/src/ol/models/validator.model.ts index 2322b34..a05c053 100644 --- a/api/src/ol/models/validator.model.ts +++ b/api/src/ol/models/validator.model.ts @@ -92,6 +92,12 @@ export class GqlValidatorGrade { public failedBlocks: number; } +export enum VfnStatusType { + InvalidAddress = 'invalidAddress', + Accessible = 'accessible', + NotAccessible = 'notAccessible', +} + interface ValidatorInput { inSet: boolean; index: BN; @@ -100,7 +106,7 @@ interface ValidatorInput { balance?: number; unlocked?: number; votingPower: BN; - vfnStatus?: String | null; + vfnStatus?: VfnStatusType | null; grade?: GqlValidatorGrade | null; vouches: Vouches; currentBid: GqlValidatorCurrentBid; @@ -150,7 +156,7 @@ export class Validator { public votingPower: BN; @Field(() => String, { nullable: true }) - public vfnStatus?: String | null; + public vfnStatus?: VfnStatusType | null; @Field(() => GqlValidatorGrade, { nullable: true }) public grade?: GqlValidatorGrade | null; @@ -236,7 +242,7 @@ export class VouchDetails { interface VfnStatusInput { address: string; - status: string; + status: VfnStatusType; } @ObjectType() diff --git a/api/src/ol/validators/validators.service.ts b/api/src/ol/validators/validators.service.ts index febdfce..eccc727 100644 --- a/api/src/ol/validators/validators.service.ts +++ b/api/src/ol/validators/validators.service.ts @@ -16,6 +16,7 @@ import { ValidatorUtils, //ThermostatMeasure, VfnStatus, + VfnStatusType, } from '../models/validator.model.js'; import { parseAddress } from '../../utils.js'; import { redisClient } from '../../redis/redis.service.js'; @@ -490,19 +491,19 @@ export class ValidatorsService { return ret; } - async getVfnStatus(address: string): Promise { + async getVfnStatus(address: string): Promise { const cacheData = await this.getFromCache(VALIDATORS_VFN_STATUS_CACHE_KEY); if (cacheData) { const vfnStatus = cacheData.find((item) => item.address === address); - return vfnStatus ? vfnStatus.status : null; + return vfnStatus ? (vfnStatus.status as VfnStatusType) : null; } return null; } - async queryVfnStatus(fullnodeAddress: String): Promise { + async queryVfnStatus(fullnodeAddress: String): Promise { // Variable to store the status - let status: 'invalidAddress' | 'accessible' | 'notAccessible'; + let status: VfnStatusType; // Check the VFN address const match = fullnodeAddress && fullnodeAddress.match(fullnodeRegex); @@ -514,16 +515,16 @@ export class ValidatorsService { // Check if the address is accessible status = await checkAddressAccessibility(valIp, 6182) .then((res) => { - return res ? 'accessible' : 'notAccessible'; + return res ? VfnStatusType.Accessible : VfnStatusType.NotAccessible; }) .catch(() => { - return 'notAccessible'; + return VfnStatusType.NotAccessible; }); } else { - status = 'invalidAddress'; + status = VfnStatusType.InvalidAddress; } - return status.toString(); + return status; } } diff --git a/web-app/src/modules/interface/Validator.interface.ts b/web-app/src/modules/interface/Validator.interface.ts index efea68f..d0d8472 100644 --- a/web-app/src/modules/interface/Validator.interface.ts +++ b/web-app/src/modules/interface/Validator.interface.ts @@ -8,6 +8,12 @@ interface Vouches { }[]; } +export enum VfnStatus { + InvalidAddress = 'invalidAddress', + Accessible = 'accessible', + NotAccessible = 'notAccessible', +} + export interface IValidator { address: string; family: string; @@ -15,7 +21,7 @@ export interface IValidator { inSet: boolean; index: number; votingPower: number; - vfnStatus: string; + vfnStatus: VfnStatus; balance?: number; unlocked?: number; vouches: Vouches;