Re-enable lightning sats feature through C# (#1014)

This commit is contained in:
Andrew Camilleri
2019-09-11 07:49:06 +02:00
committed by Nicolas Dorier
parent e6cfb6e851
commit 7ab97311be
7 changed files with 41 additions and 28 deletions

View File

@@ -156,21 +156,22 @@ namespace BTCPayServer.Tests
[Fact] [Fact]
public void CanUseLightningSatsFeature() public void CanUseLightningSatsFeature()
{ {
//uncomment after https://github.com/btcpayserver/btcpayserver/pull/1014 using (var s = SeleniumTester.Create())
// using (var s = SeleniumTester.Create()) {
// { s.Start();
// s.Start(); s.RegisterNewUser();
// s.RegisterNewUser(); var store = s.CreateNewStore();
// var store = s.CreateNewStore(); s.AddInternalLightningNode("BTC");
// s.AddInternalLightningNode("BTC"); s.GoToStore(store.storeId, StoreNavPages.Checkout);
// s.GoToStore(store.storeId, StoreNavPages.Checkout); s.SetCheckbox(s, "LightningAmountInSatoshi", true);
// s.SetCheckbox(s, "LightningAmountInSatoshi", true); var command = s.Driver.FindElement(By.Name("command"));
// s.Driver.FindElement(By.Name("command")).Click();
// var invoiceId = s.CreateInvoice(store.storeName, 10, "USD", "a@g.com"); command.ForceClick();
// s.GoToInvoiceCheckout(invoiceId); var invoiceId = s.CreateInvoice(store.storeName, 10, "USD", "a@g.com");
// Assert.Contains("Sats", s.Driver.FindElement(By.ClassName("payment__currencies_noborder")).Text); s.GoToInvoiceCheckout(invoiceId);
// Assert.Contains("Sats", s.Driver.FindElement(By.ClassName("payment__currencies_noborder")).Text);
// }
}
} }
} }
} }

View File

@@ -21,6 +21,7 @@ using BTCPayServer.Lightning.CLightning;
using BTCPayServer.Views.Stores; using BTCPayServer.Views.Stores;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using OpenQA.Selenium.Interactions;
namespace BTCPayServer.Tests namespace BTCPayServer.Tests
{ {
@@ -216,6 +217,13 @@ namespace BTCPayServer.Tests
SetCheckbox(s.Driver.FindElement(By.Name(inputName)), value); SetCheckbox(s.Driver.FindElement(By.Name(inputName)), value);
} }
public void ScrollToElement(IWebElement element)
{
Actions actions = new Actions(Driver);
actions.MoveToElement(element);
actions.Perform();
}
public void GoToInvoices() public void GoToInvoices()
{ {
Driver.FindElement(By.Id("Invoices")).Click(); Driver.FindElement(By.Id("Invoices")).Click();

View File

@@ -238,7 +238,6 @@ namespace BTCPayServer.Controllers
CustomCSSLink = storeBlob.CustomCSS?.AbsoluteUri, CustomCSSLink = storeBlob.CustomCSS?.AbsoluteUri,
CustomLogoLink = storeBlob.CustomLogo?.AbsoluteUri, CustomLogoLink = storeBlob.CustomLogo?.AbsoluteUri,
CryptoImage = Request.GetRelativePathOrAbsolute(paymentMethodHandler.GetCryptoImage(paymentMethodId)), CryptoImage = Request.GetRelativePathOrAbsolute(paymentMethodHandler.GetCryptoImage(paymentMethodId)),
LightningAmountInSatoshi = storeBlob.LightningAmountInSatoshi,
BtcAddress = paymentMethodDetails.GetPaymentDestination(), BtcAddress = paymentMethodDetails.GetPaymentDestination(),
BtcDue = accounting.Due.ToString(), BtcDue = accounting.Due.ToString(),
OrderAmount = (accounting.TotalDue - accounting.NetworkFee).ToString(), OrderAmount = (accounting.TotalDue - accounting.NetworkFee).ToString(),
@@ -295,7 +294,7 @@ namespace BTCPayServer.Controllers
.ToList() .ToList()
}; };
paymentMethodHandler.PreparePaymentModel(model, dto); paymentMethodHandler.PreparePaymentModel(model, dto, storeBlob);
model.UISettings = paymentMethodHandler.GetCheckoutUISettings(); model.UISettings = paymentMethodHandler.GetCheckoutUISettings();
model.PaymentMethodId = paymentMethodId.ToString(); model.PaymentMethodId = paymentMethodId.ToString();
var expiration = TimeSpan.FromSeconds(model.ExpirationSeconds); var expiration = TimeSpan.FromSeconds(model.ExpirationSeconds);

View File

@@ -37,7 +37,8 @@ namespace BTCPayServer.Payments.Bitcoin
public Task<BitcoinAddress> ReserveAddress; public Task<BitcoinAddress> ReserveAddress;
} }
public override void PreparePaymentModel(PaymentModel model, InvoiceResponse invoiceResponse) public override void PreparePaymentModel(PaymentModel model, InvoiceResponse invoiceResponse,
StoreBlob storeBlob)
{ {
var paymentMethodId = new PaymentMethodId(model.CryptoCode, PaymentTypes.BTCLike); var paymentMethodId = new PaymentMethodId(model.CryptoCode, PaymentTypes.BTCLike);

View File

@@ -37,7 +37,7 @@ namespace BTCPayServer.Payments
/// <returns></returns> /// <returns></returns>
object PreparePayment(ISupportedPaymentMethod supportedPaymentMethod, StoreData store, BTCPayNetworkBase network); object PreparePayment(ISupportedPaymentMethod supportedPaymentMethod, StoreData store, BTCPayNetworkBase network);
void PreparePaymentModel(PaymentModel model, InvoiceResponse invoiceResponse); void PreparePaymentModel(PaymentModel model, InvoiceResponse invoiceResponse, StoreBlob storeBlob);
string GetCryptoImage(PaymentMethodId paymentMethodId); string GetCryptoImage(PaymentMethodId paymentMethodId);
string GetPaymentMethodName(PaymentMethodId paymentMethodId); string GetPaymentMethodName(PaymentMethodId paymentMethodId);
@@ -68,7 +68,8 @@ namespace BTCPayServer.Payments
TSupportedPaymentMethod supportedPaymentMethod, TSupportedPaymentMethod supportedPaymentMethod,
PaymentMethod paymentMethod, StoreData store, TBTCPayNetwork network, object preparePaymentObject); PaymentMethod paymentMethod, StoreData store, TBTCPayNetwork network, object preparePaymentObject);
public abstract void PreparePaymentModel(PaymentModel model, InvoiceResponse invoiceResponse); public abstract void PreparePaymentModel(PaymentModel model, InvoiceResponse invoiceResponse,
StoreBlob storeBlob);
public abstract string GetCryptoImage(PaymentMethodId paymentMethodId); public abstract string GetCryptoImage(PaymentMethodId paymentMethodId);
public abstract string GetPaymentMethodName(PaymentMethodId paymentMethodId); public abstract string GetPaymentMethodName(PaymentMethodId paymentMethodId);

View File

@@ -162,7 +162,8 @@ namespace BTCPayServer.Payments.Lightning
return string.Empty; return string.Empty;
} }
public override void PreparePaymentModel(PaymentModel model, InvoiceResponse invoiceResponse) public override void PreparePaymentModel(PaymentModel model, InvoiceResponse invoiceResponse,
StoreBlob storeBlob)
{ {
var paymentMethodId = new PaymentMethodId(model.CryptoCode, PaymentTypes.LightningLike); var paymentMethodId = new PaymentMethodId(model.CryptoCode, PaymentTypes.LightningLike);
@@ -172,8 +173,16 @@ namespace BTCPayServer.Payments.Lightning
model.PaymentMethodName = GetPaymentMethodName(network); model.PaymentMethodName = GetPaymentMethodName(network);
model.InvoiceBitcoinUrl = cryptoInfo.PaymentUrls.BOLT11; model.InvoiceBitcoinUrl = cryptoInfo.PaymentUrls.BOLT11;
model.InvoiceBitcoinUrlQR = cryptoInfo.PaymentUrls.BOLT11.ToUpperInvariant(); model.InvoiceBitcoinUrlQR = cryptoInfo.PaymentUrls.BOLT11.ToUpperInvariant();
model.LightningAmountInSatoshi = storeBlob.LightningAmountInSatoshi;
if (storeBlob.LightningAmountInSatoshi && model.CryptoCode == "BTC" )
{
model.CryptoCode = "Sats";
model.BtcDue = Money.Parse(model.BtcDue).ToUnit(MoneyUnit.Satoshi).ToString();
model.BtcPaid = Money.Parse(model.BtcPaid).ToUnit(MoneyUnit.Satoshi).ToString();
model.NetworkFee = new Money(model.NetworkFee, MoneyUnit.BTC).ToUnit(MoneyUnit.Satoshi);
model.OrderAmount = Money.Parse(model.OrderAmount).ToUnit(MoneyUnit.Satoshi).ToString();
}
} }
public override string GetCryptoImage(PaymentMethodId paymentMethodId) public override string GetCryptoImage(PaymentMethodId paymentMethodId)
{ {
var network = _networkProvider.GetNetwork<BTCPayNetwork>(paymentMethodId.CryptoCode); var network = _networkProvider.GetNetwork<BTCPayNetwork>(paymentMethodId.CryptoCode);

View File

@@ -213,12 +213,6 @@
this.lineItemsExpanded ? $("line-items").slideUp() : $("line-items").slideDown(); this.lineItemsExpanded ? $("line-items").slideUp() : $("line-items").slideDown();
this.lineItemsExpanded = !this.lineItemsExpanded; this.lineItemsExpanded = !this.lineItemsExpanded;
}, },
numberFormatted: function(x) {
var rounded = Math.round(x);
var parts = rounded.toString().split(".");
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, " ");
return parts.join(".");
},
openPaymentMethodDialog: function() { openPaymentMethodDialog: function() {
var content = $("#vexPopupDialog").html(); var content = $("#vexPopupDialog").html();
vex.open({ vex.open({