Skip to content

Commit ac667ef

Browse files
authored
[GEN-1789] Introduce query-level pagination for swaps view (#442)
* refactor: rename ReturningFundsWallet to FundsDestinationWallet and add auto liquidity management Renamed ReturningFundsWallet property to FundsDestinationWallet across Node model, AutoMapper profile, and repository to better reflect its expanded purpose. Added comprehensive automatic liquidity management configuration including swap parameters, budget controls, and balance thresholds for node-level automated operations. * feat: add NodeLevelLiquidySwapOutAuto database migration Add Entity Framework migration to support node-level liquidity swap out automation functionality with comprehensive model updates and relationship mappings. * make swap configuration properties non-nullable with defaults Remove nullable modifiers from Node swap configuration properties and set appropriate default values in migration to ensure required swap parameters are always available for automatic liquidity management. * implement liquidity management modal and configuration for nodes, removed from old edit sweeping config * Removed unnecesary validation * Remove unnecessary validation for swap fee, balance threshold, swap budget, and budget refresh interval * Reduce if nesting * feat: add configurable swap out size limits for automatic liquidity management Add MINIMUM_SWAP_OUT_SIZE_BTC and MAXIMUM_SWAP_OUT_SIZE_BTC constants with default values of 0.01 and 0.5 BTC respectively. These limits can be configured via environment variables and are now used throughout the UI validation instead of hardcoded values. * refactor: remove unnecessary error toast for validation failures in liquidity management * Removed unnecesary validation * Use numeric picker to be able to introduce 0,0X decimal values * Rename swap out fee limit to routing fee limit for simplicity as we wont quote and just call like autoloop does + migration and leftovers * Missing routing term * removal useless comment * feat: add auto liquidity management with swap tracking and budget controls - Add GetInFlightSwapsByNode and GetConsumedFeesSince methods to SwapOutRepository - Implement 24-hour time window for in-flight swap tracking to prevent deadlocks - Add budget tracking functionality to calculate consumed fees since a specific date - Introduce AUTO_LIQUIDITY_MANAGEMENT_INTERVAL_MINUTES constant for job scheduling - Refactor swap size constants to be configurable via environment variables - Add comprehensive liquidity management parameters for automatic swap operations * feat: add automated liquidity management job for Lightning nodes Implements background job to automatically manage node liquidity through swap operations based on configurable thresholds and budgets. Includes balance monitoring, swap-out execution, and destination address generation with comprehensive error handling and logging. * Undo wrong merge * refactor: simplify logging in AutoLiquidityManagementJob execution * feat: improve logging by displaying amounts in BTC instead of satoshis Convert all balance, threshold, swap amount, and budget logging from satoshi values to BTC units for better readability. This makes the logs more user-friendly while maintaining the same functionality for liquidity management operations. * Deprecated removal * Fix params for swaps out * Local dev params to test * Introduce query-level pagination for swaps view Add paginated data retrieval for swap out records to improve performance and user experience. Includes pagination method in repository interface and implementation, updates UI component to use server-side pagination, and enhances requestor display to show "Autoswap" for non-manual swaps. * feat: adjust AutoLiquidityManagementJob interval for development environment * Remove GetAll from Swap Out repo * feat: add method to retrieve nodes with auto liquidity management enabled * refactor: remove disallow concurrent execution from AutoLiquidityManagementJob
1 parent 71df2ce commit ac667ef

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

src/Data/Repositories/Interfaces/ISwapOutRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public interface ISwapOutRepository
2626
{
2727
Task<SwapOut?> GetById(int id);
2828
Task<List<SwapOut>> GetByIds(List<int> ids);
29-
Task<List<SwapOut>> GetAll();
29+
Task<(List<SwapOut> swaps, int totalCount)> GetPaginatedAsync(int pageNumber, int pageSize);
3030
Task<List<SwapOut>> GetAllPending();
3131
Task<(bool, string?)> AddAsync(SwapOut swap);
3232
Task<(bool, string?)> AddRangeAsync(List<SwapOut> swaps);

src/Data/Repositories/SwapOutRepository.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,25 @@ public async Task<List<SwapOut>> GetByIds(List<int> ids)
6060
return swaps;
6161
}
6262

63-
public async Task<List<SwapOut>> GetAll()
63+
public async Task<(List<SwapOut> swaps, int totalCount)> GetPaginatedAsync(int pageNumber, int pageSize)
6464
{
6565
await using var context = await _dbContextFactory.CreateDbContextAsync();
6666

67-
var swaps = await context.SwapOuts
67+
var query = context.SwapOuts
6868
.Include(s => s.DestinationWallet)
6969
.ThenInclude(w => w!.Keys)
7070
.Include(s => s.UserRequestor)
7171
.Include(s => s.Node)
72+
.OrderByDescending(s => s.CreationDatetime);
73+
74+
var totalCount = await query.CountAsync();
75+
76+
var swaps = await query
77+
.Skip((pageNumber - 1) * pageSize)
78+
.Take(pageSize)
7279
.ToListAsync();
7380

74-
return swaps;
81+
return (swaps, totalCount);
7582
}
7683

7784
public async Task<List<SwapOut>> GetAllPending()

src/Pages/Swaps.razor

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@page "/swaps"
22
@using System.Security.Claims
33
@using Humanizer
4+
@using Blazorise
45
@attribute [Authorize(Roles = "Superadmin,NodeManager,FinanceManager")]
56

67
<Row>
@@ -9,6 +10,8 @@
910
<DataGrid TItem="SwapOut"
1011
@ref="_swapsDatagrid"
1112
Data="@_swapRequests"
13+
ReadData="@OnReadData"
14+
TotalItems="@_totalItems"
1215
Filterable="true"
1316
FilterMethod="DataGridFilterMethod.Contains"
1417
Editable="true"
@@ -47,7 +50,7 @@
4750
</DataGridColumn>
4851
<DataGridColumn TItem="SwapOut" Editable="false" Field="@nameof(SwapOut.UserRequestor)" Caption="Requestor" Sortable="true" Displayable="@IsColumnVisible(SwapsColumnName.Requestor)">
4952
<DisplayTemplate>
50-
@(context.UserRequestor?.UserName ?? "Unknown")
53+
@(context.IsManual ? (context.UserRequestor?.UserName ?? "Unknown") : "Autoswap")
5154
</DisplayTemplate>
5255
</DataGridColumn>
5356
<DataGridColumn TItem="SwapOut" Editable="false" Field="@nameof(SwapOut.Amount)" Caption="Amount (BTC)" Sortable="false" Displayable="@IsColumnVisible(SwapsColumnName.Amount)">
@@ -129,6 +132,9 @@
129132
private bool _columnsLoaded;
130133
private ColumnLayout<SwapsColumnName> _swapsColumnLayout = new();
131134
public required NewSwapModal _newSwapModal;
135+
private int _totalItems;
136+
private int _currentPage = 1;
137+
private int _pageSize = 10;
132138

133139
public abstract class SwapsColumnName
134140
{
@@ -151,7 +157,17 @@
151157
ToastService.ShowError("Bitcoin price in USD could not be retrieved.");
152158
}
153159
_availableNodes = await NodeRepository.GetAllManagedByUser(LoggedUser.Id);
154-
_swapRequests = await SwapOutRepository.GetAll();
160+
}
161+
162+
private async Task OnReadData(DataGridReadDataEventArgs<SwapOut> e)
163+
{
164+
if (!e.CancellationToken.IsCancellationRequested)
165+
{
166+
var (swaps, totalCount) = await SwapOutRepository.GetPaginatedAsync(e.Page, e.PageSize);
167+
168+
_swapRequests = swaps;
169+
_totalItems = totalCount;
170+
}
155171
}
156172

157173
protected override async Task OnAfterRenderAsync(bool firstRender)
@@ -201,8 +217,7 @@
201217

202218
private async Task OnSwapCreated()
203219
{
204-
_swapRequests = await SwapOutRepository.GetAll();
205-
StateHasChanged();
220+
await _swapsDatagrid.Reload();
206221
}
207222
}
208223

0 commit comments

Comments
 (0)