Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Change VFN Status Type to Enum and Fix Web-App Build #63

Merged
merged 1 commit into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions api/src/ol/models/validator.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -236,7 +242,7 @@ export class VouchDetails {

interface VfnStatusInput {
address: string;
status: string;
status: VfnStatusType;
}

@ObjectType()
Expand Down
17 changes: 9 additions & 8 deletions api/src/ol/validators/validators.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -490,19 +491,19 @@ export class ValidatorsService {
return ret;
}

async getVfnStatus(address: string): Promise<string | null> {
async getVfnStatus(address: string): Promise<VfnStatusType | null> {
const cacheData = await this.getFromCache<VfnStatus[]>(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<string> {
async queryVfnStatus(fullnodeAddress: String): Promise<VfnStatusType> {
// Variable to store the status
let status: 'invalidAddress' | 'accessible' | 'notAccessible';
let status: VfnStatusType;

// Check the VFN address
const match = fullnodeAddress && fullnodeAddress.match(fullnodeRegex);
Expand All @@ -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;
}
}

Expand Down
8 changes: 7 additions & 1 deletion web-app/src/modules/interface/Validator.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,20 @@ interface Vouches {
}[];
}

export enum VfnStatus {
InvalidAddress = 'invalidAddress',
Accessible = 'accessible',
NotAccessible = 'notAccessible',
}

export interface IValidator {
address: string;
family: string;
handle?: string;
inSet: boolean;
index: number;
votingPower: number;
vfnStatus: string;
vfnStatus: VfnStatus;
balance?: number;
unlocked?: number;
vouches: Vouches;
Expand Down
Loading