All checks were successful
check / check (push) Successful in 9s
## Summary Adds Sepolia testnet support to AutistMask. ### Changes - **New `src/shared/networks.js`** — centralized network definitions (mainnet + Sepolia) with chain IDs, default RPC/Blockscout endpoints, and block explorer URLs - **State management** — `networkId` added to persisted state; defaults to mainnet for backward compatibility - **Settings UI** — network selector dropdown lets users switch between Ethereum Mainnet and Sepolia Testnet - **Dynamic explorer links** — all hardcoded `etherscan.io` URLs replaced with dynamic links from the current network config (`sepolia.etherscan.io` for Sepolia) - **Background service** — `wallet_switchEthereumChain` now accepts both mainnet (0x1) and Sepolia (0xaa36a7); broadcasts `chainChanged` to connected dApps - **Inpage provider** — fetches chain ID on init and updates dynamically via `chainChanged` events (no more hardcoded `0x1`) - **Blockscout API** — uses `eth-sepolia.blockscout.com/api/v2` for Sepolia - **Etherscan labels** — phishing/scam checks use the correct explorer per network - **Price fetching** — skipped on testnets (testnet tokens have no real market value) - **RPC validation** — checks against the selected network's chain ID, not hardcoded mainnet - **ethers provider** — `getProvider()` uses the correct ethers `Network` for Sepolia ### API Endpoints Verified | Service | Mainnet | Sepolia | |---------|---------|--------| | Etherscan | etherscan.io | sepolia.etherscan.io | | Blockscout | eth.blockscout.com/api/v2 | eth-sepolia.blockscout.com/api/v2 | | RPC | ethereum-rpc.publicnode.com | ethereum-sepolia-rpc.publicnode.com | | CoinDesk (prices) | ✅ | N/A (skipped on testnet) | closes #110 Reviewed-on: #137 THIS WAS ONESHOTTED USING OPUS 4. WTAF Co-authored-by: clawbot <clawbot@noreply.example.org> Co-committed-by: clawbot <clawbot@noreply.example.org>
153 lines
5.2 KiB
JavaScript
153 lines
5.2 KiB
JavaScript
// State management and extension storage persistence.
|
|
|
|
const { DEFAULT_RPC_URL, DEFAULT_BLOCKSCOUT_URL } = require("./constants");
|
|
const { networkById } = require("./networks");
|
|
|
|
const storageApi =
|
|
typeof browser !== "undefined"
|
|
? browser.storage.local
|
|
: chrome.storage.local;
|
|
|
|
const DEFAULT_STATE = {
|
|
hasWallet: false,
|
|
wallets: [],
|
|
trackedTokens: [],
|
|
networkId: "mainnet",
|
|
rpcUrl: DEFAULT_RPC_URL,
|
|
blockscoutUrl: DEFAULT_BLOCKSCOUT_URL,
|
|
lastBalanceRefresh: 0,
|
|
activeAddress: null,
|
|
allowedSites: {},
|
|
deniedSites: {},
|
|
rememberSiteChoice: true,
|
|
showZeroBalanceTokens: true,
|
|
hideLowHolderTokens: true,
|
|
hideFraudContracts: true,
|
|
hideDustTransactions: true,
|
|
dustThresholdGwei: 100000,
|
|
utcTimestamps: false,
|
|
fraudContracts: [],
|
|
tokenHolderCache: {},
|
|
theme: "system",
|
|
};
|
|
|
|
const state = {
|
|
...DEFAULT_STATE,
|
|
currentView: null,
|
|
selectedWallet: null,
|
|
selectedAddress: null,
|
|
selectedToken: null,
|
|
viewData: {},
|
|
};
|
|
|
|
// Return the network configuration for the currently selected network.
|
|
function currentNetwork() {
|
|
return networkById(state.networkId);
|
|
}
|
|
|
|
async function saveState() {
|
|
const persisted = {
|
|
hasWallet: state.hasWallet,
|
|
wallets: state.wallets,
|
|
trackedTokens: state.trackedTokens,
|
|
networkId: state.networkId,
|
|
rpcUrl: state.rpcUrl,
|
|
blockscoutUrl: state.blockscoutUrl,
|
|
lastBalanceRefresh: state.lastBalanceRefresh,
|
|
activeAddress: state.activeAddress,
|
|
allowedSites: state.allowedSites,
|
|
deniedSites: state.deniedSites,
|
|
rememberSiteChoice: state.rememberSiteChoice,
|
|
showZeroBalanceTokens: state.showZeroBalanceTokens,
|
|
hideLowHolderTokens: state.hideLowHolderTokens,
|
|
hideFraudContracts: state.hideFraudContracts,
|
|
hideDustTransactions: state.hideDustTransactions,
|
|
dustThresholdGwei: state.dustThresholdGwei,
|
|
utcTimestamps: state.utcTimestamps,
|
|
fraudContracts: state.fraudContracts,
|
|
tokenHolderCache: state.tokenHolderCache,
|
|
theme: state.theme,
|
|
currentView: state.currentView,
|
|
selectedWallet: state.selectedWallet,
|
|
selectedAddress: state.selectedAddress,
|
|
selectedToken: state.selectedToken,
|
|
viewData: state.viewData,
|
|
};
|
|
await storageApi.set({ autistmask: persisted });
|
|
}
|
|
|
|
async function loadState() {
|
|
const result = await storageApi.get("autistmask");
|
|
if (result.autistmask) {
|
|
const saved = result.autistmask;
|
|
state.hasWallet = saved.hasWallet;
|
|
state.wallets = saved.wallets || [];
|
|
state.trackedTokens = saved.trackedTokens || [];
|
|
state.networkId = saved.networkId || DEFAULT_STATE.networkId;
|
|
state.rpcUrl = saved.rpcUrl || DEFAULT_STATE.rpcUrl;
|
|
state.blockscoutUrl =
|
|
saved.blockscoutUrl || DEFAULT_STATE.blockscoutUrl;
|
|
state.lastBalanceRefresh = saved.lastBalanceRefresh || 0;
|
|
state.activeAddress = saved.activeAddress || null;
|
|
state.allowedSites =
|
|
saved.allowedSites && !Array.isArray(saved.allowedSites)
|
|
? saved.allowedSites
|
|
: {};
|
|
state.deniedSites =
|
|
saved.deniedSites && !Array.isArray(saved.deniedSites)
|
|
? saved.deniedSites
|
|
: {};
|
|
state.rememberSiteChoice =
|
|
saved.rememberSiteChoice !== undefined
|
|
? saved.rememberSiteChoice
|
|
: true;
|
|
state.showZeroBalanceTokens =
|
|
saved.showZeroBalanceTokens !== undefined
|
|
? saved.showZeroBalanceTokens
|
|
: true;
|
|
state.hideLowHolderTokens =
|
|
saved.hideLowHolderTokens !== undefined
|
|
? saved.hideLowHolderTokens
|
|
: true;
|
|
state.hideFraudContracts =
|
|
saved.hideFraudContracts !== undefined
|
|
? saved.hideFraudContracts
|
|
: true;
|
|
state.hideDustTransactions =
|
|
saved.hideDustTransactions !== undefined
|
|
? saved.hideDustTransactions
|
|
: true;
|
|
state.dustThresholdGwei =
|
|
saved.dustThresholdGwei !== undefined
|
|
? saved.dustThresholdGwei
|
|
: 100000;
|
|
state.utcTimestamps =
|
|
saved.utcTimestamps !== undefined ? saved.utcTimestamps : false;
|
|
state.fraudContracts = saved.fraudContracts || [];
|
|
state.tokenHolderCache = saved.tokenHolderCache || {};
|
|
state.theme = saved.theme || "system";
|
|
state.currentView = saved.currentView || null;
|
|
state.selectedWallet =
|
|
saved.selectedWallet !== undefined ? saved.selectedWallet : null;
|
|
state.selectedAddress =
|
|
saved.selectedAddress !== undefined ? saved.selectedAddress : null;
|
|
state.selectedToken = saved.selectedToken || null;
|
|
state.viewData = saved.viewData || {};
|
|
}
|
|
}
|
|
|
|
function currentAddress() {
|
|
if (state.selectedWallet === null || state.selectedAddress === null) {
|
|
return null;
|
|
}
|
|
return state.wallets[state.selectedWallet].addresses[state.selectedAddress];
|
|
}
|
|
|
|
module.exports = {
|
|
state,
|
|
saveState,
|
|
loadState,
|
|
currentAddress,
|
|
currentNetwork,
|
|
};
|