* Add dashboard and chart basics

* More widgets

* Make widgets responsive

* Layout dashboard

* Prepare ExplorerClient

* Switch to Chartist

* Dynamic data for store numbers and recent transactions tiles

* Dynamic data for recent invoices tile

* Improvements

* Plug NBXPlorer DB

* Properly filter by code

* Reorder cheat mode button

* AJAX update for graph data

* Fix create invoice button

* Retry connection on transient issues

* App Top Items stats

* Design updates

* App Sales stats

* Add points for weekly histogram, set last point to current balance

Co-authored-by: nicolas.dorier <nicolas.dorier@gmail.com>
This commit is contained in:
d11n
2022-04-12 09:55:10 +02:00
committed by GitHub
parent d58803a058
commit 7ec978fcdb
41 changed files with 2037 additions and 115 deletions

View File

@@ -0,0 +1,77 @@
using System;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
using BTCPayServer.Client.Models;
using BTCPayServer.Components.StoreRecentTransactions;
using BTCPayServer.Data;
using BTCPayServer.Services.Stores;
using BTCPayServer.Services.Wallets;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Npgsql;
using StoreData = BTCPayServer.Data.StoreData;
namespace BTCPayServer.Components.StoreNumbers;
public class StoreNumbers : ViewComponent
{
private const string CryptoCode = "BTC";
private const int TransactionDays = 7;
private readonly StoreRepository _storeRepo;
private readonly ApplicationDbContextFactory _dbContextFactory;
private readonly BTCPayWalletProvider _walletProvider;
private readonly BTCPayNetworkProvider _networkProvider;
public StoreNumbers(
StoreRepository storeRepo,
ApplicationDbContextFactory dbContextFactory,
BTCPayNetworkProvider networkProvider,
BTCPayWalletProvider walletProvider)
{
_storeRepo = storeRepo;
_walletProvider = walletProvider;
_networkProvider = networkProvider;
_dbContextFactory = dbContextFactory;
}
public async Task<IViewComponentResult> InvokeAsync(StoreData store)
{
await using var ctx = _dbContextFactory.CreateContext();
var payoutsCount = await ctx.Payouts
.Where(p => p.PullPaymentData.StoreId == store.Id && !p.PullPaymentData.Archived && p.State == PayoutState.AwaitingApproval)
.CountAsync();
var refundsCount = await ctx.Invoices
.Where(i => i.StoreData.Id == store.Id && !i.Archived && i.CurrentRefundId != null)
.CountAsync();
var walletId = new WalletId(store.Id, CryptoCode);
var derivation = store.GetDerivationSchemeSettings(_networkProvider, walletId.CryptoCode);
var transactionsCount = 0;
if (derivation != null)
{
var network = derivation.Network;
var wallet = _walletProvider.GetWallet(network);
var allTransactions = await wallet.FetchTransactions(derivation.AccountDerivation);
var afterDate = DateTimeOffset.UtcNow - TimeSpan.FromDays(TransactionDays);
transactionsCount = allTransactions.UnconfirmedTransactions.Transactions
.Concat(allTransactions.ConfirmedTransactions.Transactions)
.Count(t => t.Timestamp > afterDate);
}
var vm = new StoreNumbersViewModel
{
Store = store,
WalletId = walletId,
PayoutsPending = payoutsCount,
Transactions = transactionsCount,
TransactionDays = TransactionDays,
RefundsIssued = refundsCount
};
return View(vm);
}
}