mirror of
https://github.com/aljazceru/BTCPayServerPlugins.git
synced 2025-12-17 07:34:24 +01:00
many fixes to prism ui
This commit is contained in:
@@ -29,8 +29,12 @@
|
||||
<span class="form-text">When a payout is being generated, how much of its amount in percentage should be excluded to cover the fee? Once the payment is settled, if the lightning node provides the exact fee, the balance is adjusted accordingly. Leave blank to use default setting.</span>
|
||||
</div>
|
||||
<div>
|
||||
<button type="button" class="btn btn-primary" @onclick="Update">Update</button>
|
||||
<button type="button" class="btn btn-primary" @onclick="Update">@(string.IsNullOrEmpty(OriginalWorkingId)? "Create": "Update")</button>
|
||||
<button type="button" class="btn btn-secondary" @onclick="Cancel">Cancel</button>
|
||||
@if (!string.IsNullOrEmpty(OriginalWorkingId))
|
||||
{
|
||||
<button type="button" class="btn btn-outline-danger" @onclick="() => SettingsChanged.InvokeAsync(null)">Remove</button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -42,7 +46,8 @@
|
||||
private string WorkingId { get; set; }
|
||||
private string OriginalWorkingId { get; set; }
|
||||
|
||||
|
||||
[Parameter]
|
||||
public EventCallback OnCancel { get; set; }
|
||||
[Parameter]
|
||||
public Func<string, bool> ValidateDestination { get; set; }
|
||||
|
||||
@@ -68,6 +73,7 @@
|
||||
{
|
||||
if (OriginalWorkingId != value )
|
||||
{
|
||||
|
||||
WorkingId = value;
|
||||
OriginalWorkingId = value;
|
||||
InvalidId = false;
|
||||
@@ -87,8 +93,7 @@
|
||||
{
|
||||
return;
|
||||
}
|
||||
await SettingsChanged.InvokeAsync(WorkingCopy);
|
||||
await IdChanged.InvokeAsync(WorkingId);
|
||||
await IdChanged.InvokeAsync(WorkingId).ContinueWith(task => SettingsChanged.InvokeAsync(WorkingCopy));
|
||||
}
|
||||
|
||||
[Parameter]
|
||||
@@ -98,4 +103,9 @@
|
||||
public EventCallback<string> IdChanged { get; set; }
|
||||
|
||||
|
||||
private Task Cancel()
|
||||
{
|
||||
return OnCancel.InvokeAsync(null);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
@* @using NBitcoin *@
|
||||
@* @if (Destinations.Any()) *@
|
||||
@* { *@
|
||||
@* <div class="form-group"> *@
|
||||
@* <select class="form-select" @bind="SelectedDestinationId"> *@
|
||||
@* *@
|
||||
@* <option value="null">Select destination to configure</option> *@
|
||||
@* @foreach (var destination in Destinations) *@
|
||||
@* { *@
|
||||
@* <option value="@destination.Key">@destination.Key</option> *@
|
||||
@* } *@
|
||||
@* </select> *@
|
||||
@* </div> *@
|
||||
@* *@
|
||||
@* @if (SelectedDestinationId is not null && SelectedDestinationId != "null") *@
|
||||
@* { *@
|
||||
@* <PrismDestinationEditor ValidateId="ValidateId" Id="@SelectedDestinationId" IdChanged="OnIdRenamed" ValidateDestination="s => ValidateDestination(s, false)" @bind-Settings="SelectedDestination"></PrismDestinationEditor> *@
|
||||
@* } *@
|
||||
@* } *@
|
||||
@* *@
|
||||
@* @code { *@
|
||||
@* *@
|
||||
@* [Parameter] *@
|
||||
@* public Dictionary<string, PrismDestination> Destinations { get; set; } *@
|
||||
@* *@
|
||||
@* *@
|
||||
@* public string? SelectedDestinationId { get; set; } *@
|
||||
@* *@
|
||||
@* public PrismDestination? SelectedDestination *@
|
||||
@* { *@
|
||||
@* get *@
|
||||
@* { *@
|
||||
@* if (SelectedDestinationId is null or "null") *@
|
||||
@* return null; *@
|
||||
@* Destinations.TryGetValue(SelectedDestinationId, out var res); *@
|
||||
@* return res; *@
|
||||
@* } *@
|
||||
@* set *@
|
||||
@* { *@
|
||||
@* if (SelectedDestinationId is null) *@
|
||||
@* return; *@
|
||||
@* if (value is null) *@
|
||||
@* { *@
|
||||
@* Destinations.Remove(SelectedDestinationId); *@
|
||||
@* SelectedDestinationId = null; *@
|
||||
@* } *@
|
||||
@* else *@
|
||||
@* { *@
|
||||
@* Destinations.AddOrReplace(SelectedDestinationId, value); *@
|
||||
@* } *@
|
||||
@* } *@
|
||||
@* } *@
|
||||
@* *@
|
||||
@* } *@
|
||||
@@ -66,7 +66,15 @@ else
|
||||
|
||||
<EditForm EditContext="EditContext" OnValidSubmit="Save">
|
||||
|
||||
<div class="row">
|
||||
|
||||
|
||||
<div class="row" id="prism-holder">
|
||||
|
||||
<div class="prism col-sm-12 border border-light p-2">
|
||||
@if (SelectedDestinationId is null or "null")
|
||||
{
|
||||
<h2>Global Prism Settings</h2>
|
||||
<div class="row mb-4">
|
||||
<div class="col-xl-10 col-xxl-constrain">
|
||||
|
||||
<div class="form-group form-check">
|
||||
@@ -91,31 +99,38 @@ else
|
||||
|
||||
</div>
|
||||
|
||||
<div class="row" id="prism-holder">
|
||||
|
||||
<div class="prism col-sm-12 col-md-8 border border-light p-2">
|
||||
@if(Settings.Splits.Any())
|
||||
{
|
||||
<h2>Your Prisms</h2>
|
||||
@foreach (var item in Settings.Splits)
|
||||
{
|
||||
<PrismSplit Split="@item" OnRequestRemove="@RemovePrism"/>
|
||||
}
|
||||
</div>
|
||||
<div class="prism col-sm-12 col-md-4 border border-light p-2">
|
||||
@if (Destinations.Any())
|
||||
{
|
||||
<div class="form-group">
|
||||
<select class="form-select" @bind="SelectedDestinationId">
|
||||
|
||||
<option value="null">Select destination to configure</option>
|
||||
@foreach (var destination in Destinations)
|
||||
{
|
||||
<option value="@destination">@destination</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
@if (SelectedDestinationId is not null && SelectedDestinationId != "null")
|
||||
{
|
||||
<PrismDestinationEditor ValidateId="ValidateId" Id="@SelectedDestinationId" IdChanged="OnIdRenamed" ValidateDestination="s => ValidateDestination(s, false)" @bind-Settings="SelectedDestination"></PrismDestinationEditor>
|
||||
switch (SelectedDestinationId)
|
||||
{
|
||||
case "":
|
||||
<h2>Create new Destination</h2>
|
||||
break;
|
||||
default:
|
||||
<h2>Editing @SelectedDestinationId Destination</h2>
|
||||
break;
|
||||
}
|
||||
|
||||
<PrismDestinationEditor
|
||||
ValidateId="ValidateId"
|
||||
ValidateDestination="s => ValidateDestination(s, false)"
|
||||
Id="@SelectedDestinationId"
|
||||
IdChanged="OnIdRenamed"
|
||||
@bind-Settings="SelectedDestination"
|
||||
OnCancel="o => SelectedDestinationId = null">
|
||||
</PrismDestinationEditor>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
@@ -130,9 +145,22 @@ else
|
||||
}
|
||||
<div class="row">
|
||||
<div class="d-flex">
|
||||
@if (SelectedDestinationId is null or "null")
|
||||
{
|
||||
|
||||
<button type="button" class="btn btn-primary mx-2" id="add-prism" @onclick="CreateNewPrism">Add Prism</button>
|
||||
<button type="button" class="btn btn-primary mx-2" id="add-destination" @onclick="AddDestination">Add Destination</button>
|
||||
<button type="submit" class="btn btn-primary mx-2">Save</button>
|
||||
<select class="form-select mx-2" style="max-width: fit-content" @bind="SelectedDestinationId" disabled="@(SelectedDestinationId is not null && SelectedDestinationId != "null")">
|
||||
|
||||
<option value="null">Select destination to configure</option>
|
||||
@foreach (var destination in Destinations)
|
||||
{
|
||||
<option value="@destination">@destination</option>
|
||||
}
|
||||
<option value="">Create new destination</option>
|
||||
</select>
|
||||
}
|
||||
|
||||
@if (PrismEditButtonsFilter is not null)
|
||||
{
|
||||
@((MarkupString) PrismEditButtonsFilter)
|
||||
@@ -151,7 +179,7 @@ else
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
public string? SelectedDestinationId { get; set; }
|
||||
public string? SelectedDestinationId { get; set; } = "null";
|
||||
|
||||
public PrismDestination? SelectedDestination
|
||||
{
|
||||
@@ -169,12 +197,23 @@ else
|
||||
if (value is null)
|
||||
{
|
||||
Settings.Destinations.Remove(SelectedDestinationId);
|
||||
|
||||
foreach (var settingsSplit in Settings.Splits)
|
||||
{
|
||||
settingsSplit.Destinations.RemoveAll(split => split.Destination == SelectedDestinationId);
|
||||
}
|
||||
|
||||
SelectedDestinationId = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
Settings.Destinations.AddOrReplace(SelectedDestinationId, value);
|
||||
|
||||
SelectedDestinationId = "null";
|
||||
}
|
||||
|
||||
_ = SaveDestinations();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,6 +225,7 @@ else
|
||||
public bool NoPayoutProcessors { get; set; }
|
||||
|
||||
private string PrismEditButtonsFilter { get; set; }
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (firstRender)
|
||||
@@ -347,6 +387,13 @@ else
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SaveDestinations()
|
||||
{
|
||||
var settz = await SatBreaker.Get(StoreId);
|
||||
settz.Destinations = Settings.Destinations;
|
||||
await UpdateAndShowResult(settz);
|
||||
}
|
||||
|
||||
private async Task Save()
|
||||
{
|
||||
var settz = await SatBreaker.Get(StoreId);
|
||||
@@ -356,6 +403,11 @@ else
|
||||
settz.SatThreshold = Settings.SatThreshold;
|
||||
settz.Reserve = Settings.Reserve;
|
||||
Settings = settz;
|
||||
await UpdateAndShowResult(settz);
|
||||
}
|
||||
|
||||
private async Task UpdateAndShowResult(PrismSettings settz)
|
||||
{
|
||||
var updateResult = await SatBreaker.UpdatePrismSettingsForStore(StoreId, settz);
|
||||
|
||||
if (!updateResult)
|
||||
@@ -406,6 +458,11 @@ else
|
||||
{
|
||||
if (SelectedDestinationId == s)
|
||||
return;
|
||||
if (string.IsNullOrEmpty(SelectedDestinationId))
|
||||
{
|
||||
SelectedDestinationId = s;
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
await SatBreaker._updateLock.WaitAsync();
|
||||
@@ -451,11 +508,11 @@ else
|
||||
Settings.DestinationBalance.AddOrReplace(obj.destination, obj.newBalance);
|
||||
}
|
||||
await SatBreaker.UpdatePrismSettingsForStore(StoreId, Settings, true);
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
SatBreaker._updateLock.Release();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user