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 for history and token lookups, and each recipient to Etherscan for its label. Two settings, "Use Blockscout" and "Check recipients on Etherscan", now gate those requests where they are made. Both are off in a new profile and offered unticked on Welcome and in Settings. While one is off, the screens that relied on it say so in a plain line naming the setting; after either changes in Settings, Back draws the screen it lands on again. ENS lookups ask only the RPC endpoint, so a name resolved off-chain does not resolve. README and the user guide say what is contacted by default and what each setting adds. Model: opus-5-5
This commit is contained in:
+27
-7
@@ -1,6 +1,7 @@
|
||||
// Balance fetching: ETH balances and the balances of the tokens the user
|
||||
// tracks via RPC, the other ERC-20 token balances and the holder counts via
|
||||
// Blockscout, ENS reverse lookup via RPC.
|
||||
// Blockscout while the user has "Use Blockscout" on, ENS reverse lookup via
|
||||
// RPC.
|
||||
|
||||
const {
|
||||
JsonRpcProvider,
|
||||
@@ -37,9 +38,18 @@ const { resolveTokenDecimals } = require("./approvalAmount");
|
||||
// ethers knows chains this wallet does not, so an id that is not one of ours
|
||||
// is a caller bug and must not resolve to a working provider for some other
|
||||
// chain.
|
||||
//
|
||||
// `disableCcipRead` keeps every ENS lookup on the RPC endpoint. Left on, as
|
||||
// ethers has it, a resolver that says a name is resolved off-chain makes ethers
|
||||
// fetch the web address the resolver gives, straight from the browser, with the
|
||||
// name being looked up; for the reverse lookup of the user's addresses that is
|
||||
// the user's own name (https://git.eeqj.de/sneak/AutistMask/issues/668). Such a
|
||||
// name does not resolve.
|
||||
function getProvider(rpcUrl, networkId) {
|
||||
const net = Network.from(requireNetworkId(networkId).id);
|
||||
return new JsonRpcProvider(rpcUrl, net, { staticNetwork: net });
|
||||
const provider = new JsonRpcProvider(rpcUrl, net, { staticNetwork: net });
|
||||
provider.disableCcipRead = true;
|
||||
return provider;
|
||||
}
|
||||
|
||||
function requireNetworkId(networkId) {
|
||||
@@ -81,6 +91,11 @@ function rawUnits(value) {
|
||||
|
||||
// Fetch token balances for a single address from Blockscout.
|
||||
// Returns [{ address, name, symbol, decimals, balance, holders }].
|
||||
//
|
||||
// `useBlockscout` is the user's "Use Blockscout" setting. While it is off,
|
||||
// Blockscout is not asked and the answer is an empty list: no token the user
|
||||
// has not tracked is listed.
|
||||
//
|
||||
// Filters out spam: only shows tokens that are in the known token list,
|
||||
// explicitly tracked by the user, or have >= 1000 holders. A tracked token's
|
||||
// balance is read through the RPC endpoint instead, and its row here gives that
|
||||
@@ -96,9 +111,11 @@ function rawUnits(value) {
|
||||
async function fetchTokenBalances(
|
||||
address,
|
||||
blockscoutUrl,
|
||||
useBlockscout,
|
||||
trackedTokens,
|
||||
signal,
|
||||
) {
|
||||
if (!useBlockscout) return [];
|
||||
try {
|
||||
const resp = await debugFetch(
|
||||
blockscoutUrl + "/addresses/" + address + "/token-balances",
|
||||
@@ -296,12 +313,13 @@ async function fetchTrackedTokenBalances(
|
||||
}
|
||||
|
||||
// Fetch ETH balances, ENS names, and ERC-20 token balances for all addresses.
|
||||
// `trackedTokens` are the tokens tracked on the active network. `signal` is as
|
||||
// for fetchTokenBalances().
|
||||
// `trackedTokens` are the tokens tracked on the active network.
|
||||
// `useBlockscout` and `signal` are as for fetchTokenBalances().
|
||||
async function refreshBalances(
|
||||
wallets,
|
||||
rpcUrl,
|
||||
blockscoutUrl,
|
||||
useBlockscout,
|
||||
trackedTokens,
|
||||
networkId,
|
||||
signal,
|
||||
@@ -362,13 +380,15 @@ async function refreshBalances(
|
||||
// ERC-20 token balances: the tracked tokens' through the RPC
|
||||
// endpoint, and from Blockscout the tokens the user has not
|
||||
// tracked. When Blockscout fails, the untracked rows from before
|
||||
// this refresh stay. The Blockscout request is started first and
|
||||
// handed to fetchTrackedTokenBalances() too, which waits for it
|
||||
// after sending its balanceOf reads, so the two run side by side.
|
||||
// this refresh stay; while "Use Blockscout" is off there are none.
|
||||
// The Blockscout request is started first and handed to
|
||||
// fetchTrackedTokenBalances() too, which waits for it after
|
||||
// sending its balanceOf reads, so the two run side by side.
|
||||
const previous = addr.tokenBalances || [];
|
||||
const explorerRequest = fetchTokenBalances(
|
||||
addr.address,
|
||||
blockscoutUrl,
|
||||
useBlockscout,
|
||||
tracked,
|
||||
signal,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user