fix: tracked tokens' balances are read through the RPC endpoint (closes #669)
refreshBalances() now reads the balance of every token tracked on the active network, at every address, with balanceOf through the same provider as the ETH balance, at the scale the screens read that token at. Blockscout's answer adds only the tokens the user has not tracked, admitted as before. A failed balanceOf keeps that token's previous row and is logged; while Blockscout fails, the untracked rows from before stay. A tracked token's row carries no decimals or holder count from the explorer. The browser test for a hostile symbol now untracks the stub token first, because a tracked token is listed under the symbol it was added with. Model: opus-5-5
This commit is contained in:
@@ -18,6 +18,11 @@ const {
|
||||
const RPC_URL = "https://rpc.example.invalid";
|
||||
const EXPLORER_URL = "https://explorer.example.invalid/api/v2";
|
||||
const ADDRESS = "0x1111111111111111111111111111111111111111";
|
||||
const TRACKED = {
|
||||
address: "0x7777777777777777777777777777777777777777",
|
||||
symbol: "TRK",
|
||||
decimals: 6,
|
||||
};
|
||||
|
||||
const realFetch = globalThis.fetch;
|
||||
let logged;
|
||||
@@ -30,9 +35,9 @@ beforeEach(() => {
|
||||
const failedToFetch = async () => {
|
||||
throw new TypeError("Failed to fetch");
|
||||
};
|
||||
// The RPC calls (ETH balance, ENS name, and the scan's balance and
|
||||
// transaction count) and the explorer request (token balances) all fail
|
||||
// the same way.
|
||||
// The RPC calls (ETH balance, ENS name, the tracked token's balance, and
|
||||
// the scan's balance and transaction count) and the explorer request (the
|
||||
// other token balances) all fail the same way.
|
||||
FetchRequest.registerGetUrl(failedToFetch);
|
||||
globalThis.fetch = jest.fn(failedToFetch);
|
||||
});
|
||||
@@ -49,7 +54,7 @@ function refresh(signal) {
|
||||
wallets,
|
||||
RPC_URL,
|
||||
EXPLORER_URL,
|
||||
[],
|
||||
[TRACKED],
|
||||
"mainnet",
|
||||
signal,
|
||||
);
|
||||
@@ -60,6 +65,7 @@ test("a failure while the popup is open is reported", async () => {
|
||||
for (const label of [
|
||||
"ETH balance failed",
|
||||
"ENS reverse failed",
|
||||
"token balance failed",
|
||||
"fetchTokenBalances failed: Failed to fetch",
|
||||
]) {
|
||||
expect(logged.some((line) => line.includes(label))).toBe(true);
|
||||
|
||||
Reference in New Issue
Block a user