diff --git a/BTCPayServer/BTCPayServer.csproj b/BTCPayServer/BTCPayServer.csproj index 679bebed2..49e4efe9c 100644 --- a/BTCPayServer/BTCPayServer.csproj +++ b/BTCPayServer/BTCPayServer.csproj @@ -2,7 +2,7 @@ Exe netcoreapp2.1 - 1.0.2.72 + 1.0.2.74 NU1701,CA1816,CA1308,CA1810,CA2208 @@ -128,6 +128,9 @@ $(IncludeRazorContentInPack) + + $(IncludeRazorContentInPack) + $(IncludeRazorContentInPack) diff --git a/BTCPayServer/Controllers/WalletsController.cs b/BTCPayServer/Controllers/WalletsController.cs index 0abf1d930..8f6d0c219 100644 --- a/BTCPayServer/Controllers/WalletsController.cs +++ b/BTCPayServer/Controllers/WalletsController.cs @@ -107,6 +107,35 @@ namespace BTCPayServer.Controllers [HttpGet] [Route("{walletId}")] + public async Task 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 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() - .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() + .FirstOrDefault(p => p.PaymentId.PaymentType == Payments.PaymentTypes.BTCLike && p.PaymentId.CryptoCode == walletId.CryptoCode); + return paymentMethod; + } + private static async Task GetBalanceString(BTCPayWallet wallet, DerivationStrategyBase derivationStrategy) { using (CancellationTokenSource cts = new CancellationTokenSource(TimeSpan.FromSeconds(10))) diff --git a/BTCPayServer/Models/WalletViewModels/ListTransactionsViewModel.cs b/BTCPayServer/Models/WalletViewModels/ListTransactionsViewModel.cs new file mode 100644 index 000000000..2ef58bd80 --- /dev/null +++ b/BTCPayServer/Models/WalletViewModels/ListTransactionsViewModel.cs @@ -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 Transactions { get; set; } = new List(); + } +} diff --git a/BTCPayServer/Services/Wallets/BTCPayWallet.cs b/BTCPayServer/Services/Wallets/BTCPayWallet.cs index 2877c91c3..14be0bbf6 100644 --- a/BTCPayServer/Services/Wallets/BTCPayWallet.cs +++ b/BTCPayServer/Services/Wallets/BTCPayWallet.cs @@ -151,6 +151,11 @@ namespace BTCPayServer.Services.Wallets return await completionSource.Task; } + public Task FetchTransactions(DerivationStrategyBase derivationStrategyBase) + { + return _Client.GetTransactionsAsync(derivationStrategyBase, null, false); + } + public Task BroadcastTransactionsAsync(List transactions) { var tasks = transactions.Select(t => _Client.BroadcastAsync(t)).ToArray(); diff --git a/BTCPayServer/Views/Stores/UpdateStore.cshtml b/BTCPayServer/Views/Stores/UpdateStore.cshtml index 548abe18f..1301a5e00 100644 --- a/BTCPayServer/Views/Stores/UpdateStore.cshtml +++ b/BTCPayServer/Views/Stores/UpdateStore.cshtml @@ -82,7 +82,7 @@ @if(!string.IsNullOrWhiteSpace(scheme.Value)) { - Wallet - + Wallet - } Modify diff --git a/BTCPayServer/Views/Wallets/ListWallets.cshtml b/BTCPayServer/Views/Wallets/ListWallets.cshtml index c20d510ed..6e5d6f577 100644 --- a/BTCPayServer/Views/Wallets/ListWallets.cshtml +++ b/BTCPayServer/Views/Wallets/ListWallets.cshtml @@ -45,7 +45,7 @@ @wallet.CryptoCode @wallet.Balance - Manage + Manage } diff --git a/BTCPayServer/Views/Wallets/WalletTransactions.cshtml b/BTCPayServer/Views/Wallets/WalletTransactions.cshtml new file mode 100644 index 000000000..df8c3bfe6 --- /dev/null +++ b/BTCPayServer/Views/Wallets/WalletTransactions.cshtml @@ -0,0 +1,54 @@ +@model ListTransactionsViewModel +@{ + Layout = "../Shared/_NavLayout.cshtml"; + ViewData["Title"] = "Manage wallet"; + ViewData.SetActivePageAndTitle(WalletsNavPages.Transactions); +} + + + +

@ViewData["Title"]

+
+
+ + + + + + + + + + @foreach(var transaction in Model.Transactions) + { + + + + @if(transaction.Positive) + { + + } + else + { + + } + + } + +
TimestampTransaction IdBalance
@transaction.Timestamp.ToBrowserDate() + + @transaction.Id + + @transaction.Balance@transaction.Balance
+
+
diff --git a/BTCPayServer/Views/Wallets/WalletsNavPages.cs b/BTCPayServer/Views/Wallets/WalletsNavPages.cs index 67a8304ea..ed6c5bfe1 100644 --- a/BTCPayServer/Views/Wallets/WalletsNavPages.cs +++ b/BTCPayServer/Views/Wallets/WalletsNavPages.cs @@ -7,6 +7,7 @@ namespace BTCPayServer.Views.Wallets { public enum WalletsNavPages { - Send + Send, + Transactions } } diff --git a/BTCPayServer/Views/Wallets/_Nav.cshtml b/BTCPayServer/Views/Wallets/_Nav.cshtml index 9ea5c86c2..915dc5dad 100644 --- a/BTCPayServer/Views/Wallets/_Nav.cshtml +++ b/BTCPayServer/Views/Wallets/_Nav.cshtml @@ -1,6 +1,7 @@ @inject SignInManager SignInManager