Show active address ETH balance and USD value in headline
Some checks failed
check / check (push) Has been cancelled
Some checks failed
check / check (push) Has been cancelled
The headline now shows the active address's balance as "x.yyyy ETH ($z.aa USD)" instead of the sum across all wallets.
This commit is contained in:
@@ -12,14 +12,32 @@ const QRCode = require("qrcode");
|
|||||||
const { deriveAddressFromXpub } = require("../../shared/wallet");
|
const { deriveAddressFromXpub } = require("../../shared/wallet");
|
||||||
const {
|
const {
|
||||||
formatUsd,
|
formatUsd,
|
||||||
|
getPrice,
|
||||||
getAddressValueUsd,
|
getAddressValueUsd,
|
||||||
getTotalValueUsd,
|
|
||||||
} = require("../../shared/prices");
|
} = require("../../shared/prices");
|
||||||
|
|
||||||
|
function findActiveAddr() {
|
||||||
|
for (const w of state.wallets) {
|
||||||
|
for (const a of w.addresses) {
|
||||||
|
if (a.address === state.activeAddress) return a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
function renderTotalValue() {
|
function renderTotalValue() {
|
||||||
const el = $("total-value");
|
const el = $("total-value");
|
||||||
if (!el) return;
|
if (!el) return;
|
||||||
el.textContent = formatUsd(getTotalValueUsd(state.wallets));
|
const addr = findActiveAddr();
|
||||||
|
if (!addr) {
|
||||||
|
el.textContent = "";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const ethBal = parseFloat(addr.balance || "0");
|
||||||
|
const ethStr = ethBal.toFixed(4) + " ETH";
|
||||||
|
const usd = getAddressValueUsd(addr);
|
||||||
|
const usdStr = usd !== null ? " (" + formatUsd(usd) + " USD)" : "";
|
||||||
|
el.textContent = ethStr + usdStr;
|
||||||
}
|
}
|
||||||
|
|
||||||
const EXT_ICON =
|
const EXT_ICON =
|
||||||
|
|||||||
Reference in New Issue
Block a user