summaryrefslogtreecommitdiffstats
path: root/src/rates.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-09-11 23:05:49 -0700
committerAdam Soltys <[email protected]>2026-09-11 23:05:49 -0700
commitd3234dfaf12dc3d7970c099fdc777a9b4ccc8e9d (patch)
tree87b3ad2bba95c5632a77d959d55ade3901dce76f /src/rates.js
parentc4677d7c5d66afe6ac5c7eb277cf8c3b2e08e62a (diff)
downloadcoinosv3-d3234dfaf12dc3d7970c099fdc777a9b4ccc8e9d.tar.gz
coinosv3-d3234dfaf12dc3d7970c099fdc777a9b4ccc8e9d.zip
Say the currency once, and stop hedging about old prices.
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) <[email protected]> Claude-Session: https://claude.ai/code/session_019mrt228Upn9nNCwGixzSLx
Diffstat (limited to 'src/rates.js')
-rw-r--r--src/rates.js17
1 files changed, 14 insertions, 3 deletions
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);