mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-03-13 11:35:51 +01:00
Clip configuration values for payout processors
This commit is contained in:
parent
5c91e072a6
commit
c17572c76f
5 changed files with 25 additions and 3 deletions
|
@ -16,6 +16,11 @@ using PayoutProcessorData = BTCPayServer.Data.PayoutProcessorData;
|
|||
|
||||
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
|
||||
{
|
||||
protected readonly StoreRepository _storeRepository;
|
||||
|
@ -86,6 +91,12 @@ public abstract class BaseAutomatedPayoutProcessor<T> : BaseAsyncService where T
|
|||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using BTCPayServer.Abstractions.Constants;
|
||||
|
@ -66,6 +67,8 @@ public class UILightningAutomatedPayoutProcessorsController : Controller
|
|||
[Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Cookie)]
|
||||
public async Task<IActionResult> Configure(string storeId, string cryptoCode, LightningTransferViewModel automatedTransferBlob)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
return View(automatedTransferBlob);
|
||||
if (!_lightningAutomatedPayoutSenderFactory.GetSupportedPaymentMethods().Any(id =>
|
||||
id.CryptoCode.Equals(cryptoCode, StringComparison.InvariantCultureIgnoreCase)))
|
||||
{
|
||||
|
@ -120,7 +123,7 @@ public class UILightningAutomatedPayoutProcessorsController : Controller
|
|||
{
|
||||
IntervalMinutes = blob.Interval.TotalMinutes;
|
||||
}
|
||||
|
||||
[Range(AutomatedPayoutConstants.MinIntervalMinutes, AutomatedPayoutConstants.MaxIntervalMinutes)]
|
||||
public double IntervalMinutes { get; set; }
|
||||
|
||||
public AutomatedPayoutBlob ToBlob()
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using BTCPayServer.Abstractions.Constants;
|
||||
|
@ -79,6 +80,8 @@ public class UIOnChainAutomatedPayoutProcessorsController : Controller
|
|||
[Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Cookie)]
|
||||
public async Task<IActionResult> Configure(string storeId, string cryptoCode, OnChainTransferViewModel automatedTransferBlob)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
return View(automatedTransferBlob);
|
||||
if (!_onChainAutomatedPayoutSenderFactory.GetSupportedPaymentMethods().Any(id =>
|
||||
id.CryptoCode.Equals(cryptoCode, StringComparison.InvariantCultureIgnoreCase)))
|
||||
{
|
||||
|
@ -135,8 +138,10 @@ public class UIOnChainAutomatedPayoutProcessorsController : Controller
|
|||
FeeTargetBlock = blob.FeeTargetBlock;
|
||||
}
|
||||
|
||||
[Range(1, 1000)]
|
||||
public int FeeTargetBlock { get; set; }
|
||||
|
||||
[Range(AutomatedPayoutConstants.MinIntervalMinutes, AutomatedPayoutConstants.MaxIntervalMinutes)]
|
||||
public double IntervalMinutes { get; set; }
|
||||
|
||||
public OnChainAutomatedPayoutBlob ToBlob()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
@using BTCPayServer.Abstractions.Extensions
|
||||
@using BTCPayServer.Abstractions.Extensions
|
||||
@using BTCPayServer.Views.Stores
|
||||
@using Microsoft.AspNetCore.Mvc.TagHelpers
|
||||
@model BTCPayServer.PayoutProcessors.Lightning.UILightningAutomatedPayoutProcessorsController.LightningTransferViewModel
|
||||
|
@ -23,6 +23,7 @@
|
|||
<div class="input-group">
|
||||
<input asp-for="IntervalMinutes" class="form-control" inputmode="numeric" style="max-width:10ch;">
|
||||
<span class="input-group-text">minutes</span>
|
||||
<span asp-validation-for="IntervalMinutes" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
<button name="command" type="submit" class="btn btn-primary mt-2" value="Save" id="Save">Save</button>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
@using BTCPayServer.Abstractions.Extensions
|
||||
@using BTCPayServer.Abstractions.Extensions
|
||||
@using BTCPayServer.Views.Stores
|
||||
@model BTCPayServer.PayoutProcessors.OnChain.UIOnChainAutomatedPayoutProcessorsController.OnChainTransferViewModel
|
||||
@{
|
||||
|
@ -22,6 +22,7 @@
|
|||
<div class="input-group">
|
||||
<input asp-for="IntervalMinutes" class="form-control" inputmode="numeric" style="max-width:10ch;">
|
||||
<span class="input-group-text">minutes</span>
|
||||
<span asp-validation-for="IntervalMinutes" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
|
@ -29,6 +30,7 @@
|
|||
<div class="input-group">
|
||||
<input asp-for="FeeTargetBlock" class="form-control" min="1" inputmode="numeric" style="max-width:10ch;">
|
||||
<span class="input-group-text">blocks</span>
|
||||
<span asp-validation-for="FeeTargetBlock" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
<button name="command" type="submit" class="btn btn-primary mt-2" value="Save" id="Save">Save</button>
|
||||
|
|
Loading…
Add table
Reference in a new issue