From 56da7277737baf1e9eeb2fd3318bcfd7b56461e5 Mon Sep 17 00:00:00 2001 From: Eric <5089238+emizzle@users.noreply.github.com> Date: Tue, 2 Jul 2024 16:20:31 +1000 Subject: [PATCH] change slotState and requestState to object to avoid typos --- src/utils/requests.js | 26 +++++++++++++++----------- src/utils/slots.js | 28 ++++++++++++++++------------ 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/src/utils/requests.js b/src/utils/requests.js index 41aac80..40a1127 100644 --- a/src/utils/requests.js +++ b/src/utils/requests.js @@ -30,12 +30,12 @@ export function price(request) { } export function getStateColour(state) { - if (state === 'New') { + if (state === RequestState.New) { return 'yellow' - } else if (state === 'Fulfilled') { + } else if (state === RequestState.Fulfilled) { return 'green' - } else if (state === 'Finished') { - return 'gray' + } else if (state === RequestState.Finished) { + return 'blue' } else { return 'red' } @@ -47,13 +47,17 @@ export const moderatedState = { banned: { text: 'NSFW! 🫣', color: 'red' } } -export const requestState = [ - 'New', // [default] waiting to fill slots - 'Fulfilled', // all slots filled, accepting regular proofs - 'Cancelled', // not enough slots filled before expiry - 'Finished', // successfully completed - 'Failed' // too many nodes have failed to provide proofs, data lost -] +export const RequestState = { + New: 'New', // [default] waiting to fill slots + Fulfilled: 'Fulfilled', // all slots filled, accepting regular proofs + Cancelled: 'Cancelled', // not enough slots filled before expiry + Finished: 'Finished', // successfully completed + Failed: 'Failed' // too many nodes have failed to provide proofs, data lost +} + +export function toRequestState(idx) { + return Object.values(RequestState).at(idx) +} // all parameters in seconds, return values also in seconds export function timestampsFor(ask, expiryBigInt, requestedAt) { diff --git a/src/utils/slots.js b/src/utils/slots.js index fb86321..c527937 100644 --- a/src/utils/slots.js +++ b/src/utils/slots.js @@ -1,20 +1,24 @@ -export const slotState = [ - 'Free', // [default] not filled yet, or host has vacated the slot - 'Filled', // host has filled slot - 'Finished', // successfully completed - 'Failed', // the request has failed - 'Paid', // host has been paid - 'Cancelled' // when request was cancelled then slot is cancelled as well -] +export const SlotState = { + Free: 'Free', // [default] not filled yet, or host has vacated the slot + Filled: 'Filled', // host has filled slot + Finished: 'Finished', // successfully completed + Failed: 'Failed', // the request has failed + Paid: 'Paid', // host has been paid + Cancelled: 'Cancelled' // when request was cancelled then slot is cancelled as well +} + +export function toSlotState(idx) { + return Object.values(SlotState).at(idx) +} export function getStateColour(state) { - if (state === 'Free') { + if (state === SlotState.Free) { return 'yellow' - } else if (state === 'Filled') { + } else if (state === SlotState.Filled) { return 'green' - } else if (state === 'Finished') { + } else if (state === SlotState.Finished) { return 'blue' - } else if (state === 'Paid') { + } else if (state === SlotState.Paid) { return 'gray' } else { return 'red'