Truncate addresses by 2 chars to compensate for color dot width
Some checks failed
check / check (push) Has been cancelled
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:
@@ -207,7 +207,7 @@
|
||||
<span id="address-dot"></span>
|
||||
<span
|
||||
id="address-full"
|
||||
style="width: 42ch; max-width: 100%"
|
||||
style="width: 40ch; max-width: 100%"
|
||||
></span>
|
||||
<span
|
||||
id="address-usd-total"
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -99,6 +99,13 @@ function balanceLinesForAddress(addr) {
|
||||
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),
|
||||
// all at HSL saturation 70%, lightness 50% for uniform vibrancy.
|
||||
const ADDRESS_COLORS = [
|
||||
@@ -139,4 +146,5 @@ module.exports = {
|
||||
balanceLinesForAddress,
|
||||
addressColor,
|
||||
addressDotHtml,
|
||||
truncateMiddle,
|
||||
};
|
||||
|
||||
@@ -4,6 +4,7 @@ const {
|
||||
showFlash,
|
||||
balanceLinesForAddress,
|
||||
addressDotHtml,
|
||||
truncateMiddle,
|
||||
} = require("./helpers");
|
||||
const { state, saveState } = require("../../shared/state");
|
||||
const { deriveAddressFromXpub } = require("../../shared/wallet");
|
||||
@@ -47,7 +48,7 @@ function render(ctx) {
|
||||
}
|
||||
const addrUsd = formatUsd(getAddressValueUsd(addr));
|
||||
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 += `</div>`;
|
||||
html += balanceLinesForAddress(addr);
|
||||
|
||||
Reference in New Issue
Block a user