From 5ca4e71c34dcbbb72dd6fc311c02617def4bb803 Mon Sep 17 00:00:00 2001 From: Andrew Camilleri Date: Tue, 22 Dec 2020 03:18:51 +0100 Subject: [PATCH] Introduce QR Code View component (#2125) * Introduce QR Code View component * more cleanup * fix js clipboard * Fix clipboard confirmation width calculation * fix tests Co-authored-by: Dennis Reimann --- BTCPayServer.Tests/SeleniumTester.cs | 2 +- BTCPayServer.Tests/SeleniumTests.cs | 12 +-- BTCPayServer/BTCPayServer.csproj | 1 + BTCPayServer/Components/QRCode/QRCode.cs | 22 +++++ .../ShowLightningNodeInfo.cshtml | 93 +++++-------------- .../Views/Wallets/WalletReceive.cshtml | 88 +++--------------- BTCPayServer/bundleconfig.json | 10 -- BTCPayServer/wwwroot/js/copy-to-clipboard.js | 2 +- BTCPayServer/wwwroot/main/qrcode.css | 20 ++++ 9 files changed, 87 insertions(+), 163 deletions(-) create mode 100644 BTCPayServer/Components/QRCode/QRCode.cs create mode 100644 BTCPayServer/wwwroot/main/qrcode.css diff --git a/BTCPayServer.Tests/SeleniumTester.cs b/BTCPayServer.Tests/SeleniumTester.cs index d9f87f405..4f8053d94 100644 --- a/BTCPayServer.Tests/SeleniumTester.cs +++ b/BTCPayServer.Tests/SeleniumTester.cs @@ -329,7 +329,7 @@ namespace BTCPayServer.Tests walletId ??= WalletId; GoToWallet(walletId, WalletsNavPages.Receive); Driver.FindElement(By.Id("generateButton")).Click(); - var addressStr = Driver.FindElement(By.Id("vue-address")).GetProperty("value"); + var addressStr = Driver.FindElement(By.Id("address")).GetProperty("value"); var address = BitcoinAddress.Create(addressStr, ((BTCPayNetwork)Server.NetworkProvider.GetNetwork(walletId.CryptoCode)).NBitcoinNetwork); for (int i = 0; i < coins; i++) { diff --git a/BTCPayServer.Tests/SeleniumTests.cs b/BTCPayServer.Tests/SeleniumTests.cs index 524524131..399f1edc7 100644 --- a/BTCPayServer.Tests/SeleniumTests.cs +++ b/BTCPayServer.Tests/SeleniumTests.cs @@ -560,7 +560,7 @@ namespace BTCPayServer.Tests var walletId = new WalletId(storeId, "BTC"); s.GoToWallet(walletId, WalletsNavPages.Receive); s.Driver.FindElement(By.Id("generateButton")).Click(); - var addressStr = s.Driver.FindElement(By.Id("vue-address")).GetProperty("value"); + var addressStr = s.Driver.FindElement(By.Id("address")).GetProperty("value"); var address = BitcoinAddress.Create(addressStr, ((BTCPayNetwork)s.Server.NetworkProvider.GetNetwork("BTC")).NBitcoinNetwork); await s.Server.ExplorerNode.GenerateAsync(1); for (int i = 0; i < 6; i++) @@ -761,13 +761,13 @@ namespace BTCPayServer.Tests //generate a receiving address s.Driver.FindElement(By.CssSelector("button[value=generate-new-address]")).Click(); Assert.True(s.Driver.FindElement(By.ClassName("qr-container")).Displayed); - var receiveAddr = s.Driver.FindElement(By.Id("vue-address")).GetAttribute("value"); + var receiveAddr = s.Driver.FindElement(By.Id("address")).GetAttribute("value"); //unreserve s.Driver.FindElement(By.CssSelector("button[value=unreserve-current-address]")).Click(); //generate it again, should be the same one as before as nothign got used in the meantime s.Driver.FindElement(By.CssSelector("button[value=generate-new-address]")).Click(); Assert.True(s.Driver.FindElement(By.ClassName("qr-container")).Displayed); - Assert.Equal(receiveAddr, s.Driver.FindElement(By.Id("vue-address")).GetAttribute("value")); + Assert.Equal(receiveAddr, s.Driver.FindElement(By.Id("address")).GetAttribute("value")); //send money to addr and ensure it changed var sess = await s.Server.ExplorerClient.CreateWebsocketNotificationSessionAsync(); @@ -779,8 +779,8 @@ namespace BTCPayServer.Tests await Task.Delay(200); s.Driver.Navigate().Refresh(); s.Driver.FindElement(By.CssSelector("button[value=generate-new-address]")).Click(); - Assert.NotEqual(receiveAddr, s.Driver.FindElement(By.Id("vue-address")).GetAttribute("value")); - receiveAddr = s.Driver.FindElement(By.Id("vue-address")).GetAttribute("value"); + Assert.NotEqual(receiveAddr, s.Driver.FindElement(By.Id("address")).GetAttribute("value")); + receiveAddr = s.Driver.FindElement(By.Id("address")).GetAttribute("value"); //change the wallet and ensure old address is not there and generating a new one does not result in the prev one s.GoToStore(storeId.storeId); @@ -789,7 +789,7 @@ namespace BTCPayServer.Tests s.Driver.FindElement(By.LinkText("Manage")).Click(); s.Driver.FindElement(By.Id("WalletReceive")).Click(); s.Driver.FindElement(By.CssSelector("button[value=generate-new-address]")).Click(); - Assert.NotEqual(receiveAddr, s.Driver.FindElement(By.Id("vue-address")).GetAttribute("value")); + Assert.NotEqual(receiveAddr, s.Driver.FindElement(By.Id("address")).GetAttribute("value")); var invoiceId = s.CreateInvoice(storeId.storeName); var invoice = await s.Server.PayTester.InvoiceRepository.GetInvoice(invoiceId); diff --git a/BTCPayServer/BTCPayServer.csproj b/BTCPayServer/BTCPayServer.csproj index 20c9c08e2..1af87004b 100644 --- a/BTCPayServer/BTCPayServer.csproj +++ b/BTCPayServer/BTCPayServer.csproj @@ -57,6 +57,7 @@ all runtime; build; native; contentfiles; analyzers + diff --git a/BTCPayServer/Components/QRCode/QRCode.cs b/BTCPayServer/Components/QRCode/QRCode.cs new file mode 100644 index 000000000..017923345 --- /dev/null +++ b/BTCPayServer/Components/QRCode/QRCode.cs @@ -0,0 +1,22 @@ +using System.Drawing; +using Microsoft.AspNetCore.Html; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.ViewComponents; +using QRCoder; + +namespace BTCPayServer.Components.QRCode +{ + public class QRCode : ViewComponent + { + private static QRCodeGenerator qrGenerator = new QRCodeGenerator(); + + + public IViewComponentResult Invoke(string data) + { + + QRCodeData qrCodeData = qrGenerator.CreateQrCode(data, QRCodeGenerator.ECCLevel.Q); + SvgQRCode qrCode = new SvgQRCode(qrCodeData); + return new HtmlContentViewComponentResult(new HtmlString(qrCode.GetGraphic(new Size(256,256), "#000", "#f5f5f7", true, SvgQRCode.SizingMode.ViewBoxAttribute))); + } + } +} diff --git a/BTCPayServer/Views/PublicLightningNodeInfo/ShowLightningNodeInfo.cshtml b/BTCPayServer/Views/PublicLightningNodeInfo/ShowLightningNodeInfo.cshtml index aaad32fe3..e6f89a047 100644 --- a/BTCPayServer/Views/PublicLightningNodeInfo/ShowLightningNodeInfo.cshtml +++ b/BTCPayServer/Views/PublicLightningNodeInfo/ShowLightningNodeInfo.cshtml @@ -18,65 +18,13 @@ - - + -
@@ -84,29 +32,32 @@
-

@Model.StoreName

+

@Model.StoreName

- @Model.CryptoCode + @Model.CryptoCode Lightning Node

- + @(Model.Available ? "Online" : "Unavailable") - +

-
- @Model.CryptoCode - -
-
- -
- + @if (Model.Available) + { +
+ @Model.CryptoCode +
-
+
+ +
+ +
+
+ }
diff --git a/BTCPayServer/Views/Wallets/WalletReceive.cshtml b/BTCPayServer/Views/Wallets/WalletReceive.cshtml index 80eb512f5..0c4eff51c 100644 --- a/BTCPayServer/Views/Wallets/WalletReceive.cshtml +++ b/BTCPayServer/Views/Wallets/WalletReceive.cshtml @@ -1,5 +1,4 @@ - -@addTagHelper *, BundlerMinifier.TagHelpers +@addTagHelper *, BundlerMinifier.TagHelpers @model BTCPayServer.Controllers.WalletReceiveViewModel @{ Layout = "../Shared/_NavLayout.cshtml"; @@ -10,7 +9,7 @@ {
- +
} @@ -20,7 +19,6 @@
@if (string.IsNullOrEmpty(Model.Address)) { -

Receive @Model.CryptoCode

} @@ -30,7 +28,7 @@