Fix DivideByZeroException raised if crowdfund's target amount is 0 (#3747) (#3748)

This commit is contained in:
Nicolas Dorier
2022-05-17 14:34:06 +09:00
committed by GitHub
parent a9a9f26aa0
commit f3f605a90f
2 changed files with 19 additions and 1 deletions

View File

@@ -88,6 +88,10 @@ namespace BTCPayServer.Controllers
{
ModelState.AddModelError(nameof(vm.PerksTemplate), "Invalid template");
}
if (vm.TargetAmount is decimal v && v == 0.0m)
{
vm.TargetAmount = null;
}
if (Enum.Parse<CrowdfundResetEvery>(vm.ResetEvery) != CrowdfundResetEvery.Never && !vm.StartDate.HasValue)
{

View File

@@ -12,7 +12,21 @@ namespace BTCPayServer.Services.Apps
public DateTime? EndDate { get; set; }
public string TargetCurrency { get; set; }
public decimal? TargetAmount { get; set; }
decimal? _TargetAmount;
public decimal? TargetAmount
{
get
{
// In the past, target amount might have been 0, creating exception
if (_TargetAmount is decimal v && v == 0.0m)
return null;
return _TargetAmount;
}
set
{
_TargetAmount = value;
}
}
public bool EnforceTargetAmount { get; set; }
public string CustomCSSLink { get; set; }