Providing additional parameter for info message (#5756)

* Providing additional parameter for info message

* Refactoring code to remove parameter and only set status message in LoadFromBIP21 if not present

* Update BTCPayServer/Controllers/UIWalletsController.cs

---------

Co-authored-by: Andrew Camilleri <evilkukka@gmail.com>
This commit is contained in:
rockstardev
2024-03-18 06:17:30 -05:00
committed by GitHub
parent 78f169cd24
commit b7ce6b7400

View File

@@ -459,11 +459,12 @@ namespace BTCPayServer.Controllers
}; };
if (bip21?.Any() is true) if (bip21?.Any() is true)
{ {
var messagePresent = TempData.HasStatusMessage();
foreach (var link in bip21) foreach (var link in bip21)
{ {
if (!string.IsNullOrEmpty(link)) if (!string.IsNullOrEmpty(link))
{ {
await LoadFromBIP21(walletId, model, link, network); await LoadFromBIP21(walletId, model, link, network, messagePresent);
} }
} }
} }
@@ -539,7 +540,6 @@ namespace BTCPayServer.Controllers
} }
catch (Exception ex) { model.RateError = ex.Message; } catch (Exception ex) { model.RateError = ex.Message; }
} }
return View(model); return View(model);
} }
@@ -575,7 +575,7 @@ namespace BTCPayServer.Controllers
if (!string.IsNullOrEmpty(bip21)) if (!string.IsNullOrEmpty(bip21))
{ {
vm.Outputs?.Clear(); vm.Outputs?.Clear();
await LoadFromBIP21(walletId, vm, bip21, network); await LoadFromBIP21(walletId, vm, bip21, network, TempData.HasStatusMessage());
} }
decimal transactionAmountSum = 0; decimal transactionAmountSum = 0;
@@ -870,7 +870,7 @@ namespace BTCPayServer.Controllers
private async Task LoadFromBIP21(WalletId walletId, WalletSendModel vm, string bip21, private async Task LoadFromBIP21(WalletId walletId, WalletSendModel vm, string bip21,
BTCPayNetwork network) BTCPayNetwork network, bool statusMessagePresent)
{ {
BitcoinAddress? address = null; BitcoinAddress? address = null;
vm.Outputs ??= new(); vm.Outputs ??= new();
@@ -892,6 +892,9 @@ namespace BTCPayServer.Controllers
} }
vm.Outputs.Add(output); vm.Outputs.Add(output);
address = uriBuilder.Address; address = uriBuilder.Address;
// only set SetStatusMessageModel if there is not message already or there is label / message in uri builder
if (!statusMessagePresent)
{
if (!string.IsNullOrEmpty(uriBuilder.Label) || !string.IsNullOrEmpty(uriBuilder.Message)) if (!string.IsNullOrEmpty(uriBuilder.Label) || !string.IsNullOrEmpty(uriBuilder.Message))
{ {
TempData.SetStatusMessageModel(new StatusMessageModel TempData.SetStatusMessageModel(new StatusMessageModel
@@ -901,6 +904,7 @@ namespace BTCPayServer.Controllers
$"Payment {(string.IsNullOrEmpty(uriBuilder.Label) ? string.Empty : $" to <strong>{uriBuilder.Label}</strong>")} {(string.IsNullOrEmpty(uriBuilder.Message) ? string.Empty : $" for <strong>{uriBuilder.Message}</strong>")}" $"Payment {(string.IsNullOrEmpty(uriBuilder.Label) ? string.Empty : $" to <strong>{uriBuilder.Label}</strong>")} {(string.IsNullOrEmpty(uriBuilder.Message) ? string.Empty : $" for <strong>{uriBuilder.Message}</strong>")}"
}); });
} }
}
if (uriBuilder.TryGetPayjoinEndpoint(out _)) if (uriBuilder.TryGetPayjoinEndpoint(out _))
vm.PayJoinBIP21 = uriBuilder.ToString(); vm.PayJoinBIP21 = uriBuilder.ToString();