Compare commits
1 Commits
33070cae75
...
e0886c97e0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e0886c97e0 |
@@ -2,15 +2,12 @@
|
|||||||
// Handles EIP-1193 RPC requests from content scripts and proxies
|
// Handles EIP-1193 RPC requests from content scripts and proxies
|
||||||
// non-sensitive calls to the configured Ethereum JSON-RPC endpoint.
|
// non-sensitive calls to the configured Ethereum JSON-RPC endpoint.
|
||||||
|
|
||||||
const { DEFAULT_RPC_URL } = require("../shared/constants");
|
|
||||||
const { SUPPORTED_CHAIN_IDS, networkByChainId } = require("../shared/networks");
|
|
||||||
const { getBytes } = require("ethers");
|
|
||||||
const {
|
const {
|
||||||
state,
|
ETHEREUM_MAINNET_CHAIN_ID,
|
||||||
loadState,
|
DEFAULT_RPC_URL,
|
||||||
saveState,
|
} = require("../shared/constants");
|
||||||
currentNetwork,
|
const { getBytes } = require("ethers");
|
||||||
} = require("../shared/state");
|
const { state, loadState, saveState } = require("../shared/state");
|
||||||
const { refreshBalances, getProvider } = require("../shared/balances");
|
const { refreshBalances, getProvider } = require("../shared/balances");
|
||||||
const { debugFetch } = require("../shared/log");
|
const { debugFetch } = require("../shared/log");
|
||||||
const { decryptWithPassword } = require("../shared/vault");
|
const { decryptWithPassword } = require("../shared/vault");
|
||||||
@@ -332,47 +329,31 @@ async function handleRpc(method, params, origin) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (method === "eth_chainId") {
|
if (method === "eth_chainId") {
|
||||||
return { result: currentNetwork().chainId };
|
return { result: ETHEREUM_MAINNET_CHAIN_ID };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (method === "net_version") {
|
if (method === "net_version") {
|
||||||
return { result: currentNetwork().networkVersion };
|
return { result: "1" };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (method === "wallet_switchEthereumChain") {
|
if (method === "wallet_switchEthereumChain") {
|
||||||
const chainId = params?.[0]?.chainId;
|
const chainId = params?.[0]?.chainId;
|
||||||
if (chainId === currentNetwork().chainId) {
|
if (chainId === ETHEREUM_MAINNET_CHAIN_ID) {
|
||||||
return { result: null };
|
|
||||||
}
|
|
||||||
if (SUPPORTED_CHAIN_IDS.has(chainId)) {
|
|
||||||
// Switch to the requested network
|
|
||||||
const target = networkByChainId(chainId);
|
|
||||||
state.networkId = target.id;
|
|
||||||
state.rpcUrl = target.defaultRpcUrl;
|
|
||||||
state.blockscoutUrl = target.defaultBlockscoutUrl;
|
|
||||||
await saveState();
|
|
||||||
broadcastChainChanged(target.chainId);
|
|
||||||
return { result: null };
|
return { result: null };
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
error: {
|
error: {
|
||||||
code: 4902,
|
code: 4902,
|
||||||
message:
|
message: "AutistMask only supports Ethereum mainnet.",
|
||||||
"AutistMask supports Ethereum Mainnet and Sepolia Testnet only.",
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (method === "wallet_addEthereumChain") {
|
if (method === "wallet_addEthereumChain") {
|
||||||
const chainId = params?.[0]?.chainId;
|
|
||||||
if (SUPPORTED_CHAIN_IDS.has(chainId)) {
|
|
||||||
return { result: null };
|
|
||||||
}
|
|
||||||
return {
|
return {
|
||||||
error: {
|
error: {
|
||||||
code: 4902,
|
code: 4902,
|
||||||
message:
|
message: "AutistMask only supports Ethereum mainnet.",
|
||||||
"AutistMask supports Ethereum Mainnet and Sepolia Testnet only.",
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -518,27 +499,6 @@ async function handleRpc(method, params, origin) {
|
|||||||
return { error: { message: "Unsupported method: " + method } };
|
return { error: { message: "Unsupported method: " + method } };
|
||||||
}
|
}
|
||||||
|
|
||||||
// Broadcast chainChanged to all tabs when the network is switched.
|
|
||||||
function broadcastChainChanged(chainId) {
|
|
||||||
tabsApi.query({}, (tabs) => {
|
|
||||||
for (const tab of tabs) {
|
|
||||||
tabsApi.sendMessage(
|
|
||||||
tab.id,
|
|
||||||
{
|
|
||||||
type: "AUTISTMASK_EVENT",
|
|
||||||
eventName: "chainChanged",
|
|
||||||
data: chainId,
|
|
||||||
},
|
|
||||||
() => {
|
|
||||||
if (runtime.lastError) {
|
|
||||||
// expected for tabs without our content script
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Broadcast accountsChanged to all tabs, respecting per-address permissions
|
// Broadcast accountsChanged to all tabs, respecting per-address permissions
|
||||||
async function broadcastAccountsChanged() {
|
async function broadcastAccountsChanged() {
|
||||||
// Clear non-remembered approvals on address switch
|
// Clear non-remembered approvals on address switch
|
||||||
|
|||||||
@@ -2,10 +2,7 @@
|
|||||||
// Creates window.ethereum (EIP-1193 provider) and announces via EIP-6963.
|
// Creates window.ethereum (EIP-1193 provider) and announces via EIP-6963.
|
||||||
|
|
||||||
(function () {
|
(function () {
|
||||||
// Defaults to mainnet; updated dynamically via eth_chainId on init and
|
const CHAIN_ID = "0x1"; // Ethereum mainnet
|
||||||
// chainChanged events from the extension.
|
|
||||||
let currentChainId = "0x1";
|
|
||||||
let currentNetworkVersion = "1";
|
|
||||||
|
|
||||||
const listeners = {};
|
const listeners = {};
|
||||||
let nextId = 1;
|
let nextId = 1;
|
||||||
@@ -31,12 +28,6 @@
|
|||||||
if (event.source !== window) return;
|
if (event.source !== window) return;
|
||||||
if (event.data?.type !== "AUTISTMASK_EVENT") return;
|
if (event.data?.type !== "AUTISTMASK_EVENT") return;
|
||||||
const { eventName, data } = event.data;
|
const { eventName, data } = event.data;
|
||||||
if (eventName === "chainChanged") {
|
|
||||||
currentChainId = data;
|
|
||||||
currentNetworkVersion = String(parseInt(data, 16));
|
|
||||||
provider.chainId = currentChainId;
|
|
||||||
provider.networkVersion = currentNetworkVersion;
|
|
||||||
}
|
|
||||||
emit(eventName, data);
|
emit(eventName, data);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -66,8 +57,8 @@
|
|||||||
const provider = {
|
const provider = {
|
||||||
isAutistMask: true,
|
isAutistMask: true,
|
||||||
isMetaMask: true, // compatibility — many dApps check this
|
isMetaMask: true, // compatibility — many dApps check this
|
||||||
chainId: currentChainId,
|
chainId: CHAIN_ID,
|
||||||
networkVersion: currentNetworkVersion,
|
networkVersion: "1",
|
||||||
selectedAddress: null,
|
selectedAddress: null,
|
||||||
|
|
||||||
async request(args) {
|
async request(args) {
|
||||||
@@ -84,12 +75,6 @@
|
|||||||
? result[0]
|
? result[0]
|
||||||
: null;
|
: null;
|
||||||
}
|
}
|
||||||
if (args.method === "eth_chainId" && result) {
|
|
||||||
currentChainId = result;
|
|
||||||
currentNetworkVersion = String(parseInt(result, 16));
|
|
||||||
provider.chainId = currentChainId;
|
|
||||||
provider.networkVersion = currentNetworkVersion;
|
|
||||||
}
|
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -204,19 +189,4 @@
|
|||||||
|
|
||||||
window.addEventListener("eip6963:requestProvider", announceProvider);
|
window.addEventListener("eip6963:requestProvider", announceProvider);
|
||||||
announceProvider();
|
announceProvider();
|
||||||
|
|
||||||
// Fetch the current chain ID from the extension on load so the provider
|
|
||||||
// reflects the selected network immediately (covers Sepolia etc.).
|
|
||||||
sendRequest({ method: "eth_chainId", params: [] })
|
|
||||||
.then((chainId) => {
|
|
||||||
if (chainId) {
|
|
||||||
currentChainId = chainId;
|
|
||||||
currentNetworkVersion = String(parseInt(chainId, 16));
|
|
||||||
provider.chainId = currentChainId;
|
|
||||||
provider.networkVersion = currentNetworkVersion;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
// Best-effort — keep defaults.
|
|
||||||
});
|
|
||||||
})();
|
})();
|
||||||
|
|||||||
@@ -882,24 +882,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="bg-well p-3 mx-1 mb-3">
|
|
||||||
<h3 class="font-bold mb-1">Network</h3>
|
|
||||||
<p class="text-xs text-muted mb-1">
|
|
||||||
Select the Ethereum network. Switching networks will
|
|
||||||
update the RPC and Blockscout endpoints to their
|
|
||||||
defaults.
|
|
||||||
</p>
|
|
||||||
<div class="text-xs flex items-center gap-1">
|
|
||||||
<select
|
|
||||||
id="settings-network"
|
|
||||||
class="border border-border p-1 bg-bg text-fg text-xs cursor-pointer"
|
|
||||||
>
|
|
||||||
<option value="mainnet">Ethereum Mainnet</option>
|
|
||||||
<option value="sepolia">Sepolia Testnet</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="bg-well p-3 mx-1 mb-3">
|
<div class="bg-well p-3 mx-1 mb-3">
|
||||||
<h3 class="font-bold mb-1">Ethereum RPC</h3>
|
<h3 class="font-bold mb-1">Ethereum RPC</h3>
|
||||||
<p class="text-xs text-muted mb-1">
|
<p class="text-xs text-muted mb-1">
|
||||||
|
|||||||
@@ -8,9 +8,8 @@ const {
|
|||||||
renderAddressHtml,
|
renderAddressHtml,
|
||||||
attachCopyHandlers,
|
attachCopyHandlers,
|
||||||
} = require("./helpers");
|
} = require("./helpers");
|
||||||
const { state, saveState, currentNetwork } = require("../../shared/state");
|
const { state, saveState } = require("../../shared/state");
|
||||||
const { formatEther, formatUnits, Interface, toUtf8String } = require("ethers");
|
const { formatEther, formatUnits, Interface, toUtf8String } = require("ethers");
|
||||||
const { getPrice, formatUsd } = require("../../shared/prices");
|
|
||||||
const { ERC20_ABI } = require("../../shared/constants");
|
const { ERC20_ABI } = require("../../shared/constants");
|
||||||
const { TOKEN_BY_ADDRESS } = require("../../shared/tokenList");
|
const { TOKEN_BY_ADDRESS } = require("../../shared/tokenList");
|
||||||
const txStatus = require("./txStatus");
|
const txStatus = require("./txStatus");
|
||||||
@@ -220,14 +219,8 @@ function showTxApproval(details) {
|
|||||||
$("approve-tx-to").innerHTML = escapeHtml("(contract creation)");
|
$("approve-tx-to").innerHTML = escapeHtml("(contract creation)");
|
||||||
}
|
}
|
||||||
|
|
||||||
const ethValueFormatted = formatTxValue(
|
|
||||||
formatEther(details.txParams.value || "0"),
|
|
||||||
);
|
|
||||||
const ethPrice = getPrice("ETH");
|
|
||||||
const ethUsd = ethPrice ? parseFloat(ethValueFormatted) * ethPrice : null;
|
|
||||||
const usdStr = formatUsd(ethUsd);
|
|
||||||
$("approve-tx-value").textContent =
|
$("approve-tx-value").textContent =
|
||||||
ethValueFormatted + " ETH" + (usdStr ? " (" + usdStr + ")" : "");
|
formatTxValue(formatEther(details.txParams.value || "0")) + " ETH";
|
||||||
|
|
||||||
// Decode calldata (reuse decoded from above)
|
// Decode calldata (reuse decoded from above)
|
||||||
const decodedEl = $("approve-tx-decoded");
|
const decodedEl = $("approve-tx-decoded");
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ const {
|
|||||||
renderAddressHtml,
|
renderAddressHtml,
|
||||||
attachCopyHandlers,
|
attachCopyHandlers,
|
||||||
} = require("./helpers");
|
} = require("./helpers");
|
||||||
const { state, currentNetwork } = require("../../shared/state");
|
const { state } = require("../../shared/state");
|
||||||
const { getSignerForAddress } = require("../../shared/wallet");
|
const { getSignerForAddress } = require("../../shared/wallet");
|
||||||
const { decryptWithPassword } = require("../../shared/vault");
|
const { decryptWithPassword } = require("../../shared/vault");
|
||||||
const { formatUsd, getPrice } = require("../../shared/prices");
|
const { formatUsd, getPrice } = require("../../shared/prices");
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ const {
|
|||||||
getPrice,
|
getPrice,
|
||||||
getAddressValueUsd,
|
getAddressValueUsd,
|
||||||
} = require("../../shared/prices");
|
} = require("../../shared/prices");
|
||||||
const { state, saveState, currentNetwork } = require("../../shared/state");
|
const { state, saveState } = require("../../shared/state");
|
||||||
|
|
||||||
// When views are added, removed, or transitions between them change,
|
// When views are added, removed, or transitions between them change,
|
||||||
// update the view-navigation documentation in README.md to match.
|
// update the view-navigation documentation in README.md to match.
|
||||||
@@ -278,7 +278,7 @@ const EXT_ICON =
|
|||||||
`</svg></span>`;
|
`</svg></span>`;
|
||||||
|
|
||||||
function etherscanAddressUrl(address) {
|
function etherscanAddressUrl(address) {
|
||||||
return `${currentNetwork().explorerUrl}/address/${address}`;
|
return `https://etherscan.io/address/${address}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function etherscanLinkHtml(url) {
|
function etherscanLinkHtml(url) {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ const {
|
|||||||
addressTitle,
|
addressTitle,
|
||||||
attachCopyHandlers,
|
attachCopyHandlers,
|
||||||
} = require("./helpers");
|
} = require("./helpers");
|
||||||
const { state, currentAddress, currentNetwork } = require("../../shared/state");
|
const { state, currentAddress } = require("../../shared/state");
|
||||||
const QRCode = require("qrcode");
|
const QRCode = require("qrcode");
|
||||||
|
|
||||||
function show() {
|
function show() {
|
||||||
@@ -44,9 +44,7 @@ function show() {
|
|||||||
warningEl.textContent =
|
warningEl.textContent =
|
||||||
"This is an ERC-20 token. Only send " +
|
"This is an ERC-20 token. Only send " +
|
||||||
symbol +
|
symbol +
|
||||||
" on " +
|
" on the Ethereum network to this address. Sending tokens on other networks will result in permanent loss.";
|
||||||
currentNetwork().name +
|
|
||||||
" to this address. Sending tokens on other networks will result in permanent loss.";
|
|
||||||
warningEl.style.visibility = "visible";
|
warningEl.style.visibility = "visible";
|
||||||
} else {
|
} else {
|
||||||
warningEl.textContent = "";
|
warningEl.textContent = "";
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
const { $, showView, showFlash, escapeHtml } = require("./helpers");
|
const { $, showView, showFlash, escapeHtml } = require("./helpers");
|
||||||
const { applyTheme } = require("../theme");
|
const { applyTheme } = require("../theme");
|
||||||
const { state, saveState, currentNetwork } = require("../../shared/state");
|
const { state, saveState } = require("../../shared/state");
|
||||||
const { NETWORKS, SUPPORTED_CHAIN_IDS } = require("../../shared/networks");
|
const { ETHEREUM_MAINNET_CHAIN_ID } = require("../../shared/constants");
|
||||||
const { log, debugFetch } = require("../../shared/log");
|
const { log, debugFetch } = require("../../shared/log");
|
||||||
const deleteWallet = require("./deleteWallet");
|
const deleteWallet = require("./deleteWallet");
|
||||||
|
|
||||||
@@ -125,10 +125,6 @@ function renderWalletListSettings() {
|
|||||||
function show() {
|
function show() {
|
||||||
$("settings-rpc").value = state.rpcUrl;
|
$("settings-rpc").value = state.rpcUrl;
|
||||||
$("settings-blockscout").value = state.blockscoutUrl;
|
$("settings-blockscout").value = state.blockscoutUrl;
|
||||||
const networkSelect = $("settings-network");
|
|
||||||
if (networkSelect) {
|
|
||||||
networkSelect.value = state.networkId;
|
|
||||||
}
|
|
||||||
renderTrackedTokens();
|
renderTrackedTokens();
|
||||||
renderSiteLists();
|
renderSiteLists();
|
||||||
renderWalletListSettings();
|
renderWalletListSettings();
|
||||||
@@ -172,12 +168,9 @@ function init(ctx) {
|
|||||||
showFlash("Endpoint returned error: " + json.error.message);
|
showFlash("Endpoint returned error: " + json.error.message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const net = currentNetwork();
|
if (json.result !== ETHEREUM_MAINNET_CHAIN_ID) {
|
||||||
if (json.result !== net.chainId) {
|
|
||||||
showFlash(
|
showFlash(
|
||||||
"Wrong network (expected " +
|
"Wrong network (expected mainnet, got chain " +
|
||||||
net.name +
|
|
||||||
", got chain " +
|
|
||||||
json.result +
|
json.result +
|
||||||
").",
|
").",
|
||||||
);
|
);
|
||||||
@@ -216,22 +209,6 @@ function init(ctx) {
|
|||||||
showFlash("Saved.");
|
showFlash("Saved.");
|
||||||
});
|
});
|
||||||
|
|
||||||
const networkSelect = $("settings-network");
|
|
||||||
if (networkSelect) {
|
|
||||||
networkSelect.addEventListener("change", async () => {
|
|
||||||
const newId = networkSelect.value;
|
|
||||||
const net = NETWORKS[newId];
|
|
||||||
if (!net) return;
|
|
||||||
state.networkId = newId;
|
|
||||||
state.rpcUrl = net.defaultRpcUrl;
|
|
||||||
state.blockscoutUrl = net.defaultBlockscoutUrl;
|
|
||||||
$("settings-rpc").value = state.rpcUrl;
|
|
||||||
$("settings-blockscout").value = state.blockscoutUrl;
|
|
||||||
await saveState();
|
|
||||||
showFlash("Switched to " + net.name + ".");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
$("settings-show-zero-balances").checked = state.showZeroBalanceTokens;
|
$("settings-show-zero-balances").checked = state.showZeroBalanceTokens;
|
||||||
$("settings-show-zero-balances").addEventListener("change", async () => {
|
$("settings-show-zero-balances").addEventListener("change", async () => {
|
||||||
state.showZeroBalanceTokens = $("settings-show-zero-balances").checked;
|
state.showZeroBalanceTokens = $("settings-show-zero-balances").checked;
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ const {
|
|||||||
copyableHtml,
|
copyableHtml,
|
||||||
etherscanLinkHtml,
|
etherscanLinkHtml,
|
||||||
} = require("./helpers");
|
} = require("./helpers");
|
||||||
const { state, currentNetwork } = require("../../shared/state");
|
const { state } = require("../../shared/state");
|
||||||
const { formatEther, formatUnits } = require("ethers");
|
const { formatEther, formatUnits } = require("ethers");
|
||||||
const makeBlockie = require("ethereum-blockies-base64");
|
const makeBlockie = require("ethereum-blockies-base64");
|
||||||
const { log, debugFetch } = require("../../shared/log");
|
const { log, debugFetch } = require("../../shared/log");
|
||||||
@@ -56,7 +56,7 @@ function txAddressHtml(address, ensName, title) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function txHashHtml(hash) {
|
function txHashHtml(hash) {
|
||||||
const link = `${currentNetwork().explorerUrl}/tx/${hash}`;
|
const link = `https://etherscan.io/tx/${hash}`;
|
||||||
const extLink = etherscanLinkHtml(link);
|
const extLink = etherscanLinkHtml(link);
|
||||||
return copyableHtml(hash, "break-all") + extLink;
|
return copyableHtml(hash, "break-all") + extLink;
|
||||||
}
|
}
|
||||||
@@ -133,7 +133,7 @@ function render() {
|
|||||||
if (tokenContractSection && tokenContractEl) {
|
if (tokenContractSection && tokenContractEl) {
|
||||||
if (tx.contractAddress) {
|
if (tx.contractAddress) {
|
||||||
const dot = addressDotHtml(tx.contractAddress);
|
const dot = addressDotHtml(tx.contractAddress);
|
||||||
const link = `${currentNetwork().explorerUrl}/token/${tx.contractAddress}`;
|
const link = `https://etherscan.io/token/${tx.contractAddress}`;
|
||||||
tokenContractEl.innerHTML =
|
tokenContractEl.innerHTML =
|
||||||
`<div class="flex items-center">${dot}` +
|
`<div class="flex items-center">${dot}` +
|
||||||
copyableHtml(tx.contractAddress, "break-all") +
|
copyableHtml(tx.contractAddress, "break-all") +
|
||||||
@@ -185,7 +185,7 @@ function showDetailField(sectionId, contentId, value) {
|
|||||||
function populateOnChainDetails(txData) {
|
function populateOnChainDetails(txData) {
|
||||||
// Block number
|
// Block number
|
||||||
if (txData.block_number != null) {
|
if (txData.block_number != null) {
|
||||||
const blockLink = `${currentNetwork().explorerUrl}/block/${txData.block_number}`;
|
const blockLink = `https://etherscan.io/block/${txData.block_number}`;
|
||||||
const blockSection = $("tx-detail-block-section");
|
const blockSection = $("tx-detail-block-section");
|
||||||
const blockEl = $("tx-detail-block");
|
const blockEl = $("tx-detail-block");
|
||||||
if (blockSection && blockEl) {
|
if (blockSection && blockEl) {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ const {
|
|||||||
etherscanLinkHtml,
|
etherscanLinkHtml,
|
||||||
} = require("./helpers");
|
} = require("./helpers");
|
||||||
const { TOKEN_BY_ADDRESS } = require("../../shared/tokenList");
|
const { TOKEN_BY_ADDRESS } = require("../../shared/tokenList");
|
||||||
const { state, saveState, currentNetwork } = require("../../shared/state");
|
const { state, saveState } = require("../../shared/state");
|
||||||
const { getProvider } = require("../../shared/balances");
|
const { getProvider } = require("../../shared/balances");
|
||||||
const { log } = require("../../shared/log");
|
const { log } = require("../../shared/log");
|
||||||
|
|
||||||
@@ -36,13 +36,13 @@ function toAddressHtml(address) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function txHashHtml(hash) {
|
function txHashHtml(hash) {
|
||||||
const link = `${currentNetwork().explorerUrl}/tx/${hash}`;
|
const link = `https://etherscan.io/tx/${hash}`;
|
||||||
return copyableHtml(hash, "break-all") + etherscanLinkHtml(link);
|
return copyableHtml(hash, "break-all") + etherscanLinkHtml(link);
|
||||||
}
|
}
|
||||||
|
|
||||||
function blockNumberHtml(blockNumber) {
|
function blockNumberHtml(blockNumber) {
|
||||||
const num = String(blockNumber);
|
const num = String(blockNumber);
|
||||||
const link = `${currentNetwork().explorerUrl}/block/${num}`;
|
const link = `https://etherscan.io/block/${num}`;
|
||||||
return copyableHtml(num) + etherscanLinkHtml(link);
|
return copyableHtml(num) + etherscanLinkHtml(link);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,7 +110,7 @@ function tokenLabel(address) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function etherscanTokenLink(address) {
|
function etherscanTokenLink(address) {
|
||||||
return `${currentNetwork().explorerUrl}/token/${address}`;
|
return `https://etherscan.io/token/${address}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function decodedDetailsHtml(decoded) {
|
function decodedDetailsHtml(decoded) {
|
||||||
|
|||||||
@@ -15,15 +15,10 @@ const { KNOWN_SYMBOLS, TOKEN_BY_ADDRESS } = require("./tokenList");
|
|||||||
|
|
||||||
// Use a static network to skip auto-detection (which can fail and cause
|
// Use a static network to skip auto-detection (which can fail and cause
|
||||||
// "could not coalesce error" on some RPC endpoints like Cloudflare).
|
// "could not coalesce error" on some RPC endpoints like Cloudflare).
|
||||||
// Accepts an optional networkName ("mainnet" or "sepolia") for the static
|
const mainnet = Network.from("mainnet");
|
||||||
// network hint so ethers picks the right chain parameters. When omitted,
|
|
||||||
// reads the currently selected network from extension state.
|
function getProvider(rpcUrl) {
|
||||||
function getProvider(rpcUrl, networkName) {
|
return new JsonRpcProvider(rpcUrl, mainnet, { staticNetwork: mainnet });
|
||||||
// Lazy require to avoid circular dependency issues at module scope.
|
|
||||||
const { currentNetwork } = require("./state");
|
|
||||||
const name = networkName || currentNetwork().id;
|
|
||||||
const net = Network.from(name);
|
|
||||||
return new JsonRpcProvider(rpcUrl, net, { staticNetwork: net });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatBalance(wei) {
|
function formatBalance(wei) {
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ const DEBUG_MNEMONIC =
|
|||||||
"cube evolve unfold result inch risk jealous skill hotel bulb night wreck";
|
"cube evolve unfold result inch risk jealous skill hotel bulb night wreck";
|
||||||
|
|
||||||
const ETHEREUM_MAINNET_CHAIN_ID = "0x1";
|
const ETHEREUM_MAINNET_CHAIN_ID = "0x1";
|
||||||
const ETHEREUM_SEPOLIA_CHAIN_ID = "0xaa36a7";
|
|
||||||
|
|
||||||
const DEFAULT_RPC_URL = "https://ethereum-rpc.publicnode.com";
|
const DEFAULT_RPC_URL = "https://ethereum-rpc.publicnode.com";
|
||||||
|
|
||||||
@@ -38,7 +37,6 @@ module.exports = {
|
|||||||
DEBUG,
|
DEBUG,
|
||||||
DEBUG_MNEMONIC,
|
DEBUG_MNEMONIC,
|
||||||
ETHEREUM_MAINNET_CHAIN_ID,
|
ETHEREUM_MAINNET_CHAIN_ID,
|
||||||
ETHEREUM_SEPOLIA_CHAIN_ID,
|
|
||||||
DEFAULT_RPC_URL,
|
DEFAULT_RPC_URL,
|
||||||
DEFAULT_BLOCKSCOUT_URL,
|
DEFAULT_BLOCKSCOUT_URL,
|
||||||
BIP44_ETH_PATH,
|
BIP44_ETH_PATH,
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
// Extension users make the requests directly to Etherscan — no proxy needed.
|
// Extension users make the requests directly to Etherscan — no proxy needed.
|
||||||
// This is a best-effort enrichment: network failures return null silently.
|
// This is a best-effort enrichment: network failures return null silently.
|
||||||
|
|
||||||
|
const ETHERSCAN_BASE = "https://etherscan.io/address/";
|
||||||
|
|
||||||
// Patterns in the page title that indicate a flagged address.
|
// Patterns in the page title that indicate a flagged address.
|
||||||
// Title format: "Fake_Phishing184810 | Address: 0x... | Etherscan"
|
// Title format: "Fake_Phishing184810 | Address: 0x... | Etherscan"
|
||||||
const PHISHING_LABEL_PATTERNS = [/^Fake_Phishing/i, /^Phish:/i, /^Exploiter/i];
|
const PHISHING_LABEL_PATTERNS = [/^Fake_Phishing/i, /^Phish:/i, /^Exploiter/i];
|
||||||
@@ -72,19 +74,12 @@ function parseEtherscanPage(html) {
|
|||||||
* Returns a warning object if the address is flagged, or null.
|
* Returns a warning object if the address is flagged, or null.
|
||||||
* Network failures return null silently (best-effort check).
|
* Network failures return null silently (best-effort check).
|
||||||
*
|
*
|
||||||
* Uses the current network's explorer URL so the lookup works on both
|
|
||||||
* mainnet (etherscan.io) and Sepolia (sepolia.etherscan.io).
|
|
||||||
*
|
|
||||||
* @param {string} address - Ethereum address to check.
|
* @param {string} address - Ethereum address to check.
|
||||||
* @returns {Promise<{type: string, message: string, severity: string}|null>}
|
* @returns {Promise<{type: string, message: string, severity: string}|null>}
|
||||||
*/
|
*/
|
||||||
async function checkEtherscanLabel(address) {
|
async function checkEtherscanLabel(address) {
|
||||||
try {
|
try {
|
||||||
// Lazy require to avoid pulling in chrome.storage at module scope
|
const resp = await fetch(ETHERSCAN_BASE + address, {
|
||||||
// (which breaks unit tests that only exercise parseEtherscanPage).
|
|
||||||
const { currentNetwork } = require("./state");
|
|
||||||
const etherscanBase = currentNetwork().explorerUrl + "/address/";
|
|
||||||
const resp = await fetch(etherscanBase + address, {
|
|
||||||
headers: { Accept: "text/html" },
|
headers: { Accept: "text/html" },
|
||||||
});
|
});
|
||||||
if (!resp.ok) return null;
|
if (!resp.ok) return null;
|
||||||
|
|||||||
@@ -1,57 +0,0 @@
|
|||||||
// Network definitions for supported Ethereum networks.
|
|
||||||
// Each network specifies its chain ID, default RPC and Blockscout endpoints,
|
|
||||||
// and the block explorer base URL used for address/tx/token/block links.
|
|
||||||
|
|
||||||
const NETWORKS = {
|
|
||||||
mainnet: {
|
|
||||||
id: "mainnet",
|
|
||||||
name: "Ethereum Mainnet",
|
|
||||||
chainId: "0x1",
|
|
||||||
networkVersion: "1",
|
|
||||||
nativeCurrency: "ETH",
|
|
||||||
defaultRpcUrl: "https://ethereum-rpc.publicnode.com",
|
|
||||||
defaultBlockscoutUrl: "https://eth.blockscout.com/api/v2",
|
|
||||||
explorerUrl: "https://etherscan.io",
|
|
||||||
isTestnet: false,
|
|
||||||
},
|
|
||||||
sepolia: {
|
|
||||||
id: "sepolia",
|
|
||||||
name: "Sepolia Testnet",
|
|
||||||
chainId: "0xaa36a7",
|
|
||||||
networkVersion: "11155111",
|
|
||||||
nativeCurrency: "SepoliaETH",
|
|
||||||
defaultRpcUrl: "https://ethereum-sepolia-rpc.publicnode.com",
|
|
||||||
defaultBlockscoutUrl: "https://eth-sepolia.blockscout.com/api/v2",
|
|
||||||
explorerUrl: "https://sepolia.etherscan.io",
|
|
||||||
isTestnet: true,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const SUPPORTED_CHAIN_IDS = new Set(
|
|
||||||
Object.values(NETWORKS).map((n) => n.chainId),
|
|
||||||
);
|
|
||||||
|
|
||||||
function networkById(id) {
|
|
||||||
return NETWORKS[id] || NETWORKS.mainnet;
|
|
||||||
}
|
|
||||||
|
|
||||||
function networkByChainId(chainId) {
|
|
||||||
for (const net of Object.values(NETWORKS)) {
|
|
||||||
if (net.chainId === chainId) return net;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build a block explorer link for the given path type and value.
|
|
||||||
// type: "address" | "tx" | "token" | "block"
|
|
||||||
function explorerLink(network, type, value) {
|
|
||||||
return `${network.explorerUrl}/${type}/${value}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
NETWORKS,
|
|
||||||
SUPPORTED_CHAIN_IDS,
|
|
||||||
networkById,
|
|
||||||
networkByChainId,
|
|
||||||
explorerLink,
|
|
||||||
};
|
|
||||||
@@ -8,9 +8,6 @@ const prices = {};
|
|||||||
let lastFetchedAt = 0;
|
let lastFetchedAt = 0;
|
||||||
|
|
||||||
async function refreshPrices() {
|
async function refreshPrices() {
|
||||||
// Testnet tokens have no real market value — skip price fetching.
|
|
||||||
const { currentNetwork } = require("./state");
|
|
||||||
if (currentNetwork().isTestnet) return;
|
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
if (now - lastFetchedAt < PRICE_CACHE_TTL) return;
|
if (now - lastFetchedAt < PRICE_CACHE_TTL) return;
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
// State management and extension storage persistence.
|
// State management and extension storage persistence.
|
||||||
|
|
||||||
const { DEFAULT_RPC_URL, DEFAULT_BLOCKSCOUT_URL } = require("./constants");
|
const { DEFAULT_RPC_URL, DEFAULT_BLOCKSCOUT_URL } = require("./constants");
|
||||||
const { networkById } = require("./networks");
|
|
||||||
|
|
||||||
const storageApi =
|
const storageApi =
|
||||||
typeof browser !== "undefined"
|
typeof browser !== "undefined"
|
||||||
@@ -12,7 +11,6 @@ const DEFAULT_STATE = {
|
|||||||
hasWallet: false,
|
hasWallet: false,
|
||||||
wallets: [],
|
wallets: [],
|
||||||
trackedTokens: [],
|
trackedTokens: [],
|
||||||
networkId: "mainnet",
|
|
||||||
rpcUrl: DEFAULT_RPC_URL,
|
rpcUrl: DEFAULT_RPC_URL,
|
||||||
blockscoutUrl: DEFAULT_BLOCKSCOUT_URL,
|
blockscoutUrl: DEFAULT_BLOCKSCOUT_URL,
|
||||||
lastBalanceRefresh: 0,
|
lastBalanceRefresh: 0,
|
||||||
@@ -40,17 +38,11 @@ const state = {
|
|||||||
viewData: {},
|
viewData: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
// Return the network configuration for the currently selected network.
|
|
||||||
function currentNetwork() {
|
|
||||||
return networkById(state.networkId);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function saveState() {
|
async function saveState() {
|
||||||
const persisted = {
|
const persisted = {
|
||||||
hasWallet: state.hasWallet,
|
hasWallet: state.hasWallet,
|
||||||
wallets: state.wallets,
|
wallets: state.wallets,
|
||||||
trackedTokens: state.trackedTokens,
|
trackedTokens: state.trackedTokens,
|
||||||
networkId: state.networkId,
|
|
||||||
rpcUrl: state.rpcUrl,
|
rpcUrl: state.rpcUrl,
|
||||||
blockscoutUrl: state.blockscoutUrl,
|
blockscoutUrl: state.blockscoutUrl,
|
||||||
lastBalanceRefresh: state.lastBalanceRefresh,
|
lastBalanceRefresh: state.lastBalanceRefresh,
|
||||||
@@ -83,7 +75,6 @@ async function loadState() {
|
|||||||
state.hasWallet = saved.hasWallet;
|
state.hasWallet = saved.hasWallet;
|
||||||
state.wallets = saved.wallets || [];
|
state.wallets = saved.wallets || [];
|
||||||
state.trackedTokens = saved.trackedTokens || [];
|
state.trackedTokens = saved.trackedTokens || [];
|
||||||
state.networkId = saved.networkId || DEFAULT_STATE.networkId;
|
|
||||||
state.rpcUrl = saved.rpcUrl || DEFAULT_STATE.rpcUrl;
|
state.rpcUrl = saved.rpcUrl || DEFAULT_STATE.rpcUrl;
|
||||||
state.blockscoutUrl =
|
state.blockscoutUrl =
|
||||||
saved.blockscoutUrl || DEFAULT_STATE.blockscoutUrl;
|
saved.blockscoutUrl || DEFAULT_STATE.blockscoutUrl;
|
||||||
@@ -143,10 +134,4 @@ function currentAddress() {
|
|||||||
return state.wallets[state.selectedWallet].addresses[state.selectedAddress];
|
return state.wallets[state.selectedWallet].addresses[state.selectedAddress];
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = { state, saveState, loadState, currentAddress };
|
||||||
state,
|
|
||||||
saveState,
|
|
||||||
loadState,
|
|
||||||
currentAddress,
|
|
||||||
currentNetwork,
|
|
||||||
};
|
|
||||||
|
|||||||
Reference in New Issue
Block a user