From d3234dfaf12dc3d7970c099fdc777a9b4ccc8e9d Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Fri, 11 Sep 2026 23:05:49 -0700 Subject: Say the currency once, and stop hedging about old prices. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The balance read "US$74.67 USD" — the symbol and the unit tag saying the same thing twice. Amounts now format bare, like sats and BTC do: whatever labels the number says which money it is. The currency symbol stays where a number stands alone in prose, which is the "Worth then" line and nowhere else. The '~' marking a payment older than any price we sampled is gone too. It was bookkeeping the beta doesn't need: a payment we have a price for is shown at that price, one we don't is shown at today's, and nobody has to learn a squiggle. The currency picker has moved to sit beside the language picker at the foot of the page — display preferences together, where they're findable. It spent one day under Settings → Network, where it wasn't. And a bug this feature exposed rather than caused: nine notices end in the word "sats" in every language we ship, and were being handed the display unit. "Uncooperative exit costs about US$2.03 sats" — and long before fiat, "about 0.00435397 sats" for anyone in BTC. They're given sats now, which is what they claim to be showing. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_019mrt228Upn9nNCwGixzSLx --- src/rates.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src/rates.js') diff --git a/src/rates.js b/src/rates.js index bc32bd7..19b3512 100644 --- a/src/rates.js +++ b/src/rates.js @@ -116,13 +116,24 @@ export async function refreshRates({ force = false } = {}) { // it does — a third position that shows blanks is worse than two that work. export const haveRate = () => rateNow() != null; +// Two shapes. `fmtFiat` carries its own currency symbol, for a line of prose +// that has to say what the number is. `fmtFiatBare` is just the number, for +// the places where the unit is already spelled out beside it — a balance +// under its USD tag reading "US$74.67 USD" says it twice. export function fmtFiat(sats, rate, code = getCurrency()) { if (!rate) return ''; const v = (Number(sats) / 100_000_000) * rate; - const digits = Math.abs(v) < 1 && v !== 0 ? 4 : 2; try { - return v.toLocaleString(undefined, { style: 'currency', currency: code, maximumFractionDigits: digits, minimumFractionDigits: 2 }); + return v.toLocaleString(undefined, { style: 'currency', currency: code, maximumFractionDigits: fiatDigits(v), minimumFractionDigits: 2 }); } catch { - return v.toFixed(digits) + ' ' + code; // a code Intl doesn't know + return fmtFiatBare(sats, rate) + ' ' + code; // a code Intl doesn't know } } +export function fmtFiatBare(sats, rate) { + if (!rate) return ''; + const v = (Number(sats) / 100_000_000) * rate; + return v.toLocaleString(undefined, { maximumFractionDigits: fiatDigits(v), minimumFractionDigits: 2 }); +} +// Under a unit of currency, sats are small: a tenth of a cent still deserves +// to be a number rather than 0.00. +const fiatDigits = (v) => (Math.abs(v) < 1 && v !== 0 ? 4 : 2); -- cgit v1.2.3