From e56a6a481f443ec91dbab9619c226faa906d4d8d Mon Sep 17 00:00:00 2001 From: JettTech Date: Tue, 9 Apr 2024 06:31:19 -0500 Subject: [PATCH] avoid u64 overflow --- src/store/preferences.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/store/preferences.ts b/src/store/preferences.ts index c8397f1..ab1b5f2 100644 --- a/src/store/preferences.ts +++ b/src/store/preferences.ts @@ -41,8 +41,15 @@ export const usePreferencesStore = defineStore('preferences', { actions: { async setDefaultPreferences(): Promise { - const maxTimeBeforeInvoice = Number(this.invoicesSettings.frequency.period) || 7 + const maxDaysBeforeInvoice = Number(this.invoicesSettings.frequency.period) || 7 const invoiceDuePeriod = Number(this.invoicesSettings.due.period) || 7 + let maxTimeBeforeInvoice = maxDaysBeforeInvoice * 24 * 60 * 60 + + // NB: 18446744073709551615 is the max u64 number, which is the required type for `max_time_before_invoice.secs` + // Number should never need to exceed this amount. + if (maxTimeBeforeInvoice > 18446744073709551615) { + maxTimeBeforeInvoice = 18446744073709551615 + } const payload: DefaultPreferencesPayload = { price_compute: `${this.pricesSettings.cpu}`, @@ -50,8 +57,8 @@ export const usePreferencesStore = defineStore('preferences', { price_bandwidth: `${this.pricesSettings.bandwidth}`, max_fuel_before_invoice: `${this.invoicesSettings.frequency.amount}`, max_time_before_invoice: { - secs: maxTimeBeforeInvoice * 24 * 60 * 60, - nanos: 0 + secs: maxTimeBeforeInvoice, + nanos: 0, }, invoice_due_in_days: invoiceDuePeriod, jurisdiction_prefs: {