diff --git a/BTCPayServer.Tests/Checkoutv2Tests.cs b/BTCPayServer.Tests/Checkoutv2Tests.cs index ac383cfcb..f10352b6f 100644 --- a/BTCPayServer.Tests/Checkoutv2Tests.cs +++ b/BTCPayServer.Tests/Checkoutv2Tests.cs @@ -64,9 +64,9 @@ namespace BTCPayServer.Tests var qrValue = s.Driver.FindElement(By.CssSelector(".qr-container")).GetAttribute("data-qr-value"); var address = s.Driver.FindElement(By.CssSelector(".qr-container")).GetAttribute("data-clipboard"); var payUrl = s.Driver.FindElement(By.Id("PayInWallet")).GetAttribute("href"); - var copyAddress = s.Driver.FindElement(By.Id("Address_BTC")).GetAttribute("value"); + var copyAddress = s.Driver.FindElement(By.CssSelector("#Address_BTC .truncate-center-start")).Text; Assert.Equal($"bitcoin:{address}", payUrl); - Assert.StartsWith("bcrt", s.Driver.FindElement(By.Id("Address_BTC")).GetAttribute("value")); + Assert.StartsWith("bcrt", s.Driver.FindElement(By.CssSelector("#Address_BTC .truncate-center-start")).Text); Assert.DoesNotContain("lightning=", payUrl); Assert.Equal(address, copyAddress); Assert.Equal($"bitcoin:{address.ToUpperInvariant()}", qrValue); @@ -86,7 +86,7 @@ namespace BTCPayServer.Tests { payUrl = s.Driver.FindElement(By.Id("PayInWallet")).GetAttribute("href"); Assert.StartsWith("lightning:lnurl", payUrl); - Assert.StartsWith("lnurl", s.Driver.WaitForElement(By.Id("Lightning_BTC")).GetAttribute("value")); + Assert.StartsWith("lnurl", s.Driver.WaitForElement(By.CssSelector("#Lightning_BTC .truncate-center-start")).Text); s.Driver.ElementDoesNotExist(By.Id("Address_BTC")); }); @@ -101,7 +101,7 @@ namespace BTCPayServer.Tests qrValue = s.Driver.FindElement(By.CssSelector(".qr-container")).GetAttribute("data-qr-value"); address = s.Driver.FindElement(By.CssSelector(".qr-container")).GetAttribute("data-clipboard"); payUrl = s.Driver.FindElement(By.Id("PayInWallet")).GetAttribute("href"); - copyAddress = s.Driver.FindElement(By.Id("Lightning_BTC_LightningLike")).GetAttribute("value"); + copyAddress = s.Driver.FindElement(By.CssSelector("#Lightning_BTC_LightningLike .truncate-center-start")).Text; Assert.Equal($"lightning:{address}", payUrl); Assert.Equal(address, copyAddress); Assert.Equal($"lightning:{address.ToUpperInvariant()}", qrValue); @@ -229,8 +229,8 @@ namespace BTCPayServer.Tests qrValue = s.Driver.FindElement(By.CssSelector(".qr-container")).GetAttribute("data-qr-value"); address = s.Driver.FindElement(By.CssSelector(".qr-container")).GetAttribute("data-clipboard"); payUrl = s.Driver.FindElement(By.Id("PayInWallet")).GetAttribute("href"); - var copyAddressOnchain = s.Driver.FindElement(By.Id("Address_BTC")).GetAttribute("value"); - var copyAddressLightning = s.Driver.FindElement(By.Id("Lightning_BTC")).GetAttribute("value"); + var copyAddressOnchain = s.Driver.FindElement(By.CssSelector("#Address_BTC .truncate-center-start")).Text; + var copyAddressLightning = s.Driver.FindElement(By.CssSelector("#Lightning_BTC .truncate-center-start")).Text; Assert.StartsWith($"bitcoin:{address}?amount=", payUrl); Assert.Contains("?amount=", payUrl); Assert.Contains("&lightning=", payUrl); @@ -297,8 +297,8 @@ namespace BTCPayServer.Tests qrValue = s.Driver.FindElement(By.CssSelector(".qr-container")).GetAttribute("data-qr-value"); address = s.Driver.FindElement(By.CssSelector(".qr-container")).GetAttribute("data-clipboard"); payUrl = s.Driver.FindElement(By.Id("PayInWallet")).GetAttribute("href"); - copyAddressOnchain = s.Driver.FindElement(By.Id("Address_BTC")).GetAttribute("value"); - copyAddressLightning = s.Driver.FindElement(By.Id("Lightning_BTC")).GetAttribute("value"); + copyAddressOnchain = s.Driver.FindElement(By.CssSelector("#Address_BTC .truncate-center-start")).Text; + copyAddressLightning = s.Driver.FindElement(By.CssSelector("#Lightning_BTC .truncate-center-start")).Text; Assert.StartsWith($"bitcoin:{address}", payUrl); Assert.Contains("?lightning=lnurl", payUrl); Assert.DoesNotContain("amount=", payUrl); diff --git a/BTCPayServer/Components/TruncateCenter/Default.cshtml b/BTCPayServer/Components/TruncateCenter/Default.cshtml index ec65c1989..a9d6c3f34 100644 --- a/BTCPayServer/Components/TruncateCenter/Default.cshtml +++ b/BTCPayServer/Components/TruncateCenter/Default.cshtml @@ -1,10 +1,29 @@ @model BTCPayServer.Components.TruncateCenter.TruncateCenterViewModel - - @Model.Truncated - @Model.Text +@{ + var classes = string.IsNullOrEmpty(Model.Classes) ? string.Empty : Model.Classes.Trim(); + @if (Model.Copy) classes += " truncate-center--copy"; + @if (Model.Elastic) classes += " truncate-center--elastic"; +} + + @if (Model.IsVue) + { + + + + + + } + else + { + + @(Model.Elastic ? Model.Text : $"{Model.Start}…") + @Model.End + + @Model.Text + } @if (Model.Copy) { - } diff --git a/BTCPayServer/Components/TruncateCenter/TruncateCenter.cs b/BTCPayServer/Components/TruncateCenter/TruncateCenter.cs index 3e4f84edd..5eac498b6 100644 --- a/BTCPayServer/Components/TruncateCenter/TruncateCenter.cs +++ b/BTCPayServer/Components/TruncateCenter/TruncateCenter.cs @@ -15,7 +15,7 @@ namespace BTCPayServer.Components.TruncateCenter; /// HTML with truncated string public class TruncateCenter : ViewComponent { - public IViewComponentResult Invoke(string text, string link = null, string classes = null, int padding = 7, bool copy = true) + public IViewComponentResult Invoke(string text, string link = null, string classes = null, int padding = 7, bool copy = true, bool elastic = false, bool isVue = false) { if (string.IsNullOrEmpty(text)) return new HtmlContentViewComponentResult(new StringHtmlContent(string.Empty)); @@ -23,11 +23,17 @@ public class TruncateCenter : ViewComponent { Classes = classes, Padding = padding, + Elastic = elastic, + IsVue = isVue, Copy = copy, Text = text, - Link = link, - Truncated = text.Length > 2 * padding ? $"{text[..padding]}…{text[^padding..]}" : text + Link = link }; + if (!isVue && text.Length > 2 * padding) + { + vm.Start = text[..padding]; + vm.End = text[^padding..]; + } return View(vm); } } diff --git a/BTCPayServer/Components/TruncateCenter/TruncateCenterViewModel.cs b/BTCPayServer/Components/TruncateCenter/TruncateCenterViewModel.cs index 770eac31c..8e5bb10b6 100644 --- a/BTCPayServer/Components/TruncateCenter/TruncateCenterViewModel.cs +++ b/BTCPayServer/Components/TruncateCenter/TruncateCenterViewModel.cs @@ -3,10 +3,13 @@ namespace BTCPayServer.Components.TruncateCenter public class TruncateCenterViewModel { public string Text { get; set; } - public string Truncated { get; set; } + public string Start { get; set; } + public string End { get; set; } public string Classes { get; set; } public string Link { get; set; } public int Padding { get; set; } public bool Copy { get; set; } + public bool Elastic { get; set; } + public bool IsVue { get; set; } } } diff --git a/BTCPayServer/Views/Shared/Bitcoin/BitcoinLikeMethodCheckout-v2.cshtml b/BTCPayServer/Views/Shared/Bitcoin/BitcoinLikeMethodCheckout-v2.cshtml index 1fe8e38aa..9fe5b697f 100644 --- a/BTCPayServer/Views/Shared/Bitcoin/BitcoinLikeMethodCheckout-v2.cshtml +++ b/BTCPayServer/Views/Shared/Bitcoin/BitcoinLikeMethodCheckout-v2.cshtml @@ -1,4 +1,6 @@ @using BTCPayServer.BIP78.Sender +@using BTCPayServer.Components.TruncateCenter +@using BTCPayServer.Abstractions.TagHelpers @model BTCPayServer.Models.InvoicingModels.PaymentModel