fix: price data update time serialization

price update time was not properly serialized as a number like the schema was, and led to dates being stored as empty objects. UI code also did not check if date was NaN, and rendered "invalid date" instead.
This commit is contained in:
xenticore
2025-03-29 14:19:38 -04:00
parent 13a8e14284
commit be6206194b
3 changed files with 10 additions and 8 deletions

View File

@@ -7,8 +7,8 @@ import { logDebug, log } from "./utils/log"
export class ItemPriceData {
/** Item SKU. */
sku: string
/** Date updated. */
update: Date
/** Date updated, as Unix timestamp. */
update: number
/** TTL in milliseconds. */
ttl: number
/** Price in keys. */
@@ -19,7 +19,7 @@ export class ItemPriceData {
scmPrice: number
toString(): string {
return `Price for ${this.sku}, fetched ${this.update} (expires ${this.update.getTime() + this.ttl})\n` +
return `Price for ${this.sku}, fetched ${new Date(this.update)} (expires ${new Date(this.update + this.ttl)})\n` +
JSON.stringify({
keys: this.keys,
metal: this.metal,
@@ -43,8 +43,8 @@ export async function fetchPrice(token: string, sku: string, update: Date = new
return new Promise(async (resolve, reject) => {
var data: ItemPriceData | null
const cached = await getStorageValue(storage_priceprefix + sku, null)
if (cached != null && 'keys' in cached && 'metal' in cached) {
const cached: ItemPriceData = await getStorageValue(storage_priceprefix + sku, null)
if (cached != null && 'keys' in cached && 'metal' in cached && !isNaN(cached.update)) {
data = cached
}
@@ -55,7 +55,7 @@ export async function fetchPrice(token: string, sku: string, update: Date = new
}
data = new ItemPriceData()
data.sku = sku
data.update = update
data.update = update.getTime()
data.ttl = ttl
try {