Skip to content

Commit

Permalink
Merge pull request #213 from Elenpay/wallet-balance-in-channel-request
Browse files Browse the repository at this point in the history
Wallet balance in channel request
  • Loading branch information
RodriFS authored Jun 26, 2023
2 parents d442601 + 902b16a commit fce918f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 32 deletions.
57 changes: 28 additions & 29 deletions src/Pages/ChannelRequests.razor
Original file line number Diff line number Diff line change
Expand Up @@ -91,34 +91,29 @@
</DisplayTemplate>
<EditTemplate>
<Validation Validator="@ValidationRule.IsSelected" @ref="_walletValidation">
@if (context.CellValue == null || (int)context.CellValue == 0)
{
<SelectList TItem="Wallet"
TValue="int"
Data="@_allWallets"
TextField="@((item) => item.Name)"
ValueField="@((item) => item.Id)"
SelectedValueChanged="(id) => OnSelectedWallet(id)"
DefaultItemText="Choose the wallet">
<Feedback>
<ValidationError/>
</Feedback>
</SelectList>
}
else
{
<SelectList TItem="Wallet"
TValue="int"
Data="@_allWallets"
TextField="@((item) => item.Name)"
ValueField="@((item) => item.Id)"
SelectedValueChanged="(id) => OnSelectedWallet(id)"
SelectedValue="(int)context.CellValue">
<Feedback>
<ValidationError/>
</Feedback>
</SelectList>
}
<SelectList TItem="Wallet"
TValue="int?"
DefaultItemText="Choose the wallet"
DefaultItemDisabled
Data="@_allWallets"
TextField="@((item) => item.Name)"
ValueField="@((item) => item.Id)"
SelectedValueChanged="(id) => OnSelectedWallet(id.Value)"
SelectedValue="@(_selectedWalletId)">
<Feedback>
<ValidationError/>
</Feedback>
</SelectList>
<FieldHelp>
@if (_selectedWalletId != null)
{
@($"{_selectedWalletBalance:f8} BTC ({Math.Round(PriceConversionHelper.BtcToUsdConversion(_selectedWalletBalance, _btcPrice), 2)} USD)")
}
else
{
@("Wallet not selected")
}
</FieldHelp>
</Validation>
</EditTemplate>
</DataGridColumn>
Expand Down Expand Up @@ -422,6 +417,7 @@
private int _selectedSourceNodeId;
private Node? _selectedDestNode;
private int? _selectedWalletId;
private decimal _selectedWalletBalance;
private string? _destNodeName;
private static readonly decimal _minimumChannelCapacity = new Money(Constants.MINIMUM_CHANNEL_CAPACITY_SATS).ToUnit(MoneyUnit.BTC);
private decimal _amount { get; set; } = _minimumChannelCapacity;
Expand Down Expand Up @@ -523,9 +519,12 @@
_selectedSourceNodeId = nodeId;
}

private void OnSelectedWallet(int walletId)
private async Task OnSelectedWallet(int walletId)
{
_selectedWalletId = walletId == 0 ? null : walletId;
var wallet = _allWallets.Find(w => w.Id == _selectedWalletId);
var balance = (await LightningService.GetWalletBalance(wallet))?.Available ?? new Money(0);
_selectedWalletBalance = ((Money)balance).ToUnit(MoneyUnit.BTC);
}

private async Task SearchNode()
Expand Down
21 changes: 18 additions & 3 deletions src/Shared/UTXOSelectorModal.razor
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@
@if (_selectedStrategy == CoinSelectionStrategy.ClosestToTargetFirst)
{
<Field>
<FieldLabel>Target</FieldLabel>
<FieldLabel Class="d-flex">
Target
<Tooltip Text="Order of the UTXOs around how close they are to this target amount" Placement="TooltipPlacement.Right">
<Icon Class="ml-1" Name="IconName.InfoCircle" TextColor="TextColor.Info"></Icon>
</Tooltip>
</FieldLabel>
<NumericPicker TValue="decimal" Min="0" Decimals="8" Step="0.00001m" CurrencySymbol=" BTC" CurrencySymbolPlacement="CurrencySymbolPlacement.Suffix" Disabled="@(_selectedStrategy != CoinSelectionStrategy.ClosestToTargetFirst)" Value="_closestTo" ValueChanged="OnClosestToChanged" Debounce="true"/>
<FieldHelp>
@($"{Math.Round(PriceConversionHelper.BtcToUsdConversion(_closestTo, _btcPrice), 2)} USD")
Expand All @@ -47,14 +52,24 @@
@if (!_isManualSelection)
{
<Field>
<FieldLabel>Amount</FieldLabel>
<FieldLabel Class="d-flex">
Amount
<Tooltip Text="The total amount to reach by adding the selected UTXOs" Placement="TooltipPlacement.Right">
<Icon Class="ml-1" Name="IconName.InfoCircle" TextColor="TextColor.Info"></Icon>
</Tooltip>
</FieldLabel>
<NumericPicker TValue="decimal" Min="0" Decimals="8" Step="0.00001m" CurrencySymbol=" BTC" CurrencySymbolPlacement="CurrencySymbolPlacement.Suffix" Value="_amount" ValueChanged="OnAmountChanged" Debounce="true"/>
<FieldHelp>
@($"{Math.Round(PriceConversionHelper.BtcToUsdConversion(_amount, _btcPrice), 2)} USD")
</FieldHelp>
</Field>
<Field>
<FieldLabel>Limit</FieldLabel>
<FieldLabel Class="d-flex">
Limit
<Tooltip Text="The maximum number of UTXOs allowed to use" Placement="TooltipPlacement.Right">
<Icon Class="ml-1" Name="IconName.InfoCircle" TextColor="TextColor.Info"></Icon>
</Tooltip>
</FieldLabel>
<NumericPicker TValue="int" Min="0" CurrencySymbol=" UTXOs" CurrencySymbolPlacement="CurrencySymbolPlacement.Suffix" Value="_limit" ValueChanged="OnLimitChanged" Debounce="true"/>
</Field>
}
Expand Down

0 comments on commit fce918f

Please sign in to comment.