// Parsing for the dust threshold field in Settings. // // Pure: no DOM, no state, so the accepted set can be unit tested directly // instead of through the settings view. // // Accepted input is plain decimal digits only, meaning a whole number of // gwei, zero or greater. Zero is a real setting: it hides nothing. // // Deliberately rejected, not coerced: // "" nothing to save // "-1" a negative threshold has no meaning // "1.5" fractional gwei is not a threshold the filter can use // "100 gwei" the unit is already printed beside the field // "0x10" hex, which Number() would silently read as 16 // "1e3" exponent notation, which Number() would silently read as 1000 // // The last two are the reason this is a digit test and not a Number() test. // Number() accepts both, and accepting them would put a number in the field // that the user did not type — the same silent substitution the visible // rejection message exists to end. // Must render on ONE line of #flash-msg; see showFlash() in // src/popup/views/helpers.js for how long that is. const DUST_THRESHOLD_MESSAGE = "Enter a whole number of gwei, zero or greater."; // Returns the threshold in gwei, or null if the input is not one. function parseDustThresholdGwei(raw) { if (typeof raw !== "string") return null; const trimmed = raw.trim(); if (!/^[0-9]+$/.test(trimmed)) return null; const val = Number(trimmed); // A run of digits long enough to exceed Number's exact integer range // would round on the way in, so it is not a threshold we can store. if (!Number.isSafeInteger(val)) return null; return val; } module.exports = { DUST_THRESHOLD_MESSAGE, parseDustThresholdGwei };