Show total balances for each currency on List Wallets Page

This commit is contained in:
Max Dignan
2021-09-15 10:52:57 -04:00
committed by Andrew Camilleri
parent 88c925017d
commit b7a081b9a4
3 changed files with 33 additions and 2 deletions

View File

@@ -259,10 +259,20 @@ namespace BTCPayServer.Controllers
{
walletVm.Balance = "";
}
walletVm.Network = wallet.Network;
walletVm.CryptoCode = wallet.Network.CryptoCode;
walletVm.StoreId = wallet.Store.Id;
walletVm.Id = new WalletId(wallet.Store.Id, wallet.Network.CryptoCode);
walletVm.StoreName = wallet.Store.StoreName;
if (wallets.BalanceForCryptoCode.ContainsKey(wallet.Network))
{
wallets.BalanceForCryptoCode[wallet.Network] = wallets.BalanceForCryptoCode[wallet.Network].Add(await GetBalanceAsMoney(wallet.Wallet, wallet.DerivationStrategy));
}
else
{
wallets.BalanceForCryptoCode[wallet.Network] = await GetBalanceAsMoney(wallet.Wallet, wallet.DerivationStrategy);
}
}
return View(wallets);
@@ -1061,13 +1071,25 @@ namespace BTCPayServer.Controllers
return CurrentStore.GetDerivationSchemeSettings(NetworkProvider, walletId.CryptoCode);
}
private static async Task<string> GetBalanceString(BTCPayWallet wallet, DerivationStrategyBase derivationStrategy)
private static async Task<IMoney> GetBalanceAsMoney(BTCPayWallet wallet, DerivationStrategyBase derivationStrategy)
{
using CancellationTokenSource cts = new CancellationTokenSource(TimeSpan.FromSeconds(10));
try
{
var b = await wallet.GetBalance(derivationStrategy, cts.Token);
return (b.Available ?? b.Total).ShowMoney(wallet.Network);
return (b.Available ?? b.Total);
}
catch
{
return NBitcoin.Money.Zero;
}
}
private static async Task<string> GetBalanceString(BTCPayWallet wallet, DerivationStrategyBase derivationStrategy)
{
try
{
return (await GetBalanceAsMoney(wallet, derivationStrategy)).ShowMoney(wallet.Network);
}
catch
{