Skip to content

Commit

Permalink
feat: check node version too
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-yarmosh committed Jan 16, 2025
1 parent eb1f92d commit e372fcc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
10 changes: 5 additions & 5 deletions store/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ import { defineStore } from 'pinia';

export const useMetadata = defineStore('metadata', {
state: (): Metadata => ({
targetNodeVersion: 0,
targetNodeVersion: '',
targetHardwareDeviceFirmware: '',
creditsPerDollar: 0,
creditsPerAdoptedProbe: 0,
}),
actions: {
setMetadata (metadata: Metadata) {
this.targetNodeVersion = metadata.targetNodeVersion;
this.targetHardwareDeviceFirmware = metadata.targetHardwareDeviceFirmware;
this.creditsPerDollar = metadata.creditsPerDollar;
this.creditsPerAdoptedProbe = metadata.creditsPerAdoptedProbe;
this.targetNodeVersion = String(metadata.targetNodeVersion);
this.targetHardwareDeviceFirmware = String(metadata.targetHardwareDeviceFirmware);
this.creditsPerDollar = Number(metadata.creditsPerDollar);
this.creditsPerAdoptedProbe = Number(metadata.creditsPerAdoptedProbe);
},
},
});
2 changes: 1 addition & 1 deletion types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ declare global {
} | null;

type Metadata = {
targetNodeVersion: number,
targetNodeVersion: string,
targetHardwareDeviceFirmware: string,
creditsPerDollar: number,
creditsPerAdoptedProbe: number,
Expand Down
12 changes: 8 additions & 4 deletions utils/probe-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,23 @@ const compareSemver = (a: string, b: string) => {
return 0;
};

const isFirmwareOutdated = (probeFirmware: string | null, metadataFirmware: string) => {
if (!probeFirmware || !metadataFirmware) {
const isOutdated = (probeValue: string | null, metadataValue: string) => {
if (!probeValue || !metadataValue) {
return false;
}

const result = compareSemver(probeFirmware.replaceAll('v', ''), metadataFirmware.replaceAll('v', ''));
const result = compareSemver(probeValue.replaceAll('v', ''), metadataValue.replaceAll('v', ''));
return result === -1;
};

export const getProbeStatus = (probe: Probe) => {
const metadata = useMetadata();

if (probe.status === 'ready' && isFirmwareOutdated(probe.hardwareDeviceFirmware, metadata.targetHardwareDeviceFirmware)) {
if (
probe.status === 'ready'
&& (isOutdated(probe.hardwareDeviceFirmware, metadata.targetHardwareDeviceFirmware)
|| isOutdated(probe.nodeVersion, metadata.targetNodeVersion)
)) {
return 'Ready (outdated)';
}

Expand Down

0 comments on commit e372fcc

Please sign in to comment.