Fix possible null reference exception when creating a pull payment (#3162)

Co-authored-by: Andrew Camilleri <evilkukka@gmail.com>
This commit is contained in:
Umar Bolatov
2021-11-28 22:26:30 -08:00
committed by GitHub
parent 8f0d82d219
commit 26f3cffe5c
2 changed files with 6 additions and 1 deletions

View File

@@ -95,9 +95,13 @@ namespace BTCPayServer.Controllers
model.PaymentMethodItems =
paymentMethodOptions.Select(id => new SelectListItem(id.ToPrettyString(), id.ToString(), true));
model.Name ??= string.Empty;
model.Currency = model.Currency.ToUpperInvariant().Trim();
model.Currency = model.Currency?.ToUpperInvariant()?.Trim() ?? String.Empty;
model.PaymentMethods ??= new List<string>();
if (!model.PaymentMethods.Any())
{
// Since we assign all payment methods to be selected by default above we need to update
// them here to reflect user's selection so that they can correct their mistake
model.PaymentMethodItems = paymentMethodOptions.Select(id => new SelectListItem(id.ToPrettyString(), id.ToString(), false));
ModelState.AddModelError(nameof(model.PaymentMethods), "You need at least one payment method");
}
if (_currencyNameTable.GetCurrencyData(model.Currency, false) is null)

View File

@@ -42,6 +42,7 @@
</label>
</div>
}
<span asp-validation-for="PaymentMethods" class="text-danger mt-0"></span>
</div>
<h5 class="mt-4 mb-2">Additional Options</h5>