diff options
Diffstat (limited to 'src/app.js')
| -rw-r--r-- | src/app.js | 33 |
1 files changed, 20 insertions, 13 deletions
@@ -1248,8 +1248,13 @@ let unit = (() => { // been fetched — a third position showing blanks is worse than two that work. function toggleUnit() { const ring = haveRate() ? ['sats', 'btc', 'fiat'] : ['sats', 'btc']; + setUnit(ring[(ring.indexOf(unit) + 1) % ring.length]); + render(); +} +function setUnit(next) { + if (next === unit) return; const was = unit; - unit = ring[(ring.indexOf(unit) + 1) % ring.length]; + unit = next; try { localStorage.setItem(UNIT_KEY, unit); } catch {} @@ -1261,7 +1266,6 @@ function toggleUnit() { const sat = parseField(r.amount, was); if (sat) r.amount = amountField(sat); } - render(); } // A sats figure as the amount field types it in the current unit — what a @@ -6088,15 +6092,21 @@ function handleScanned(raw) { if (featureMatchSend(text)) return; if (/^bitcoin:/i.test(text)) { - const { address, amount } = parseBip21(text); + const { address, sats } = parseBip21(text); if (!address) { ui.sendError = t('scanUnrecognized'); render(); return; } s.recipients[0].address = address; - if (amount != null) { - s.recipients[0].amount = amount; + if (sats != null) { + // A request's amount is written in BTC, so the form shows it in BTC, + // whatever unit was chosen: with dollars selected the BTC figure used + // to land in the box as it was and read as that many dollars ("it + // should always switch over to BTC as the units if I'm scanning a + // BIP21 URL like that", Adam, 2026-11-22). + setUnit('btc'); + s.recipients[0].amount = amountField(sats); s.max = false; } render(); @@ -6121,21 +6131,18 @@ function handleScanned(raw) { render(); } -// bitcoin:<address>?amount=<btc>&label=... — amount is in BTC; convert to the -// current display unit so it lands in the form's amount field correctly. +// bitcoin:<address>?amount=<btc>&label=... — amount is in BTC; handed back +// in sats. function parseBip21(uri) { const m = /^bitcoin:([^?]*)(?:\?(.*))?$/i.exec(uri.trim()); if (!m) return {}; const address = decodeURIComponent((m[1] || '').trim()); - let amount = null; + let sats = null; if (m[2]) { const amt = new URLSearchParams(m[2]).get('amount'); - if (amt && isFinite(Number(amt)) && Number(amt) > 0) { - const sats = Math.round(Number(amt) * SATS); - amount = unit === 'sats' ? String(sats) : String(Number(amt)); - } + if (amt && isFinite(Number(amt)) && Number(amt) > 0) sats = Math.round(Number(amt) * SATS); } - return { address, amount }; + return { address, sats }; } function broadcastConfirmView() { |
