From 89041a67443f4cbb553d3fad07aae55a702a9cc9 Mon Sep 17 00:00:00 2001 From: d11n Date: Fri, 27 Oct 2023 02:59:12 +0200 Subject: [PATCH] Wallet Send: Fill label from BIP21 (#5428) Fixes #5426. --- BTCPayServer/Controllers/UIWalletsController.cs | 16 ++++++++++------ BTCPayServer/Views/UIWallets/WalletSend.cshtml | 1 - 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/BTCPayServer/Controllers/UIWalletsController.cs b/BTCPayServer/Controllers/UIWalletsController.cs index 7de358d52..23acbf837 100644 --- a/BTCPayServer/Controllers/UIWalletsController.cs +++ b/BTCPayServer/Controllers/UIWalletsController.cs @@ -877,8 +877,7 @@ namespace BTCPayServer.Controllers try { var uriBuilder = new NBitcoin.Payment.BitcoinUrlBuilder(bip21, network.NBitcoinNetwork); - - vm.Outputs.Add(new WalletSendModel.TransactionOutput() + var output = new WalletSendModel.TransactionOutput { Amount = uriBuilder.Amount?.ToDecimal(MoneyUnit.BTC), DestinationAddress = uriBuilder.Address?.ToString(), @@ -886,15 +885,20 @@ namespace BTCPayServer.Controllers PayoutId = uriBuilder.UnknownParameters.ContainsKey("payout") ? uriBuilder.UnknownParameters["payout"] : null - }); + }; + if (!string.IsNullOrEmpty(uriBuilder.Label)) + { + output.Labels = output.Labels.Append(uriBuilder.Label).ToArray(); + } + vm.Outputs.Add(output); address = uriBuilder.Address; if (!string.IsNullOrEmpty(uriBuilder.Label) || !string.IsNullOrEmpty(uriBuilder.Message)) { - TempData.SetStatusMessageModel(new StatusMessageModel() + TempData.SetStatusMessageModel(new StatusMessageModel { Severity = StatusMessageModel.StatusSeverity.Info, Html = - $"Payment {(string.IsNullOrEmpty(uriBuilder.Label) ? string.Empty : $" to {uriBuilder.Label}")} {(string.IsNullOrEmpty(uriBuilder.Message) ? string.Empty : $" for {uriBuilder.Message}")}" + $"Payment {(string.IsNullOrEmpty(uriBuilder.Label) ? string.Empty : $" to {uriBuilder.Label}")} {(string.IsNullOrEmpty(uriBuilder.Message) ? string.Empty : $" for {uriBuilder.Message}")}" }); } @@ -926,7 +930,7 @@ namespace BTCPayServer.Controllers if (address is not null) { var addressLabels = await WalletRepository.GetWalletLabels(new WalletObjectId(walletId, WalletObjectData.Types.Address, address.ToString())); - vm.Outputs.Last().Labels = addressLabels.Select(tuple => tuple.Label).ToArray(); + vm.Outputs.Last().Labels = vm.Outputs.Last().Labels.Concat(addressLabels.Select(tuple => tuple.Label)).ToArray(); } } diff --git a/BTCPayServer/Views/UIWallets/WalletSend.cshtml b/BTCPayServer/Views/UIWallets/WalletSend.cshtml index 347300ff0..8fbb543ed 100644 --- a/BTCPayServer/Views/UIWallets/WalletSend.cshtml +++ b/BTCPayServer/Views/UIWallets/WalletSend.cshtml @@ -2,7 +2,6 @@ @using Microsoft.AspNetCore.Mvc.ModelBinding @using BTCPayServer.Controllers @using BTCPayServer.Services -@using Microsoft.AspNetCore.Mvc.TagHelpers @using BTCPayServer.Components.LabelManager @using BTCPayServer.Components.UIExtensionPoint @inject BTCPayServer.Security.ContentSecurityPolicies Csp