Skip to content

Commit 890768f

Browse files
Merge pull request #3455 from getAlby/subsat-amounts
feat: handle sub sat amounts
2 parents 0395dd6 + 4cc4337 commit 890768f

File tree

5 files changed

+18
-16
lines changed

5 files changed

+18
-16
lines changed

src/app/screens/ConfirmPayment/index.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,26 @@ function ConfirmPayment() {
3737
const paymentRequest = navState.args?.paymentRequest as string;
3838
const invoice = lightningPayReq.decode(paymentRequest);
3939

40+
const amountSat =
41+
invoice.satoshis || Number(invoice.millisatoshis) / 1000 || 0;
42+
4043
const navigate = useNavigate();
4144
const auth = useAccount();
4245

43-
const [budget, setBudget] = useState(
44-
((invoice.satoshis || 0) * 10).toString()
45-
);
46+
const [budget, setBudget] = useState((amountSat * 10).toString());
4647
const [fiatAmount, setFiatAmount] = useState("");
4748
const [fiatBudgetAmount, setFiatBudgetAmount] = useState("");
4849

49-
const formattedInvoiceSats = getFormattedSats(invoice.satoshis || 0);
50+
const formattedInvoiceSats = getFormattedSats(amountSat);
5051

5152
useEffect(() => {
5253
(async () => {
53-
if (showFiat && invoice.satoshis) {
54-
const res = await getFormattedFiat(invoice.satoshis);
54+
if (showFiat && amountSat !== 0) {
55+
const res = await getFormattedFiat(amountSat);
5556
setFiatAmount(res);
5657
}
5758
})();
58-
}, [invoice.satoshis, showFiat, getFormattedFiat]);
59+
}, [amountSat, showFiat, getFormattedFiat]);
5960

6061
useEffect(() => {
6162
(async () => {
@@ -150,7 +151,7 @@ function ConfirmPayment() {
150151
<div className="my-4">
151152
<div className="mb-4 p-4 shadow bg-white dark:bg-surface-02dp rounded-lg">
152153
<PaymentSummary
153-
amount={invoice.satoshis || "0"} // TODO: allow entering amount or do not allow zero-amount invoices
154+
amount={amountSat} // TODO: allow entering amount or do not allow zero-amount invoices
154155
fiatAmount={fiatAmount}
155156
description={invoice.tagsObject.description}
156157
/>

src/app/screens/ConfirmPaymentAsync/index.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,20 @@ function ConfirmPaymentAsync() {
3232
const navState = useNavigationState();
3333
const paymentRequest = navState.args?.paymentRequest as string;
3434
const invoice = lightningPayReq.decode(paymentRequest);
35-
35+
const amountSat =
36+
invoice.satoshis || Number(invoice.millisatoshis) / 1000 || 0;
3637
const navigate = useNavigate();
3738

3839
const [fiatAmount, setFiatAmount] = useState("");
3940

4041
useEffect(() => {
4142
(async () => {
42-
if (showFiat && invoice.satoshis) {
43-
const res = await getFormattedFiat(invoice.satoshis);
43+
if (showFiat && amountSat !== 0) {
44+
const res = await getFormattedFiat(amountSat);
4445
setFiatAmount(res);
4546
}
4647
})();
47-
}, [invoice.satoshis, showFiat, getFormattedFiat]);
48+
}, [amountSat, showFiat, getFormattedFiat]);
4849

4950
const [loading, setLoading] = useState(false);
5051

@@ -99,7 +100,7 @@ function ConfirmPaymentAsync() {
99100
<div className="my-4">
100101
<div className="mb-4 p-4 shadow bg-white dark:bg-surface-02dp rounded-lg">
101102
<PaymentSummary
102-
amount={invoice.satoshis || "0"} // TODO: allow entering amount or do not allow zero-amount invoices
103+
amount={amountSat} // TODO: allow entering amount or do not allow zero-amount invoices
103104
fiatAmount={fiatAmount}
104105
description={invoice.tagsObject.description}
105106
/>

src/extension/background-script/connectors/galoy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ class Galoy implements Connector {
225225
const rate = await getCurrencyRateWithCache(CURRENCIES[currency]);
226226
absSettlementAmount = this.fromFiatCents(absSettlementAmount);
227227
displayAmount = [absSettlementAmount, CURRENCIES[currency]];
228-
absSettlementAmount = Math.floor(absSettlementAmount / rate);
228+
absSettlementAmount = Math.ceil(absSettlementAmount / rate);
229229
}
230230

231231
const createdAtDate = new Date(tx.createdAt * 1000);

src/extension/background-script/connectors/lnbits.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ class LnBits implements Connector {
142142
settled: !transaction.pending,
143143
settleDate: transaction.time * 1000,
144144
creationDate: creationDate,
145-
totalAmount: Math.abs(Math.floor(transaction.amount / 1000)),
145+
totalAmount: Math.ceil(Math.abs(transaction.amount / 1000)),
146146
type: transaction.amount > 0 ? "received" : "sent",
147147
};
148148
})

src/extension/background-script/connectors/nwc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class NWCConnector implements Connector {
103103
settled: transaction.state == "settled",
104104
settleDate: transaction.settled_at * 1000,
105105
creationDate: transaction.created_at * 1000,
106-
totalAmount: Math.floor(transaction.amount / 1000),
106+
totalAmount: Math.ceil(transaction.amount / 1000),
107107
type: transaction.type == "incoming" ? "received" : "sent",
108108
custom_records: this.tlvToCustomRecords(
109109
transaction.metadata?.["tlv_records"] as TLVRecord[] | undefined

0 commit comments

Comments
 (0)