Skip to content

Commit

Permalink
avoid u64 overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
JettTech committed Apr 9, 2024
1 parent 9adb6b6 commit e56a6a4
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/store/preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,24 @@ export const usePreferencesStore = defineStore('preferences', {

actions: {
async setDefaultPreferences(): Promise<void> {
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}`,
price_storage: `${this.pricesSettings.storage}`,
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: {
Expand Down

0 comments on commit e56a6a4

Please sign in to comment.