fix(2380): fixed block duration field to account for the new api format (#2423)

* fix(2380): fixed block duration field to account for the new api format

* fix(2380): removed unneeded import

* fix(2380): a little more hardened against duration being undefined and different environments returning different data

* fix(2380): improved comment
This commit is contained in:
Sam Keen 2022-12-16 12:25:20 +00:00 committed by GitHub
parent 98d01d7933
commit f133200c7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 4 deletions

View File

@ -1,3 +1,3 @@
# App configuration variables
NX_VEGA_URL=https://api.stagnet3.vega.xyz/graphql
NX_VEGA_ENV=STAGNET3;
NX_VEGA_ENV=STAGNET3

View File

@ -110,9 +110,30 @@ export const statsFields: { [key in keyof Stats]: StatFields[] } = {
blockDuration: [
{
title: t('Block time'),
formatter: (duration: number) => (duration / 1000000000).toFixed(3),
goodThreshold: (blockDuration: number) =>
blockDuration > 0 && blockDuration <= 2000000000,
formatter: (duration: string) => {
const dp = 3;
if (duration?.includes('ms')) {
return (parseFloat(duration) / 1000).toFixed(dp).toString();
} else if (duration?.includes('s')) {
return parseFloat(duration).toFixed(dp).toString();
}
return duration
? (Number(duration) / 1000000000).toFixed(dp)
: undefined;
},
goodThreshold: (blockDuration: string) => {
if (blockDuration?.includes('ms')) {
// we only get ms from the api if duration is less than 1s, so this
// automatically passes
return true;
} else if (blockDuration?.includes('s')) {
return parseFloat(blockDuration) <= 2;
} else {
return (
Number(blockDuration) > 0 && Number(blockDuration) <= 2000000000
);
}
},
description: t('Seconds between the two most recent blocks'),
},
],