mirror of
https://github.com/aljazceru/btcpayserver-breez-nodeless-plugin.git
synced 2025-12-17 08:34:20 +01:00
212 lines
8.4 KiB
Plaintext
212 lines
8.4 KiB
Plaintext
@using Breez.Sdk.Spark
|
|
@using BTCPayServer
|
|
@using BTCPayServer.Client
|
|
@using BTCPayServer.Components.QRCode
|
|
@using BTCPayServer.Components.TruncateCenter
|
|
@using BTCPayServer.Models.StoreViewModels
|
|
@using BTCPayServer.Payments
|
|
@using BTCPayServer.Plugins.Breez
|
|
@using BTCPayServer.Security
|
|
@using BTCPayServer.Services
|
|
@using BTCPayServer.Services.Invoices
|
|
@using Microsoft.AspNetCore.Mvc.TagHelpers
|
|
@using NBitcoin
|
|
@inject BreezService BreezService
|
|
@inject TransactionLinkProviders TransactionLinkProviders
|
|
@inject PaymentMethodHandlerDictionary PaymentMethodHandlerDictionary
|
|
@inject BTCPayNetworkProvider BTCPayNetworkProvider
|
|
@{
|
|
ViewData.SetActivePage("Breez", "Swap In", "SwapIn");
|
|
var pmi = PaymentMethodId.Parse("BTC-OnChain");
|
|
string storeId = Model switch
|
|
{
|
|
string s => s,
|
|
StoreDashboardViewModel dashboardModel => dashboardModel.StoreId,
|
|
_ => Context.GetImplicitStoreId()
|
|
};
|
|
var sdk = BreezService.GetClient(storeId)?.Sdk;
|
|
if (sdk is null)
|
|
return;
|
|
|
|
// Get current receive payment swap info (if any)
|
|
SwapInfo? currentSwap = null;
|
|
try
|
|
{
|
|
// Simplified logic - skip complex payment lookup for now
|
|
Payment? pendingReceive = null;
|
|
|
|
// Skip pending receive logic for SDK v0.4.1 compatibility
|
|
|
|
// If no pending swap, create a new one
|
|
if (currentSwap == null)
|
|
{
|
|
var request = new ReceivePaymentRequest(
|
|
paymentMethod: new ReceivePaymentMethod.BitcoinAddress()
|
|
);
|
|
var response = await sdk.ReceivePayment(request: request);
|
|
|
|
// Create swap info from response
|
|
currentSwap = new SwapInfo
|
|
{
|
|
bitcoinAddress = response.paymentRequest,
|
|
minAllowedDeposit = 1000, // Default minimum
|
|
maxAllowedDeposit = 16777215, // Default maximum (~0.16 BTC)
|
|
status = "Created"
|
|
};
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
<div class="alert alert-danger" role="alert">
|
|
<h5 class="alert-heading">Error</h5>
|
|
<p class="mb-0">Failed to initialize swap-in: @ex.Message</p>
|
|
</div>
|
|
return;
|
|
}
|
|
|
|
// Get refundable deposits using the new SDK pattern
|
|
// TODO: Fix for v2.2.1 - DepositInfo structure needs to be updated
|
|
// List<DepositInfo>? refundables = null;
|
|
// try
|
|
// {
|
|
// var request = new ListUnclaimedDepositsRequest();
|
|
// var response = await sdk.ListUnclaimedDeposits(request);
|
|
// refundables = response.deposits.ToList();
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// <div class="alert alert-warning" role="alert">
|
|
// <small>Unable to fetch refundable swaps: @ex.Message</small>
|
|
// </div>
|
|
// }
|
|
|
|
@* TODO: Fix for v2.2.1 - derivation settings check needed *@
|
|
|
|
// NodeState API has changed in SDK v0.4.1 - using GetInfo instead
|
|
var nodeInfo = new Breez.Sdk.Spark.GetInfoRequest(ensureSynced: false);
|
|
Breez.Sdk.Spark.GetInfoResponse? ni = null;
|
|
try
|
|
{
|
|
ni = await sdk.GetInfo(nodeInfo);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
<div class="alert alert-warning" role="alert">
|
|
<small>Unable to fetch node info: @ex.Message</small>
|
|
</div>
|
|
}
|
|
|
|
// Use standard fee rates since RecommendedFees API may have changed
|
|
var hasFeeRates = true; // Always show fee options
|
|
|
|
// Get explorer URL for transaction links
|
|
var network = BTCPayNetworkProvider.GetNetwork<BTCPayNetwork>("BTC");
|
|
var explorerUrl = network.BlockExplorerLink?.ToString() ?? "#";
|
|
}
|
|
|
|
@if (hasFeeRates)
|
|
{
|
|
<datalist id="fees">
|
|
<!-- Using standard fee rates as fallback since SDK properties may have different names -->
|
|
<option value="10">Fastest fee (10 sat/vB)</option>
|
|
<option value="5">Hour fee (5 sat/vB)</option>
|
|
<option value="2">Economic fee (2 sat/vB)</option>
|
|
<option value="1">Minimum fee (1 sat/vB)</option>
|
|
</datalist>
|
|
}
|
|
|
|
<div class="row mb-4 mt-4">
|
|
<div class="col-12">
|
|
|
|
@if (currentSwap != null)
|
|
{
|
|
<div class="payment-box">
|
|
<div class="qr-container" data-clipboard="@currentSwap.bitcoinAddress">
|
|
<vc:qr-code data="@currentSwap.bitcoinAddress"/>
|
|
</div>
|
|
<div class="input-group mt-3">
|
|
<div class="form-floating">
|
|
<vc:truncate-center text="@currentSwap.bitcoinAddress" padding="15" elastic="true" classes="form-control-plaintext" id="Address"/>
|
|
<label for="Address">Address</label>
|
|
</div>
|
|
<div class="w-100">
|
|
<span class="text-muted">Please send an amount between <br/> @Money.Satoshis(currentSwap.minAllowedDeposit).ToDecimal(MoneyUnit.BTC) and @Money.Satoshis(currentSwap.maxAllowedDeposit).ToDecimal(MoneyUnit.BTC)BTC </span>
|
|
@* TODO: Fix for v2.2.1 - derivation settings check needed *@
|
|
@*
|
|
@if (derivationSettings != null)
|
|
{
|
|
<button type="button" class="btn btn-primary" id="copy-address" data-clipboard="@currentSwap.bitcoinAddress">
|
|
<span class="d-none d-md-inline">Copy Address</span>
|
|
<span class="d-md-none">Copy</span>
|
|
</button>
|
|
}
|
|
*@
|
|
</div>
|
|
</div>
|
|
</div>
|
|
}
|
|
|
|
@*
|
|
@if (refundables?.Any() is true)
|
|
{
|
|
<div class="table-responsive mt-4">
|
|
<table class="table table-hover">
|
|
<thead>
|
|
<tr>
|
|
<th>Deposit Tx</th>
|
|
<th>Amount</th>
|
|
<th>Swap Tx</th>
|
|
<th>Refundable</th>
|
|
<th class="text-right">Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
@foreach (var deposit in refundables)
|
|
{
|
|
<tr>
|
|
<td>
|
|
@{
|
|
var txLink = TransactionLinkProviders.GetTransactionLink(deposit.txId, "BTC");
|
|
}
|
|
<a href="@txLink" target="_blank" rel="noreferrer noopener">
|
|
<vc:truncate-center text="@deposit.txId" padding="10" elastic="true" />
|
|
</a>
|
|
</td>
|
|
<td>@deposit.amount</td>
|
|
<td>
|
|
@if (!string.IsNullOrEmpty(deposit.swapTxId))
|
|
{
|
|
var swapTxLink = TransactionLinkProviders.GetTransactionLink(deposit.swapTxId, "BTC");
|
|
<a href="@swapTxLink" target="_blank" rel="noreferrer noopener">
|
|
<vc:truncate-center text="@deposit.swapTxId" padding="10" elastic="true" />
|
|
</a>
|
|
}
|
|
else
|
|
{
|
|
<span>N/A</span>
|
|
}
|
|
</td>
|
|
<td>
|
|
@if (deposit.refundable)
|
|
{
|
|
<span class="text-success">Yes</span>
|
|
}
|
|
else
|
|
{
|
|
<span class="text-muted">No</span>
|
|
}
|
|
</td>
|
|
<td class="text-right">
|
|
<form asp-action="SwapInRefund" asp-route-storeId="@storeId" method="get">
|
|
<button type="submit" class="btn btn-sm btn-outline-primary">Refund</button>
|
|
</form>
|
|
</td>
|
|
</tr>
|
|
}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
}
|
|
*@
|
|
</div>
|
|
</div> |