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

@@ -207,7 +207,7 @@
<span id="address-dot"></span> <span id="address-dot"></span>
<span <span
id="address-full" id="address-full"
style="width: 42ch; max-width: 100%" style="width: 40ch; max-width: 100%"
></span> ></span>
<span <span
id="address-usd-total" id="address-usd-total"

View File

@@ -4,6 +4,7 @@ const {
showFlash, showFlash,
balanceLinesForAddress, balanceLinesForAddress,
addressDotHtml, addressDotHtml,
truncateMiddle,
} = require("./helpers"); } = require("./helpers");
const { state, currentAddress } = require("../../shared/state"); const { state, currentAddress } = require("../../shared/state");
const { formatUsd, getAddressValueUsd } = require("../../shared/prices"); const { formatUsd, getAddressValueUsd } = require("../../shared/prices");
@@ -74,13 +75,6 @@ function timeAgo(timestamp) {
return years + " year" + (years !== 1 ? "s" : "") + " ago"; 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) { function escapeHtml(s) {
const div = document.createElement("div"); const div = document.createElement("div");
div.textContent = s; div.textContent = s;
@@ -135,7 +129,7 @@ function renderTransactions(txs) {
const ensName = ensNameMap.get(counterparty) || null; const ensName = ensNameMap.get(counterparty) || null;
const dirLabel = tx.direction === "sent" ? "Sent" : "Received"; const dirLabel = tx.direction === "sent" ? "Sent" : "Received";
const amountStr = escapeHtml(tx.value + " " + tx.symbol); 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 displayAddr = ensName || truncateMiddle(counterparty, maxAddr);
const addrStr = escapeHtml(displayAddr); const addrStr = escapeHtml(displayAddr);
const dot = addressDotHtml(counterparty); const dot = addressDotHtml(counterparty);

View File

@@ -99,6 +99,13 @@ function balanceLinesForAddress(addr) {
return html; return html;
} }
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));
}
// 16 colors evenly spaced around the hue wheel (22.5° apart), // 16 colors evenly spaced around the hue wheel (22.5° apart),
// all at HSL saturation 70%, lightness 50% for uniform vibrancy. // all at HSL saturation 70%, lightness 50% for uniform vibrancy.
const ADDRESS_COLORS = [ const ADDRESS_COLORS = [
@@ -139,4 +146,5 @@ module.exports = {
balanceLinesForAddress, balanceLinesForAddress,
addressColor, addressColor,
addressDotHtml, addressDotHtml,
truncateMiddle,
}; };

View File

@@ -4,6 +4,7 @@ const {
showFlash, showFlash,
balanceLinesForAddress, balanceLinesForAddress,
addressDotHtml, addressDotHtml,
truncateMiddle,
} = require("./helpers"); } = require("./helpers");
const { state, saveState } = require("../../shared/state"); const { state, saveState } = require("../../shared/state");
const { deriveAddressFromXpub } = require("../../shared/wallet"); const { deriveAddressFromXpub } = require("../../shared/wallet");
@@ -47,7 +48,7 @@ function render(ctx) {
} }
const addrUsd = formatUsd(getAddressValueUsd(addr)); const addrUsd = formatUsd(getAddressValueUsd(addr));
html += `<div class="flex text-xs">`; html += `<div class="flex text-xs">`;
html += `<span class="flex items-center" style="width:42ch;max-width:100%">${addr.ensName ? "" : dot}${addr.address}</span>`; html += `<span class="flex items-center" style="width:42ch;max-width:100%">${addr.ensName ? "" : dot}${truncateMiddle(addr.address, 40)}</span>`;
html += `<span class="text-right text-muted flex-1">${addrUsd}</span>`; html += `<span class="text-right text-muted flex-1">${addrUsd}</span>`;
html += `</div>`; html += `</div>`;
html += balanceLinesForAddress(addr); html += balanceLinesForAddress(addr);