change slotState and requestState to object to avoid typos

This commit is contained in:
Eric 2024-07-02 16:20:31 +10:00
parent 09c4ed7daf
commit 56da727773
No known key found for this signature in database
2 changed files with 31 additions and 23 deletions

View File

@ -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) {

View File

@ -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'