aboutsummaryrefslogtreecommitdiffstats
path: root/src/format.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-09-11 22:55:14 -0700
committerAdam Soltys <[email protected]>2026-09-11 22:55:14 -0700
commite9a0aa2ca4d3aa659b579295dd983decd3729b6f (patch)
treeb237a05408a451aedd2d86be0fdda04040a37aaf /src/format.js
parentefaa9a6d0525e5fab18bb1c97da5685107506eff (diff)
downloadcoinosv3-e9a0aa2ca4d3aa659b579295dd983decd3729b6f.tar.gz
coinosv3-e9a0aa2ca4d3aa659b579295dd983decd3729b6f.zip
Every payment remembers what it was worth.
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) <[email protected]> Claude-Session: https://claude.ai/code/session_019mrt228Upn9nNCwGixzSLx
Diffstat (limited to 'src/format.js')
-rw-r--r--src/format.js10
1 files changed, 7 insertions, 3 deletions
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) {