Honor evmScanApiKey on etherscan.io - #1078
Open
j0ntz wants to merge 1 commit into
Open
Conversation
The Etherscan V2 upgrade made key lookup for api.etherscan.io require the deprecated etherscanApiKey option and throw before it ever considered evmScanApiKey, the supported option. A build configured with only evmScanApiKey therefore sent a keyless request, which Etherscan V2 rejects with 'Missing/Invalid API Key'. EvmScan is the only network adapter with a non-null fetchTxs on the 15 EVM networks that route through api.etherscan.io, so the failed lookup left transaction history permanently unsynced. With balance complete and history at zero, the token sync tracker reports exactly 0.5, which surfaces as a wallet stuck at 50%. Check evmScanApiKey first for every server, and treat an empty string or empty array as unconfigured so it still falls through to the deprecated per-network keys.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Open
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CHANGELOG
Does this branch warrant an entry to the CHANGELOG?
Dependencies
none
Description
Asana task
getEvmScanApiKeyrequires the deprecatedetherscanApiKeyinit option whenever the server isapi.etherscan.io, and throws before it ever considersevmScanApiKey, the option the function itself tells callers to use:An app configured with only
evmScanApiKeytherefore gets no key at all. Etherscan V2 rejects keyless requests:The impact is larger than fee estimation.
EvmScanAdapteris the ONLY adapter with a non-nullfetchTxson the 15 EVM networks whosenetworkAdapterConfigspoint atapi.etherscan.io(ethereum, polygon, base, arbitrum, optimism, avalanche, binancesmartchain, celo, zksync, sonic, opbnb, monad, hyperEvm, holesky, sepolia).RpcAdapter,BlockbookAdapterandAmberdataAdapterall setfetchTxs = null. So the failed key lookup meansacquireTxsnever receives atokenTxsupdate,setHistoryRatios(_, 1)never fires, and transaction history stays unsynced forever.makeTokenSyncTrackeraverages balance and history progress per token, so a wallet whose balance is complete and whose history is stuck at zero reports exactly0.5:which surfaces in the app as a wallet permanently stuck at 50% sync. This was reported against a white-label build whose env.json carries only
evmScanApiKey.This regressed in
0296a76c"Upgrade to Etherscan V2" (first released in v4.47.0), which moved theevmScanApiKeycheck below the new etherscan.io branch. Before that commit,evmScanApiKeywas checked first and such a build worked.The fix: check
evmScanApiKeyfirst for every server, etherscan.io included. Treat an empty string or empty array as unconfigured, so a caller that defaults the option to[](edge-react-gui does) still falls through to the deprecated per-network keys instead of sending an empty key. The hard error for etherscan.io is kept for the case where no usable key exists at all, and the deprecation warning now fires on that path too.Testing
test/ethereum/fees/getEvmScanApiKey.test.tscover:evmScanApiKeyresolving for etherscan.io and for other scan hosts, an empty array falling back to the deprecated key, an absentevmScanApiKeyfalling back, and no usable key still throwing.npm test: passing.evmScanApiKey. Before: an ETH wallet resync left the app at "Loading Transactions... 49.9% Complete" with an empty transaction list. After: the transaction list fully repopulated and the sync indicator cleared.Note
Medium Risk
Changes init-option resolution for all EvmScan and gas-oracle calls on etherscan.io hosts across many EVM networks; behavior is intentionally different but fixes a production sync regression with targeted tests.
Overview
Fixes EVM wallet sync stuck at 50% when the app is configured with only the supported
evmScanApiKeyinit option (no deprecatedetherscanApiKey).getEvmScanApiKeynow checksevmScanApiKeyfirst for every scan host, includingapi.etherscan.io. After the Etherscan V2 upgrade, the etherscan.io branch ran before that check and requiredetherscanApiKey, so builds with onlyevmScanApiKeysent no API key. Etherscan V2 rejects those requests, which brokeEvmScanAdaptertransaction history on the networks that rely on that host—history never advanced while balance could still sync, so overall progress averaged to half.A new
hasApiKeyhelper treats absent values, empty strings, and empty arrays as unconfigured (matching GUI defaults likeevmScanApiKey: []), so those cases fall through to deprecated per-network keys instead of a keyless call. The hard error for etherscan.io with no usable key now referencesevmScanApiKeyand logs the deprecation warning when falling back toetherscanApiKey.Unit tests in
test/ethereum/fees/getEvmScanApiKey.test.tscover the etherscan.io and other hosts paths, empty-array fallback, and the throw when nothing is configured.Reviewed by Cursor Bugbot for commit 2bd8113. Bugbot is set up for automated code reviews on this repo. Configure here.