From e9a0aa2ca4d3aa659b579295dd983decd3729b6f Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Fri, 11 Sep 2026 22:55:14 -0700 Subject: Every payment remembers what it was worth. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A payment is worth what it was worth WHEN IT HAPPENED, and that number is gone by the time you look at it unless someone wrote it down. So every price the app fetches is kept as a sample — one an hour, a few months back — and a payment's fiat value is read off the sample nearest its own timestamp. The history rows and both detail pages (on-chain and Spending) pass the time the money moved; balances and forms use the live price, as they should. A payment older than any sample we hold is priced at today's number and says so with a '~', because that is a different claim and shouldn't look like the same one. The detail page spells it out: "Worth then $X · $Y now". Fiat is a third position on the unit toggle rather than a second number beside the first: sats → BTC → your money → sats. One figure, and which figure is your choice. The ring skips fiat entirely until a price has been fetched — a third position showing blanks is worse than two that work. Typing an amount with the unit on USD means dollars, priced now. The rates are coinos' own endpoint, a map of every currency it knows, so there's no third party watching what the wallet asks about; the currency picker under Settings → Network lists all of them. Changing it starts the recorded history again rather than relabelling samples taken in another currency. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_019mrt228Upn9nNCwGixzSLx --- src/format.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/format.js') diff --git a/src/format.js b/src/format.js index a7f49c2..febba22 100644 --- a/src/format.js +++ b/src/format.js @@ -39,11 +39,15 @@ export function fmtUsd(sats, price) { return usd.toLocaleString('en-US', { style: 'currency', currency: 'USD' }); } -// Parse a user-entered amount. Accepts BTC (default) or sats. -export function parseAmount(value, unit) { +// Parse a user-entered amount. Accepts BTC (default), sats, or — when the +// display unit is the user's own money and a rate is passed — that: typing 5 +// with the unit on USD means five dollars' worth, priced right now. +export function parseAmount(value, unit, rate = null) { const n = Number(String(value).trim().replace(/,/g, '')); if (!isFinite(n) || n < 0) return null; - return unit === 'sats' ? Math.round(n) : Math.round(n * SATS); + if (unit === 'sats') return Math.round(n); + if (unit === 'fiat') return rate ? Math.round((n / rate) * SATS) : null; + return Math.round(n * SATS); } export function shortAddr(a, head = 10, tail = 8) { -- cgit v1.2.3