diff --git a/BTCPayServer/Components/TruncateCenter/Default.cshtml b/BTCPayServer/Components/TruncateCenter/Default.cshtml index e692d389c..c45fc173e 100644 --- a/BTCPayServer/Components/TruncateCenter/Default.cshtml +++ b/BTCPayServer/Components/TruncateCenter/Default.cshtml @@ -1,7 +1,6 @@ @model BTCPayServer.Components.TruncateCenter.TruncateCenterViewModel @{ var classes = string.IsNullOrEmpty(Model.Classes) ? string.Empty : Model.Classes.Trim(); - var isTruncated = !string.IsNullOrEmpty(Model.Start) && !string.IsNullOrEmpty(Model.End); @if (Model.Copy) classes += " truncate-center--copy"; @if (Model.Elastic) classes += " truncate-center--elastic"; var prefix = Model.IsVue ? ":" : ""; @@ -24,8 +23,8 @@ } else { - - @(Model.Elastic || !isTruncated ? Model.Text[..^Model.Padding] : $"{Model.Start}…") + + @Model.Start @Model.End @Model.Text diff --git a/BTCPayServer/Components/TruncateCenter/TruncateCenter.cs b/BTCPayServer/Components/TruncateCenter/TruncateCenter.cs index d66711076..934676690 100644 --- a/BTCPayServer/Components/TruncateCenter/TruncateCenter.cs +++ b/BTCPayServer/Components/TruncateCenter/TruncateCenter.cs @@ -19,6 +19,7 @@ public class TruncateCenter : ViewComponent { if (string.IsNullOrEmpty(text)) return new HtmlContentViewComponentResult(new StringHtmlContent(string.Empty)); + var vm = new TruncateCenterViewModel { Classes = classes, @@ -28,12 +29,15 @@ public class TruncateCenter : ViewComponent Copy = copy, Text = text, Link = link, - Id = id + Id = id, + IsTruncated = text.Length > 2 * padding }; - if (!isVue && text.Length > 2 * padding) + if (!vm.IsVue) { - vm.Start = text[..padding]; - vm.End = text[^padding..]; + vm.Start = vm.IsTruncated ? text[..padding] : text; + vm.End = vm.IsTruncated ? text[^padding..] : string.Empty; + if (!vm.Elastic && vm.IsTruncated) + vm.Start = $"{vm.Start}…"; } return View(vm); } diff --git a/BTCPayServer/Components/TruncateCenter/TruncateCenterViewModel.cs b/BTCPayServer/Components/TruncateCenter/TruncateCenterViewModel.cs index a3586b77b..f59ec45a2 100644 --- a/BTCPayServer/Components/TruncateCenter/TruncateCenterViewModel.cs +++ b/BTCPayServer/Components/TruncateCenter/TruncateCenterViewModel.cs @@ -1,16 +1,17 @@ -namespace BTCPayServer.Components.TruncateCenter +#nullable enable +namespace BTCPayServer.Components.TruncateCenter; + +public class TruncateCenterViewModel { - public class TruncateCenterViewModel - { - public string Text { get; set; } - public string Start { get; set; } - public string End { get; set; } - public string Id { 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; } - } + public string Text { get; init; } = null!; + public string? Start { get; set; } + public string? End { get; set; } + public string? Id { get; init; } + public string? Classes { get; init; } + public string? Link { get; init; } + public int Padding { get; init; } + public bool Copy { get; init; } + public bool Elastic { get; init; } + public bool IsVue { get; init; } + public bool IsTruncated { get; init; } }