// Reads "Use Blockscout", "Check recipients on Etherscan" or the active network // from the stored profile. // // Before each request that sends the user's data to Blockscout or Etherscan, the // wallet reads that service's setting from storage. The wallet reads the setting // again when the answer lands. While the setting is off, no such request is // made, and an answer that lands after the setting went off is dropped. A page's // own copy of the setting is not used, because another page may have just // changed it. // // Before asking Blockscout for the transaction history, a screen remembers // which network is active. If another network is active on the page or in // storage when the answer lands, the screen drops the answer. A switch saved // elsewhere reaches storage first and the page later. const { storageGet } = require("./browserApi"); const { normalizePersisted } = require("./persistedState"); // Whether the setting `name` is on in the stored profile. `name` is // "useBlockscout" or "checkRecipientsOnEtherscan". The profile is read through // normalizePersisted(), as a load reads it, so only a stored true is on. A // failed read counts as off. async function storedSettingIsOn(name) { try { const { autistmask } = await storageGet("autistmask"); return normalizePersisted(autistmask)[name]; } catch { return false; } } // Whether `networkId` is the active network in the stored profile. A failed // read counts as no. async function storedNetworkIs(networkId) { try { const { autistmask } = await storageGet("autistmask"); return normalizePersisted(autistmask).networkId === networkId; } catch { return false; } } module.exports = { storedSettingIsOn, storedNetworkIs };