Setting exchange rate after CreateInvoice call to take into account what API has returned

This commit is contained in:
rockstardev 2024-07-04 05:36:12 -05:00
parent 597e2b0ec1
commit b333aeb450

View File

@ -97,6 +97,15 @@ namespace BTCPayServer.Payments.Lightning
var request = new CreateInvoiceParams(new LightMoney(due, LightMoneyUnit.BTC), description, expiry); var request = new CreateInvoiceParams(new LightMoney(due, LightMoneyUnit.BTC), description, expiry);
request.PrivateRouteHints = storeBlob.LightningPrivateRouteHints; request.PrivateRouteHints = storeBlob.LightningPrivateRouteHints;
lightningInvoice = await client.CreateInvoice(request, cts.Token); lightningInvoice = await client.CreateInvoice(request, cts.Token);
// Only apply Rate on non BTC invoices
// if API due is larger, otherwise it will mask problems with exchange rate
if (invoice.Currency != "BTC")
{
var apiDue = lightningInvoice.Amount.ToUnit(LightMoneyUnit.BTC);
if (apiDue > due)
paymentMethod.Rate = invoice.MinimumNetDue / apiDue;
}
} }
catch (OperationCanceledException) when (cts.IsCancellationRequested) catch (OperationCanceledException) when (cts.IsCancellationRequested)
{ {