Clip configuration values for payout processors

This commit is contained in:
nicolas.dorier
2023-04-26 18:24:46 +09:00
parent 5c91e072a6
commit c17572c76f
5 changed files with 25 additions and 3 deletions

View File

@@ -16,6 +16,11 @@ using PayoutProcessorData = BTCPayServer.Data.PayoutProcessorData;
namespace BTCPayServer.PayoutProcessors; namespace BTCPayServer.PayoutProcessors;
public class AutomatedPayoutConstants
{
public const double MinIntervalMinutes = 10.0;
public const double MaxIntervalMinutes = 60.0;
}
public abstract class BaseAutomatedPayoutProcessor<T> : BaseAsyncService where T : AutomatedPayoutBlob public abstract class BaseAutomatedPayoutProcessor<T> : BaseAsyncService where T : AutomatedPayoutBlob
{ {
protected readonly StoreRepository _storeRepository; protected readonly StoreRepository _storeRepository;
@@ -86,6 +91,12 @@ public abstract class BaseAutomatedPayoutProcessor<T> : BaseAsyncService where T
new AfterPayoutFilterData(store, paymentMethod, payouts)); new AfterPayoutFilterData(store, paymentMethod, payouts));
} }
} }
// Clip interval
if (blob.Interval < TimeSpan.FromMinutes(AutomatedPayoutConstants.MinIntervalMinutes))
blob.Interval = TimeSpan.FromMinutes(AutomatedPayoutConstants.MinIntervalMinutes);
if (blob.Interval > TimeSpan.FromMinutes(AutomatedPayoutConstants.MaxIntervalMinutes))
blob.Interval = TimeSpan.FromMinutes(AutomatedPayoutConstants.MaxIntervalMinutes);
await Task.Delay(blob.Interval, CancellationToken); await Task.Delay(blob.Interval, CancellationToken);
} }

View File

@@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using BTCPayServer.Abstractions.Constants; using BTCPayServer.Abstractions.Constants;
@@ -66,6 +67,8 @@ public class UILightningAutomatedPayoutProcessorsController : Controller
[Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Cookie)] [Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Cookie)]
public async Task<IActionResult> Configure(string storeId, string cryptoCode, LightningTransferViewModel automatedTransferBlob) public async Task<IActionResult> Configure(string storeId, string cryptoCode, LightningTransferViewModel automatedTransferBlob)
{ {
if (!ModelState.IsValid)
return View(automatedTransferBlob);
if (!_lightningAutomatedPayoutSenderFactory.GetSupportedPaymentMethods().Any(id => if (!_lightningAutomatedPayoutSenderFactory.GetSupportedPaymentMethods().Any(id =>
id.CryptoCode.Equals(cryptoCode, StringComparison.InvariantCultureIgnoreCase))) id.CryptoCode.Equals(cryptoCode, StringComparison.InvariantCultureIgnoreCase)))
{ {
@@ -120,7 +123,7 @@ public class UILightningAutomatedPayoutProcessorsController : Controller
{ {
IntervalMinutes = blob.Interval.TotalMinutes; IntervalMinutes = blob.Interval.TotalMinutes;
} }
[Range(AutomatedPayoutConstants.MinIntervalMinutes, AutomatedPayoutConstants.MaxIntervalMinutes)]
public double IntervalMinutes { get; set; } public double IntervalMinutes { get; set; }
public AutomatedPayoutBlob ToBlob() public AutomatedPayoutBlob ToBlob()

View File

@@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using BTCPayServer.Abstractions.Constants; using BTCPayServer.Abstractions.Constants;
@@ -79,6 +80,8 @@ public class UIOnChainAutomatedPayoutProcessorsController : Controller
[Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Cookie)] [Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Cookie)]
public async Task<IActionResult> Configure(string storeId, string cryptoCode, OnChainTransferViewModel automatedTransferBlob) public async Task<IActionResult> Configure(string storeId, string cryptoCode, OnChainTransferViewModel automatedTransferBlob)
{ {
if (!ModelState.IsValid)
return View(automatedTransferBlob);
if (!_onChainAutomatedPayoutSenderFactory.GetSupportedPaymentMethods().Any(id => if (!_onChainAutomatedPayoutSenderFactory.GetSupportedPaymentMethods().Any(id =>
id.CryptoCode.Equals(cryptoCode, StringComparison.InvariantCultureIgnoreCase))) id.CryptoCode.Equals(cryptoCode, StringComparison.InvariantCultureIgnoreCase)))
{ {
@@ -135,8 +138,10 @@ public class UIOnChainAutomatedPayoutProcessorsController : Controller
FeeTargetBlock = blob.FeeTargetBlock; FeeTargetBlock = blob.FeeTargetBlock;
} }
[Range(1, 1000)]
public int FeeTargetBlock { get; set; } public int FeeTargetBlock { get; set; }
[Range(AutomatedPayoutConstants.MinIntervalMinutes, AutomatedPayoutConstants.MaxIntervalMinutes)]
public double IntervalMinutes { get; set; } public double IntervalMinutes { get; set; }
public OnChainAutomatedPayoutBlob ToBlob() public OnChainAutomatedPayoutBlob ToBlob()

View File

@@ -1,4 +1,4 @@
@using BTCPayServer.Abstractions.Extensions @using BTCPayServer.Abstractions.Extensions
@using BTCPayServer.Views.Stores @using BTCPayServer.Views.Stores
@using Microsoft.AspNetCore.Mvc.TagHelpers @using Microsoft.AspNetCore.Mvc.TagHelpers
@model BTCPayServer.PayoutProcessors.Lightning.UILightningAutomatedPayoutProcessorsController.LightningTransferViewModel @model BTCPayServer.PayoutProcessors.Lightning.UILightningAutomatedPayoutProcessorsController.LightningTransferViewModel
@@ -23,6 +23,7 @@
<div class="input-group"> <div class="input-group">
<input asp-for="IntervalMinutes" class="form-control" inputmode="numeric" style="max-width:10ch;"> <input asp-for="IntervalMinutes" class="form-control" inputmode="numeric" style="max-width:10ch;">
<span class="input-group-text">minutes</span> <span class="input-group-text">minutes</span>
<span asp-validation-for="IntervalMinutes" class="text-danger"></span>
</div> </div>
</div> </div>
<button name="command" type="submit" class="btn btn-primary mt-2" value="Save" id="Save">Save</button> <button name="command" type="submit" class="btn btn-primary mt-2" value="Save" id="Save">Save</button>

View File

@@ -1,4 +1,4 @@
@using BTCPayServer.Abstractions.Extensions @using BTCPayServer.Abstractions.Extensions
@using BTCPayServer.Views.Stores @using BTCPayServer.Views.Stores
@model BTCPayServer.PayoutProcessors.OnChain.UIOnChainAutomatedPayoutProcessorsController.OnChainTransferViewModel @model BTCPayServer.PayoutProcessors.OnChain.UIOnChainAutomatedPayoutProcessorsController.OnChainTransferViewModel
@{ @{
@@ -22,6 +22,7 @@
<div class="input-group"> <div class="input-group">
<input asp-for="IntervalMinutes" class="form-control" inputmode="numeric" style="max-width:10ch;"> <input asp-for="IntervalMinutes" class="form-control" inputmode="numeric" style="max-width:10ch;">
<span class="input-group-text">minutes</span> <span class="input-group-text">minutes</span>
<span asp-validation-for="IntervalMinutes" class="text-danger"></span>
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
@@ -29,6 +30,7 @@
<div class="input-group"> <div class="input-group">
<input asp-for="FeeTargetBlock" class="form-control" min="1" inputmode="numeric" style="max-width:10ch;"> <input asp-for="FeeTargetBlock" class="form-control" min="1" inputmode="numeric" style="max-width:10ch;">
<span class="input-group-text">blocks</span> <span class="input-group-text">blocks</span>
<span asp-validation-for="FeeTargetBlock" class="text-danger"></span>
</div> </div>
</div> </div>
<button name="command" type="submit" class="btn btn-primary mt-2" value="Save" id="Save">Save</button> <button name="command" type="submit" class="btn btn-primary mt-2" value="Save" id="Save">Save</button>