aboutsummaryrefslogtreecommitdiffstats
path: root/src/app.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/app.js')
-rw-r--r--src/app.js12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/app.js b/src/app.js
index 1e77849..122ccfe 100644
--- a/src/app.js
+++ b/src/app.js
@@ -1151,6 +1151,16 @@ function toggleUnit() {
render();
}
+// A sats figure as the amount field types it in the current unit — what a
+// Max button or a fixed-amount invoice fills in. Fiat is floored to the
+// cent so a filled-in maximum never parses back to more than was offered.
+function amountField(sat) {
+ if (unit === 'sats') return String(sat);
+ const r = unit === 'fiat' && rateNow();
+ if (r) return (Math.floor((sat / 1e8) * r * 100) / 100).toFixed(2);
+ return (sat / 1e8).toFixed(8);
+}
+
const unitLabel = () => (unit === 'sats' ? 'sats' : unit === 'fiat' ? getCurrency() : 'BTC');
// "Worth X then · Y now" for a payment's detail page — the one place both
@@ -5951,7 +5961,7 @@ const ctx = {
openWalletSettings: (view) => openWalletSettings(view),
// one page of the Settings hub, from anywhere (Notifications' gear)
openSettingsPage: (page) => { clearFeatureNav(); ui.screen = 'wallet'; ui.tab = 'settings'; ui.settingsPage = page; render(); try { window.scrollTo(0, 0); } catch {} },
- fmtAmount, unitLabel, unitTag, getUnit: () => unit, toggleUnit, download,
+ fmtAmount, unitLabel, unitTag, getUnit: () => unit, toggleUnit, download, amountField,
// in fiat the typed figure is money, so it needs today's price to become sats
parseAmount: (v, u) => parseAmount(v, u, rateNow()),
worthLine,