mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2024-11-19 09:54:30 +01:00
This commit is contained in:
parent
616883648f
commit
b443acd43b
@ -2,6 +2,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using BTCPayServer.Controllers;
|
using BTCPayServer.Controllers;
|
||||||
using BTCPayServer.Data;
|
using BTCPayServer.Data;
|
||||||
@ -28,20 +29,20 @@ namespace BTCPayServer.Components.WalletNav
|
|||||||
private readonly UIWalletsController _walletsController;
|
private readonly UIWalletsController _walletsController;
|
||||||
private readonly CurrencyNameTable _currencies;
|
private readonly CurrencyNameTable _currencies;
|
||||||
private readonly BTCPayNetworkProvider _networkProvider;
|
private readonly BTCPayNetworkProvider _networkProvider;
|
||||||
private readonly IRateProvider _rateProvider;
|
private readonly RateFetcher _rateFetcher;
|
||||||
|
|
||||||
public WalletNav(
|
public WalletNav(
|
||||||
BTCPayWalletProvider walletProvider,
|
BTCPayWalletProvider walletProvider,
|
||||||
BTCPayNetworkProvider networkProvider,
|
BTCPayNetworkProvider networkProvider,
|
||||||
UIWalletsController walletsController,
|
UIWalletsController walletsController,
|
||||||
CurrencyNameTable currencies,
|
CurrencyNameTable currencies,
|
||||||
IRateProvider rateProvider)
|
RateFetcher rateFetcher)
|
||||||
{
|
{
|
||||||
_walletProvider = walletProvider;
|
_walletProvider = walletProvider;
|
||||||
_networkProvider = networkProvider;
|
_networkProvider = networkProvider;
|
||||||
_walletsController = walletsController;
|
_walletsController = walletsController;
|
||||||
_currencies = currencies;
|
_currencies = currencies;
|
||||||
_rateProvider = rateProvider;
|
_rateFetcher = rateFetcher;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IViewComponentResult> InvokeAsync(WalletId walletId)
|
public async Task<IViewComponentResult> InvokeAsync(WalletId walletId)
|
||||||
@ -68,13 +69,12 @@ namespace BTCPayServer.Components.WalletNav
|
|||||||
|
|
||||||
if (defaultCurrency != network.CryptoCode)
|
if (defaultCurrency != network.CryptoCode)
|
||||||
{
|
{
|
||||||
var rates = await _rateProvider.GetRatesAsync(default);
|
var rule = store.GetStoreBlob().GetRateRules(_networkProvider)?.GetRuleFor(new Rating.CurrencyPair(network.CryptoCode, defaultCurrency));
|
||||||
var rate = rates.FirstOrDefault(pair => pair.CurrencyPair.Right == defaultCurrency &&
|
var bid = rule is null ? null : (await _rateFetcher.FetchRate(rule, HttpContext.RequestAborted)).BidAsk?.Bid;
|
||||||
pair.CurrencyPair.Left == network.CryptoCode);
|
if (bid is decimal b)
|
||||||
if (rate != null)
|
|
||||||
{
|
{
|
||||||
var currencyData = _currencies.GetCurrencyData(defaultCurrency, false);
|
var currencyData = _currencies.GetCurrencyData(defaultCurrency, true);
|
||||||
vm.BalanceDefaultCurrency = (balance.GetValue() * rate.BidAsk.Bid).ShowMoney(currencyData.Divisibility);
|
vm.BalanceDefaultCurrency = (balance.GetValue() * b).ShowMoney(currencyData.Divisibility);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user