Can show the transaction list in wallet menu

This commit is contained in:
nicolas.dorier 2018-07-27 00:08:07 +09:00
parent 638b58ab48
commit 52f60b0457
9 changed files with 130 additions and 12 deletions

View File

@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<Version>1.0.2.72</Version>
<Version>1.0.2.74</Version>
<NoWarn>NU1701,CA1816,CA1308,CA1810,CA2208</NoWarn>
</PropertyGroup>
<ItemGroup>
@ -128,6 +128,9 @@
<Content Update="Views\Wallets\ListWallets.cshtml">
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>
<Content Update="Views\Wallets\WalletTransactions.cshtml">
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>
<Content Update="Views\Wallets\_Nav.cshtml">
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>

View File

@ -107,6 +107,35 @@ namespace BTCPayServer.Controllers
[HttpGet]
[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(
[ModelBinder(typeof(WalletIdModelBinder))]
WalletId walletId)
@ -114,14 +143,7 @@ namespace BTCPayServer.Controllers
if (walletId?.StoreId == null)
return NotFound();
var store = await _Repo.FindStore(walletId.StoreId, GetUserId());
if (store == null || !store.HasClaim(Policies.CanModifyStoreSettings.Key))
return NotFound();
var paymentMethod = store
.GetSupportedPaymentMethods(_NetworkProvider)
.OfType<DerivationStrategy>()
.FirstOrDefault(p => p.PaymentId.PaymentType == Payments.PaymentTypes.BTCLike && p.PaymentId.CryptoCode == walletId.CryptoCode);
DerivationStrategy paymentMethod = GetPaymentMethod(walletId, store);
if (paymentMethod == null)
return NotFound();
@ -151,6 +173,18 @@ namespace BTCPayServer.Controllers
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)
{
using (CancellationTokenSource cts = new CancellationTokenSource(TimeSpan.FromSeconds(10)))

View File

@ -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>();
}
}

View File

@ -151,6 +151,11 @@ namespace BTCPayServer.Services.Wallets
return await completionSource.Task;
}
public Task<GetTransactionsResponse> FetchTransactions(DerivationStrategyBase derivationStrategyBase)
{
return _Client.GetTransactionsAsync(derivationStrategyBase, null, false);
}
public Task<BroadcastResult[]> BroadcastTransactionsAsync(List<Transaction> transactions)
{
var tasks = transactions.Select(t => _Client.BroadcastAsync(t)).ToArray();

View File

@ -82,7 +82,7 @@
<td style="text-align:right">
@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>
</td>

View File

@ -45,7 +45,7 @@
<td>@wallet.CryptoCode</td>
<td>@wallet.Balance</td>
<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>
</tr>
}

View 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>

View File

@ -7,6 +7,7 @@ namespace BTCPayServer.Views.Wallets
{
public enum WalletsNavPages
{
Send
Send,
Transactions
}
}

View File

@ -1,6 +1,7 @@
@inject SignInManager<ApplicationUser> SignInManager
<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>
</div>