fix: Blockscout and Etherscan lookups are off until the user turns them on (closes #668)
Out of the box the wallet sent the user's addresses to Blockscout. It sent each recipient to Etherscan for its label. Two settings, "Use Blockscout" and "Check recipients on Etherscan", now gate those requests. Both are off in a new install and offered unticked on Welcome and in Settings. While one is off, the screens that relied on it say so in a plain line. Each gated request reads its setting from storage before it asks and when the answer lands. An answer that lands after the setting went off is dropped. An open popup takes a change another page saved and draws its screens again. While "Use Blockscout" is off, no address keeps an untracked token. ENS lookups ask only the RPC endpoint. Model: opus-5-5
This commit is contained in:
+54
-18
@@ -11,7 +11,7 @@ const {
|
||||
const { StateUnusableError } = require("../shared/stateSchema");
|
||||
const { log, setRuntimeDebug } = require("../shared/log");
|
||||
const { refreshPrices } = require("../shared/prices");
|
||||
const { refreshBalances } = require("../shared/balances");
|
||||
const { refreshBalances, dropUntrackedTokens } = require("../shared/balances");
|
||||
const { clearPopupCaches } = require("../shared/chainSwitch");
|
||||
const {
|
||||
$,
|
||||
@@ -71,21 +71,27 @@ let refreshInFlight = false;
|
||||
// the recovery screen: there is no profile left to refresh.
|
||||
let refreshTimer = null;
|
||||
|
||||
// The refresh first takes any change to the network or to either setting saved
|
||||
// elsewhere (followStoredSettings() below), so what it draws follows them.
|
||||
//
|
||||
// The refresh writes into a copy of the wallets. Inside the save, under the
|
||||
// lock, its results are copied onto the address records in `state` only if the
|
||||
// network it ran on is still the active one, on this page and in the stored
|
||||
// record; the background's switch, after the user approves a site's request,
|
||||
// reaches this page only after the stored record (followNetworkSwitch() below).
|
||||
// reaches this page only after the stored record (followStoredSettings()).
|
||||
// A switch while the refresh ran cleared every address's balances
|
||||
// (applyChainSwitchFields() in src/shared/chainSwitchFields.js), and the
|
||||
// previous network's must not come back over them
|
||||
// (https://git.eeqj.de/sneak/AutistMask/issues/577). A dropped refresh is not
|
||||
// recorded as done. Results are copied by address, so an address added or
|
||||
// removed meanwhile is left as it is.
|
||||
// removed meanwhile is left as it is. Blockscout may have answered before the
|
||||
// user turned "Use Blockscout" off. So if the stored setting is off when the
|
||||
// refresh saves, the save drops every token the user has not tracked.
|
||||
async function doRefreshAndRender() {
|
||||
if (refreshInFlight) return;
|
||||
refreshInFlight = true;
|
||||
try {
|
||||
await followStoredSettings();
|
||||
const networkId = state.networkId;
|
||||
const wallets = structuredClone(state.wallets);
|
||||
await Promise.all([
|
||||
@@ -117,6 +123,9 @@ async function doRefreshAndRender() {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!stored.useBlockscout) {
|
||||
dropUntrackedTokens(state.wallets, stored.trackedTokens);
|
||||
}
|
||||
state.lastBalanceRefresh = Date.now();
|
||||
return true;
|
||||
});
|
||||
@@ -228,17 +237,36 @@ function fallbackView() {
|
||||
// src/shared/chainSwitch.js), so a record naming a network other than this
|
||||
// page's always holds a switch saved elsewhere, and a switch the user picks
|
||||
// here while this waits for the lock is made after it.
|
||||
async function followNetworkSwitch() {
|
||||
let switched = false;
|
||||
//
|
||||
// Another page may change "Use Blockscout" or "Check recipients on Etherscan".
|
||||
// This page takes either change the same way and draws its screens again. Its
|
||||
// own changes to them are made under the lock too (views/settings.js,
|
||||
// views/welcome.js).
|
||||
async function followStoredSettings() {
|
||||
let changed = false;
|
||||
// A failed save is reported by saveState() itself: see onSaveFailure().
|
||||
await saveState((stored) => {
|
||||
if (stored.networkId === state.networkId) return false;
|
||||
settings.cutViewStack();
|
||||
takeStoredNetwork(stored);
|
||||
clearPopupCaches();
|
||||
switched = true;
|
||||
if (stored.networkId !== state.networkId) {
|
||||
settings.cutViewStack();
|
||||
takeStoredNetwork(stored);
|
||||
clearPopupCaches();
|
||||
changed = true;
|
||||
}
|
||||
if (stored.useBlockscout !== state.useBlockscout) {
|
||||
settings.setUseBlockscout(stored.useBlockscout);
|
||||
changed = true;
|
||||
}
|
||||
if (
|
||||
stored.checkRecipientsOnEtherscan !==
|
||||
state.checkRecipientsOnEtherscan
|
||||
) {
|
||||
state.checkRecipientsOnEtherscan =
|
||||
stored.checkRecipientsOnEtherscan;
|
||||
changed = true;
|
||||
}
|
||||
if (!changed) return false;
|
||||
}).catch(() => {});
|
||||
if (switched) settings.showNewNetwork();
|
||||
if (changed) settings.showNewSettings();
|
||||
}
|
||||
|
||||
// The background opens the approval window as wide as the page, but the
|
||||
@@ -385,19 +413,27 @@ async function init() {
|
||||
settingsAddToken.init(ctx);
|
||||
deleteAddress.init(ctx);
|
||||
|
||||
// Only a record naming a network other than this page's is followed: the
|
||||
// one this page's own switch in Settings saves names the network it
|
||||
// already has, and a record naming none is no switch.
|
||||
// Only a record whose network, "Use Blockscout" or "Check recipients on
|
||||
// Etherscan" differs from this page's is followed. A record this page's
|
||||
// own save wrote matches this page. A record naming no network is no
|
||||
// switch.
|
||||
onStorageChanged((changes) => {
|
||||
const written = changes.autistmask && changes.autistmask.newValue;
|
||||
if (!written || !written.networkId) return;
|
||||
if (written.networkId !== state.networkId) followNetworkSwitch();
|
||||
if (
|
||||
written.networkId !== state.networkId ||
|
||||
written.useBlockscout !== state.useBlockscout ||
|
||||
written.checkRecipientsOnEtherscan !==
|
||||
state.checkRecipientsOnEtherscan
|
||||
) {
|
||||
followStoredSettings();
|
||||
}
|
||||
});
|
||||
// A switch saved since loadState() above, before there was a listener.
|
||||
followNetworkSwitch();
|
||||
// A change saved since loadState() above, before there was a listener.
|
||||
followStoredSettings();
|
||||
|
||||
if (!state.hasWallet) {
|
||||
showView("welcome");
|
||||
welcome.show();
|
||||
} else {
|
||||
renderWalletList();
|
||||
restoreView();
|
||||
|
||||
Reference in New Issue
Block a user