diff --git a/src/popup/index.html b/src/popup/index.html
index 78528cd..a7ada43 100644
--- a/src/popup/index.html
+++ b/src/popup/index.html
@@ -166,6 +166,7 @@
+
diff --git a/src/popup/index.js b/src/popup/index.js
index e658f15..7f04280 100644
--- a/src/popup/index.js
+++ b/src/popup/index.js
@@ -138,14 +138,24 @@ async function refreshBalances() {
const updates = [];
for (const wallet of state.wallets) {
for (const addr of wallet.addresses) {
+ // Fetch ETH balance
updates.push(
provider
.getBalance(addr.address)
.then((bal) => {
addr.balance = formatBalance(bal);
})
+ .catch(() => {}),
+ );
+ // Reverse ENS lookup
+ updates.push(
+ provider
+ .lookupAddress(addr.address)
+ .then((name) => {
+ addr.ensName = name || null;
+ })
.catch(() => {
- // leave balance unchanged on error
+ addr.ensName = null;
}),
);
}
@@ -174,10 +184,15 @@ function renderWalletList() {
html += `
`;
wallet.addresses.forEach((addr, ai) => {
- html += ``;
+ html += `
`;
+ if (addr.ensName) {
+ html += `
${addr.ensName}
`;
+ }
+ html += `
`;
html += `${addr.address}`;
html += `${addr.balance} ETH`;
html += `
`;
+ html += `
`;
});
html += `
`;
@@ -221,6 +236,13 @@ function showAddressDetail() {
$("address-copied-msg").textContent = "";
$("address-eth-balance").textContent = addr.balance;
$("address-usd-value").textContent = "";
+ const ensEl = $("address-ens");
+ if (addr.ensName) {
+ ensEl.textContent = addr.ensName;
+ ensEl.classList.remove("hidden");
+ } else {
+ ensEl.classList.add("hidden");
+ }
updateTokenList(addr);
updateSendTokenSelect(addr);
showView("address");
@@ -442,7 +464,7 @@ async function init() {
});
// -- Send --
- $("btn-send-confirm").addEventListener("click", () => {
+ $("btn-send-confirm").addEventListener("click", async () => {
const to = $("send-to").value.trim();
const amount = $("send-amount").value.trim();
if (!to) {
@@ -455,9 +477,32 @@ async function init() {
$("send-status").classList.remove("hidden");
return;
}
+ // Resolve ENS name if it looks like one
+ let resolvedTo = to;
+ if (to.includes(".") && !to.startsWith("0x")) {
+ const statusEl = $("send-status");
+ statusEl.textContent = "Resolving " + to + "...";
+ statusEl.classList.remove("hidden");
+ try {
+ const provider = getProvider();
+ const resolved = await provider.resolveName(to);
+ if (!resolved) {
+ showError("send-status", "Could not resolve " + to);
+ return;
+ }
+ resolvedTo = resolved;
+ statusEl.textContent = to + " = " + resolvedTo;
+ } catch (e) {
+ showError("send-status", "Failed to resolve ENS name.");
+ return;
+ }
+ }
// TODO: prompt for password, decrypt key, construct and send transaction
const el = $("send-status");
- el.textContent = "Sent! (stub — password/signing not yet implemented)";
+ el.textContent =
+ "Sending to " +
+ resolvedTo +
+ " (stub — password/signing not yet implemented)";
el.classList.remove("hidden");
});