Skip to content

Commit

Permalink
feat: filtering channels by funding wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
markettes committed Jul 18, 2023
1 parent fc85399 commit 0650215
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 12 deletions.
32 changes: 23 additions & 9 deletions src/Data/Models/Channel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,27 @@
*
*/

using System.ComponentModel.DataAnnotations.Schema;

namespace FundsManager.Data.Models
{
public class Channel : Entity
{

public enum ChannelStatus
{
Open = 1,
Closed = 2
}

public string FundingTx { get; set; }
public uint FundingTxOutputIndex { get; set; }

/// <summary>
/// Final Channel id by LND
/// </summary>
public ulong ChanId { get; set; }

/// <summary>
/// Capacity in SATS
/// </summary>
Expand All @@ -44,31 +46,43 @@ public enum ChannelStatus
public string? BtcCloseAddress { get; set; }

public ChannelStatus Status { get; set; }

/// <summary>
/// Indicates if this channel was created by NodeGuard
/// </summary>
public bool CreatedByNodeGuard { get; set; }

/// <summary>
/// Bool to indicate if this channel's liquidity should be automatically managed
/// </summary>
public bool IsAutomatedLiquidityEnabled { get; set; }

/// <summary>
/// Bool to indicate if this channel is private
/// </summary>
public bool IsPrivate { get; set; }

[NotMapped]
public int? OpenedWithId
{
get
{
if (ChannelOperationRequests != null && ChannelOperationRequests.Count > 0)
return ChannelOperationRequests.FirstOrDefault().Wallet.Id;
else
return null;
}
}

#region Relationships

public ICollection<ChannelOperationRequest> ChannelOperationRequests { get; set; }

public ICollection<LiquidityRule> LiquidityRules { get; set; }

public int SourceNodeId { get; set; }
public Node SourceNode { get; set; }

public int DestinationNodeId { get; set; }
public Node DestinationNode { get; set; }

Expand Down
42 changes: 39 additions & 3 deletions src/Pages/Channels.razor
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
<DropdownItem Disabled="@(checkDisableCloseChannelButton(context.Item))" Clicked="() => MarkAsClosed(context.Item)">Mark as closed</DropdownItem>
<DropdownItem Clicked="@(() => ShowModal(context.Item))">Requests</DropdownItem>
}

</DropdownMenu>
</Dropdown>
</DeleteCommandTemplate>
Expand Down Expand Up @@ -93,7 +92,27 @@
@context.Status.ToString("G")
</DisplayTemplate>
</DataGridColumn>

<DataGridColumn TItem="Channel" Field="@nameof(Channel.OpenedWithId)" Caption="Opened with" CustomFilter="OnWalletFilter" Filterable="true" Displayable="@IsColumnVisible(ChannelsColumnName.OpenedWith)">
<FilterTemplate>
<Select TValue="int" SelectedValue="@(_filterWalletId)" SelectedValueChanged="@(value => { _filterWalletId = value; context.TriggerFilterChange(_filterWalletId); })">
<SelectItem Value="@(0)">All</SelectItem>
@foreach (var wallet in _wallets)
{
<SelectItem Value="@(wallet.Id)">@wallet.Name</SelectItem>
}
</Select>
</FilterTemplate>
<DisplayTemplate>
@{
Wallet wallet = null;
if (context.OpenedWithId != null)
{
wallet = Task.Run(() => WalletRepository.GetById((int)context.OpenedWithId)).Result;
}
@(wallet == null ? "Unknown" : wallet.Name)
}
</DisplayTemplate>
</DataGridColumn>
<DataGridColumn TItem="Channel" Field="@nameof(Channel.FundingTx)" Caption="OutPoint" Filterable="false" Sortable="false" Displayable="@IsColumnVisible(ChannelsColumnName.Outpoint)">
<DisplayTemplate>
@StringHelper.TruncateHeadAndTail(context.FundingTx, 5):@context.FundingTxOutputIndex
Expand Down Expand Up @@ -332,6 +351,8 @@
private int _sourceNodeIdFilter = 0;
private int _destinationNodeIdFilter = 0;
private List<Node> _nodes = new List<Node>();
private List<Wallet> _wallets = new List<Wallet>();
private int _filterWalletId;

[CascadingParameter]
private ApplicationUser? LoggedUser { get; set; }
Expand All @@ -350,6 +371,7 @@
public static readonly ColumnDefault SourceNode = new("Source Node");
public static readonly ColumnDefault DestinationNode = new("Destination Node");
public static readonly ColumnDefault Status = new("Status");
public static readonly ColumnDefault OpenedWith = new("Opened With");
public static readonly ColumnDefault Outpoint = new("Outpoint");
public static readonly ColumnDefault Capacity = new("Capacity (BTC)");
public static readonly ColumnDefault Private = new("Private");
Expand Down Expand Up @@ -382,6 +404,7 @@
_availableWallets = await WalletRepository.GetAvailableWallets();
_channels = await ChannelRepository.GetAllManagedByUserNodes(LoggedUser.Id);
_nodes = await NodeRepository.GetAll();
_wallets = await WalletRepository.GetAll();
_channelsDataGridRef.FilterData();
}

Expand Down Expand Up @@ -692,6 +715,19 @@
return true;
}

private bool OnWalletFilter(object itemValue, object searchValue)
{
if (searchValue == null || (int)searchValue == 0)
{
return true;
}
if (itemValue == null) return false;
if ((int)itemValue == (int)searchValue)
{
return true;
}
return false;
}

private bool OnSourceNodeIdFilter(object itemValue, object searchValue)
{
Expand Down Expand Up @@ -750,7 +786,7 @@

private bool IsColumnVisible(ColumnDefault column)
{
if (ChannelsColumnLayout == null)
if (ChannelsColumnLayout == null)
{
return true;
}
Expand Down

0 comments on commit 0650215

Please sign in to comment.