Truncate addresses by 2 chars to compensate for color dot width
Some checks failed
check / check (push) Has been cancelled

Move truncateMiddle to helpers.js for reuse. Shorten displayed addresses
by 2 characters wherever a dot is shown: home view (40 char max), tx list
(maxAddr - 2), and address detail container (40ch width).
This commit is contained in:
2026-02-26 03:29:09 +07:00
parent 138468287c
commit 166bb46149
4 changed files with 13 additions and 10 deletions

View File

@@ -4,6 +4,7 @@ const {
showFlash,
balanceLinesForAddress,
addressDotHtml,
truncateMiddle,
} = require("./helpers");
const { state, currentAddress } = require("../../shared/state");
const { formatUsd, getAddressValueUsd } = require("../../shared/prices");
@@ -74,13 +75,6 @@ function timeAgo(timestamp) {
return years + " year" + (years !== 1 ? "s" : "") + " ago";
}
function truncateMiddle(str, maxLen) {
if (str.length <= maxLen) return str;
if (maxLen < 5) return str.slice(0, maxLen);
const half = Math.floor((maxLen - 1) / 2);
return str.slice(0, half) + "\u2026" + str.slice(-(maxLen - 1 - half));
}
function escapeHtml(s) {
const div = document.createElement("div");
div.textContent = s;
@@ -135,7 +129,7 @@ function renderTransactions(txs) {
const ensName = ensNameMap.get(counterparty) || null;
const dirLabel = tx.direction === "sent" ? "Sent" : "Received";
const amountStr = escapeHtml(tx.value + " " + tx.symbol);
const maxAddr = Math.max(10, 38 - Math.max(0, amountStr.length - 10));
const maxAddr = Math.max(10, 36 - Math.max(0, amountStr.length - 10));
const displayAddr = ensName || truncateMiddle(counterparty, maxAddr);
const addrStr = escapeHtml(displayAddr);
const dot = addressDotHtml(counterparty);