From 26f3cffe5ce83a75db0ce6ddf8126fd2f2730d18 Mon Sep 17 00:00:00 2001 From: Umar Bolatov Date: Sun, 28 Nov 2021 22:26:30 -0800 Subject: [PATCH] Fix possible null reference exception when creating a pull payment (#3162) Co-authored-by: Andrew Camilleri --- .../Controllers/StorePullPaymentsController.PullPayments.cs | 6 +++++- BTCPayServer/Views/StorePullPayments/NewPullPayment.cshtml | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/BTCPayServer/Controllers/StorePullPaymentsController.PullPayments.cs b/BTCPayServer/Controllers/StorePullPaymentsController.PullPayments.cs index 70679217a..9e0bb7bb5 100644 --- a/BTCPayServer/Controllers/StorePullPaymentsController.PullPayments.cs +++ b/BTCPayServer/Controllers/StorePullPaymentsController.PullPayments.cs @@ -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(); 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) diff --git a/BTCPayServer/Views/StorePullPayments/NewPullPayment.cshtml b/BTCPayServer/Views/StorePullPayments/NewPullPayment.cshtml index 4f37e81b3..41563aa38 100644 --- a/BTCPayServer/Views/StorePullPayments/NewPullPayment.cshtml +++ b/BTCPayServer/Views/StorePullPayments/NewPullPayment.cshtml @@ -42,6 +42,7 @@ } +
Additional Options