mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-17 22:14:26 +01:00
Can show the transaction list in wallet menu
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||||
<Version>1.0.2.72</Version>
|
<Version>1.0.2.74</Version>
|
||||||
<NoWarn>NU1701,CA1816,CA1308,CA1810,CA2208</NoWarn>
|
<NoWarn>NU1701,CA1816,CA1308,CA1810,CA2208</NoWarn>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -128,6 +128,9 @@
|
|||||||
<Content Update="Views\Wallets\ListWallets.cshtml">
|
<Content Update="Views\Wallets\ListWallets.cshtml">
|
||||||
<Pack>$(IncludeRazorContentInPack)</Pack>
|
<Pack>$(IncludeRazorContentInPack)</Pack>
|
||||||
</Content>
|
</Content>
|
||||||
|
<Content Update="Views\Wallets\WalletTransactions.cshtml">
|
||||||
|
<Pack>$(IncludeRazorContentInPack)</Pack>
|
||||||
|
</Content>
|
||||||
<Content Update="Views\Wallets\_Nav.cshtml">
|
<Content Update="Views\Wallets\_Nav.cshtml">
|
||||||
<Pack>$(IncludeRazorContentInPack)</Pack>
|
<Pack>$(IncludeRazorContentInPack)</Pack>
|
||||||
</Content>
|
</Content>
|
||||||
|
|||||||
@@ -107,6 +107,35 @@ namespace BTCPayServer.Controllers
|
|||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("{walletId}")]
|
[Route("{walletId}")]
|
||||||
|
public async Task<IActionResult> WalletTransactions(
|
||||||
|
[ModelBinder(typeof(WalletIdModelBinder))]
|
||||||
|
WalletId walletId)
|
||||||
|
{
|
||||||
|
var store = await _Repo.FindStore(walletId.StoreId, GetUserId());
|
||||||
|
DerivationStrategy paymentMethod = GetPaymentMethod(walletId, store);
|
||||||
|
if (paymentMethod == null)
|
||||||
|
return NotFound();
|
||||||
|
|
||||||
|
var wallet = _walletProvider.GetWallet(paymentMethod.Network);
|
||||||
|
var transactions = await wallet.FetchTransactions(paymentMethod.DerivationStrategyBase);
|
||||||
|
|
||||||
|
var model = new ListTransactionsViewModel();
|
||||||
|
foreach(var tx in transactions.UnconfirmedTransactions.Transactions.Concat(transactions.ConfirmedTransactions.Transactions))
|
||||||
|
{
|
||||||
|
var vm = new ListTransactionsViewModel.TransactionViewModel();
|
||||||
|
model.Transactions.Add(vm);
|
||||||
|
vm.Id = tx.TransactionId.ToString();
|
||||||
|
vm.Link = string.Format(CultureInfo.InvariantCulture, paymentMethod.Network.BlockExplorerLink, vm.Id);
|
||||||
|
vm.Timestamp = tx.Timestamp;
|
||||||
|
vm.Positive = tx.BalanceChange >= Money.Zero;
|
||||||
|
vm.Balance = tx.BalanceChange.ToString();
|
||||||
|
}
|
||||||
|
return View(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
[Route("{walletId}/send")]
|
||||||
public async Task<IActionResult> WalletSend(
|
public async Task<IActionResult> WalletSend(
|
||||||
[ModelBinder(typeof(WalletIdModelBinder))]
|
[ModelBinder(typeof(WalletIdModelBinder))]
|
||||||
WalletId walletId)
|
WalletId walletId)
|
||||||
@@ -114,14 +143,7 @@ namespace BTCPayServer.Controllers
|
|||||||
if (walletId?.StoreId == null)
|
if (walletId?.StoreId == null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
var store = await _Repo.FindStore(walletId.StoreId, GetUserId());
|
var store = await _Repo.FindStore(walletId.StoreId, GetUserId());
|
||||||
if (store == null || !store.HasClaim(Policies.CanModifyStoreSettings.Key))
|
DerivationStrategy paymentMethod = GetPaymentMethod(walletId, store);
|
||||||
return NotFound();
|
|
||||||
|
|
||||||
var paymentMethod = store
|
|
||||||
.GetSupportedPaymentMethods(_NetworkProvider)
|
|
||||||
.OfType<DerivationStrategy>()
|
|
||||||
.FirstOrDefault(p => p.PaymentId.PaymentType == Payments.PaymentTypes.BTCLike && p.PaymentId.CryptoCode == walletId.CryptoCode);
|
|
||||||
|
|
||||||
if (paymentMethod == null)
|
if (paymentMethod == null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
|
|
||||||
@@ -151,6 +173,18 @@ namespace BTCPayServer.Controllers
|
|||||||
return View(model);
|
return View(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private DerivationStrategy GetPaymentMethod(WalletId walletId, StoreData store)
|
||||||
|
{
|
||||||
|
if (store == null || !store.HasClaim(Policies.CanModifyStoreSettings.Key))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var paymentMethod = store
|
||||||
|
.GetSupportedPaymentMethods(_NetworkProvider)
|
||||||
|
.OfType<DerivationStrategy>()
|
||||||
|
.FirstOrDefault(p => p.PaymentId.PaymentType == Payments.PaymentTypes.BTCLike && p.PaymentId.CryptoCode == walletId.CryptoCode);
|
||||||
|
return paymentMethod;
|
||||||
|
}
|
||||||
|
|
||||||
private static async Task<string> GetBalanceString(BTCPayWallet wallet, DerivationStrategyBase derivationStrategy)
|
private static async Task<string> GetBalanceString(BTCPayWallet wallet, DerivationStrategyBase derivationStrategy)
|
||||||
{
|
{
|
||||||
using (CancellationTokenSource cts = new CancellationTokenSource(TimeSpan.FromSeconds(10)))
|
using (CancellationTokenSource cts = new CancellationTokenSource(TimeSpan.FromSeconds(10)))
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace BTCPayServer.Models.WalletViewModels
|
||||||
|
{
|
||||||
|
public class ListTransactionsViewModel
|
||||||
|
{
|
||||||
|
public class TransactionViewModel
|
||||||
|
{
|
||||||
|
public DateTimeOffset Timestamp { get; set; }
|
||||||
|
public string Id { get; set; }
|
||||||
|
public string Link { get; set; }
|
||||||
|
public bool Positive { get; set; }
|
||||||
|
public string Balance { get; set; }
|
||||||
|
}
|
||||||
|
public List<TransactionViewModel> Transactions { get; set; } = new List<TransactionViewModel>();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -151,6 +151,11 @@ namespace BTCPayServer.Services.Wallets
|
|||||||
return await completionSource.Task;
|
return await completionSource.Task;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Task<GetTransactionsResponse> FetchTransactions(DerivationStrategyBase derivationStrategyBase)
|
||||||
|
{
|
||||||
|
return _Client.GetTransactionsAsync(derivationStrategyBase, null, false);
|
||||||
|
}
|
||||||
|
|
||||||
public Task<BroadcastResult[]> BroadcastTransactionsAsync(List<Transaction> transactions)
|
public Task<BroadcastResult[]> BroadcastTransactionsAsync(List<Transaction> transactions)
|
||||||
{
|
{
|
||||||
var tasks = transactions.Select(t => _Client.BroadcastAsync(t)).ToArray();
|
var tasks = transactions.Select(t => _Client.BroadcastAsync(t)).ToArray();
|
||||||
|
|||||||
@@ -82,7 +82,7 @@
|
|||||||
<td style="text-align:right">
|
<td style="text-align:right">
|
||||||
@if(!string.IsNullOrWhiteSpace(scheme.Value))
|
@if(!string.IsNullOrWhiteSpace(scheme.Value))
|
||||||
{
|
{
|
||||||
<a asp-action="WalletSend" asp-controller="Wallets" asp-route-walletId="@scheme.WalletId">Wallet</a><span> - </span>
|
<a asp-action="WalletTransactions" asp-controller="Wallets" asp-route-walletId="@scheme.WalletId">Wallet</a><span> - </span>
|
||||||
}
|
}
|
||||||
<a asp-action="AddDerivationScheme" asp-route-cryptoCode="@scheme.Crypto">Modify</a>
|
<a asp-action="AddDerivationScheme" asp-route-cryptoCode="@scheme.Crypto">Modify</a>
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
@@ -45,7 +45,7 @@
|
|||||||
<td>@wallet.CryptoCode</td>
|
<td>@wallet.CryptoCode</td>
|
||||||
<td>@wallet.Balance</td>
|
<td>@wallet.Balance</td>
|
||||||
<td style="text-align:right">
|
<td style="text-align:right">
|
||||||
<a asp-action="WalletSend" asp-route-walletId="@wallet.Id">Manage</a>
|
<a asp-action="WalletTransactions" asp-route-walletId="@wallet.Id">Manage</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
|
|||||||
54
BTCPayServer/Views/Wallets/WalletTransactions.cshtml
Normal file
54
BTCPayServer/Views/Wallets/WalletTransactions.cshtml
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
@model ListTransactionsViewModel
|
||||||
|
@{
|
||||||
|
Layout = "../Shared/_NavLayout.cshtml";
|
||||||
|
ViewData["Title"] = "Manage wallet";
|
||||||
|
ViewData.SetActivePageAndTitle(WalletsNavPages.Transactions);
|
||||||
|
}
|
||||||
|
|
||||||
|
<style type="text/css">
|
||||||
|
.smMaxWidth {
|
||||||
|
max-width: 200px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@@media (min-width: 768px) {
|
||||||
|
.smMaxWidth {
|
||||||
|
max-width: 400px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<h4>@ViewData["Title"]</h4>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-10">
|
||||||
|
<table class="table table-sm table-responsive-lg">
|
||||||
|
<thead class="thead-inverse">
|
||||||
|
<tr>
|
||||||
|
<th>Timestamp</th>
|
||||||
|
<th>Transaction Id</th>
|
||||||
|
<th style="text-align:right">Balance</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach(var transaction in Model.Transactions)
|
||||||
|
{
|
||||||
|
<tr>
|
||||||
|
<td>@transaction.Timestamp.ToBrowserDate()</td>
|
||||||
|
<td class="smMaxWidth text-truncate">
|
||||||
|
<a href="@transaction.Link" target="_blank">
|
||||||
|
@transaction.Id
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
@if(transaction.Positive)
|
||||||
|
{
|
||||||
|
<td style="text-align:right; color:green;">@transaction.Balance</td>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<td style="text-align:right; color:red;">@transaction.Balance</td>
|
||||||
|
}
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -7,6 +7,7 @@ namespace BTCPayServer.Views.Wallets
|
|||||||
{
|
{
|
||||||
public enum WalletsNavPages
|
public enum WalletsNavPages
|
||||||
{
|
{
|
||||||
Send
|
Send,
|
||||||
|
Transactions
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
@inject SignInManager<ApplicationUser> SignInManager
|
@inject SignInManager<ApplicationUser> SignInManager
|
||||||
|
|
||||||
<div class="nav flex-column nav-pills">
|
<div class="nav flex-column nav-pills">
|
||||||
|
<a class="nav-link @ViewData.IsActivePage(WalletsNavPages.Transactions)" asp-action="WalletTransactions">Transactions</a>
|
||||||
<a class="nav-link @ViewData.IsActivePage(WalletsNavPages.Send)" asp-action="WalletSend">Send</a>
|
<a class="nav-link @ViewData.IsActivePage(WalletsNavPages.Send)" asp-action="WalletSend">Send</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user