From cade6c6c38b4e156b25b31623299db2be6f2fca9 Mon Sep 17 00:00:00 2001 From: dstrukt Date: Sun, 19 Jun 2022 19:52:12 -0700 Subject: [PATCH] Move `View` action to the `Name` column in Payouts & Payment Requests (#3873) * ui+paymentrequest: moves 'view' link to name * ui+pull: moves 'view' link to name column * Update links, fix tests Co-authored-by: Dennis Reimann --- BTCPayServer.Tests/SeleniumTests.cs | 28 ++++---- .../StoreLightningBalance.cs | 5 ++ .../Controllers/UIPaymentRequestController.cs | 2 +- BTCPayServer/Models/ViewPullPaymentModel.cs | 5 +- .../EditPaymentRequest.cshtml | 37 ++++++----- .../GetPaymentRequests.cshtml | 16 ++--- .../ViewPaymentRequest.cshtml | 10 +++ .../UIPullPayment/ViewPullPayment.cshtml | 38 ++++++----- .../UIStorePullPayments/PullPayments.cshtml | 66 +++++++++---------- 9 files changed, 118 insertions(+), 89 deletions(-) diff --git a/BTCPayServer.Tests/SeleniumTests.cs b/BTCPayServer.Tests/SeleniumTests.cs index d4277e150..6e56ed834 100644 --- a/BTCPayServer.Tests/SeleniumTests.cs +++ b/BTCPayServer.Tests/SeleniumTests.cs @@ -759,35 +759,38 @@ namespace BTCPayServer.Tests currencyInput.SendKeys("BTC"); s.Driver.FindElement(By.Id("SaveButton")).Click(); - s.Driver.FindElement(By.XPath($"//a[starts-with(@id, 'Edit-')]")).Click(); + s.Driver.FindElement(By.XPath("//a[starts-with(@id, 'Edit-')]")).Click(); + var editUrl = s.Driver.Url; + s.Driver.FindElement(By.Id("ViewPaymentRequest")).Click(); - s.Driver.SwitchTo().Window(s.Driver.WindowHandles.Last()); + var viewUrl = s.Driver.Url; + Assert.Equal("Amount due", s.Driver.FindElement(By.CssSelector("[data-test='amount-due-title']")).Text); Assert.Equal("Pay Invoice", s.Driver.FindElement(By.CssSelector("[data-test='pay-button']")).Text.Trim()); // expire - s.Driver.SwitchTo().Window(s.Driver.WindowHandles.First()); + s.GoToUrl(editUrl); s.Driver.ExecuteJavaScript("document.getElementById('ExpiryDate').value = '2021-01-21T21:00:00.000Z'"); s.Driver.FindElement(By.Id("SaveButton")).Click(); - s.Driver.FindElement(By.XPath($"//a[starts-with(@id, 'Edit-')]")).Click(); - s.Driver.SwitchTo().Window(s.Driver.WindowHandles.Last()); - s.Driver.Navigate().Refresh(); + s.Driver.FindElement(By.XPath("//a[starts-with(@id, 'Edit-')]")).Click(); + + s.GoToUrl(viewUrl); Assert.Equal("Expired", s.Driver.WaitForElement(By.CssSelector("[data-test='status']")).Text); // unexpire - s.Driver.SwitchTo().Window(s.Driver.WindowHandles.First()); + s.GoToUrl(editUrl); s.Driver.FindElement(By.Id("ClearExpiryDate")).Click(); s.Driver.FindElement(By.Id("SaveButton")).Click(); - s.Driver.FindElement(By.XPath($"//a[starts-with(@id, 'Edit-')]")).Click(); - s.Driver.SwitchTo().Window(s.Driver.WindowHandles.Last()); - s.Driver.Navigate().Refresh(); + s.Driver.FindElement(By.XPath("//a[starts-with(@id, 'Edit-')]")).Click(); + + s.GoToUrl(viewUrl); s.Driver.AssertElementNotFound(By.CssSelector("[data-test='status']")); Assert.Equal("Pay Invoice", s.Driver.FindElement(By.CssSelector("[data-test='pay-button']")).Text.Trim()); - s.Driver.SwitchTo().Window(s.Driver.WindowHandles.First()); // archive (from details page) + s.GoToUrl(editUrl); var payReqId = s.Driver.Url.Split('/').Last(); s.Driver.FindElement(By.Id("ArchivePaymentRequest")).Click(); Assert.Contains("The payment request has been archived", s.FindAlertMessage().Text); @@ -1365,11 +1368,10 @@ namespace BTCPayServer.Tests newStore = s.CreateNewStore(); s.AddLightningNode(); + //Currently an onchain wallet is required to use the Lightning payouts feature.. s.GenerateWallet("BTC", "", true, true); - s.GoToStore(newStore.storeId, StoreNavPages.PullPayments); - s.Driver.FindElement(By.Id("NewPullPayment")).Click(); var paymentMethodOptions = s.Driver.FindElements(By.CssSelector("input[name='PaymentMethods']")); diff --git a/BTCPayServer/Components/StoreLightningBalance/StoreLightningBalance.cs b/BTCPayServer/Components/StoreLightningBalance/StoreLightningBalance.cs index 46e26a743..37923e945 100644 --- a/BTCPayServer/Components/StoreLightningBalance/StoreLightningBalance.cs +++ b/BTCPayServer/Components/StoreLightningBalance/StoreLightningBalance.cs @@ -76,6 +76,11 @@ public class StoreLightningBalance : ViewComponent // not all implementations support balance fetching vm.ProblemDescription = "Your node does not support balance fetching."; } + catch + { + // general error + vm.ProblemDescription = "Could not fetch Lightning balance."; + } } else { diff --git a/BTCPayServer/Controllers/UIPaymentRequestController.cs b/BTCPayServer/Controllers/UIPaymentRequestController.cs index 33c76fe82..b0e456c8f 100644 --- a/BTCPayServer/Controllers/UIPaymentRequestController.cs +++ b/BTCPayServer/Controllers/UIPaymentRequestController.cs @@ -148,7 +148,7 @@ namespace BTCPayServer.Controllers data = await _PaymentRequestRepository.CreateOrUpdatePaymentRequest(data); _EventAggregator.Publish(new PaymentRequestUpdated { Data = data, PaymentRequestId = data.Id, }); - TempData[WellKnownTempData.SuccessMessage] = $"Payment request [{viewModel.Title}] {(isNewPaymentRequest ? "created" : "updated")} successfully"; + TempData[WellKnownTempData.SuccessMessage] = $"Payment request \"{viewModel.Title}\" {(isNewPaymentRequest ? "created" : "updated")} successfully"; return RedirectToAction(nameof(GetPaymentRequests), new { storeId = store.Id, payReqId = data.Id }); } diff --git a/BTCPayServer/Models/ViewPullPaymentModel.cs b/BTCPayServer/Models/ViewPullPaymentModel.cs index d286945bf..c833736fa 100644 --- a/BTCPayServer/Models/ViewPullPaymentModel.cs +++ b/BTCPayServer/Models/ViewPullPaymentModel.cs @@ -19,6 +19,7 @@ namespace BTCPayServer.Models public ViewPullPaymentModel(PullPaymentData data, DateTimeOffset now) { Id = data.Id; + StoreId = data.StoreId; var blob = data.GetBlob(); PaymentMethods = blob.SupportedPaymentMethods; SelectedPaymentMethod = PaymentMethods.First().ToString(); @@ -64,6 +65,8 @@ namespace BTCPayServer.Models } } + public string StoreId { get; set; } + public string SelectedPaymentMethod { get; set; } public PaymentMethodId[] PaymentMethods { get; set; } @@ -87,7 +90,7 @@ namespace BTCPayServer.Models public string Description { get; set; } public string EmbeddedCSS { get; set; } public string CustomCSSLink { get; set; } - public List Payouts { get; set; } = new List(); + public List Payouts { get; set; } = new (); public DateTimeOffset StartDate { get; set; } public DateTime LastRefreshed { get; set; } public CurrencyData CurrencyData { get; set; } diff --git a/BTCPayServer/Views/UIPaymentRequest/EditPaymentRequest.cshtml b/BTCPayServer/Views/UIPaymentRequest/EditPaymentRequest.cshtml index 99af2c0dd..eb2824089 100644 --- a/BTCPayServer/Views/UIPaymentRequest/EditPaymentRequest.cshtml +++ b/BTCPayServer/Views/UIPaymentRequest/EditPaymentRequest.cshtml @@ -27,7 +27,7 @@ else { - View + View } @@ -128,19 +128,22 @@ -
- Invoices - Clone - @if (!Model.Archived) - { - Archive - } - else - { - Unarchive - } -
+@if (!string.IsNullOrEmpty(Model.Id)) +{ +
+ Invoices + Clone + @if (!Model.Archived) + { + Archive + } + else + { + Unarchive + } +
+} + diff --git a/BTCPayServer/Views/UIPaymentRequest/GetPaymentRequests.cshtml b/BTCPayServer/Views/UIPaymentRequest/GetPaymentRequests.cshtml index 75bcc98ab..7ebff5d79 100644 --- a/BTCPayServer/Views/UIPaymentRequest/GetPaymentRequests.cshtml +++ b/BTCPayServer/Views/UIPaymentRequest/GetPaymentRequests.cshtml @@ -65,22 +65,20 @@ @foreach (var item in Model.Items) { - @item.Title + + @item.Title + @(item.ExpiryDate?.ToString("g") ?? "No Expiry") @item.Amount @item.Currency @item.Status - Edit + Invoices - - View - - - Invoices - - - Pay - - - Clone + Clone - @(item.Archived ? "Unarchive" : "Archive") + - + View } diff --git a/BTCPayServer/Views/UIPaymentRequest/ViewPaymentRequest.cshtml b/BTCPayServer/Views/UIPaymentRequest/ViewPaymentRequest.cshtml index 024fde4bd..8c286d4c0 100644 --- a/BTCPayServer/Views/UIPaymentRequest/ViewPaymentRequest.cshtml +++ b/BTCPayServer/Views/UIPaymentRequest/ViewPaymentRequest.cshtml @@ -1,6 +1,11 @@ @using BTCPayServer.Services.Invoices @using BTCPayServer.Client.Models @using BTCPayServer.Abstractions.Contracts +@using BTCPayServer.Client +@using BTCPayServer.Components.ThemeSwitch +@using BTCPayServer.TagHelpers +@using BundlerMinifier.TagHelpers +@using Microsoft.AspNetCore.Mvc.TagHelpers @model BTCPayServer.Models.PaymentRequestViewModels.ViewPaymentRequestViewModel @addTagHelper *, BundlerMinifier.TagHelpers @inject BTCPayServer.Services.BTCPayServerEnvironment env @@ -361,6 +366,11 @@