working balance tile.
MODIFY
WalletWasabi.Fluent/ViewModels/Wallets/Home/Tiles/WalletBalanceTileViewModel.cs
WalletWasabi.Fluent/ViewModels/Wallets/Home/Tiles/WalletBalanceTileViewModel.cs
+using System;
+using System.Reactive;
using NBitcoin;
using WalletWasabi.Wallets;
-using ReactiveUI;
using WalletWasabi.Fluent.Helpers;
namespace WalletWasabi.Fluent.ViewModels.Wallets.Home.Tiles
{
public partial class WalletBalanceTileViewModel : ViewModelBase
{
+ private readonly Wallet _wallet;
[AutoNotify] private string _balanceBtc;
[AutoNotify] private string _balanceFiat;
- public WalletBalanceTileViewModel(Wallet wallet)
+ public WalletBalanceTileViewModel(Wallet wallet, IObservable<Unit> balanceChanged)
{
- Wallet wallet1 = wallet;
+ _wallet = wallet;
- _balanceBtc = wallet1.Coins.Confirmed().TotalAmount().ToDecimal(MoneyUnit.BTC).FormattedBtc() + " BTC";
- _balanceFiat = wallet1.Coins.Confirmed().TotalAmount().ToDecimal(MoneyUnit.BTC)
- .GenerateFiatText(wallet.Synchronizer.UsdExchangeRate, "USD");
+ balanceChanged.Subscribe(_ => UpdateBalance());
+
+ UpdateBalance();
+ }
+
+ private void UpdateBalance()
+ {
+ BalanceBtc = _wallet.Coins.Confirmed().TotalAmount().ToDecimal(MoneyUnit.BTC)
+ .FormattedBtc() + " BTC";
+
+ BalanceFiat = _wallet.Coins.Confirmed().TotalAmount().ToDecimal(MoneyUnit.BTC)
+ .GenerateFiatText(_wallet.Synchronizer.UsdExchangeRate, "USD");
}
}
}
\ No newline at end of file

MODIFY
WalletWasabi.Fluent/ViewModels/Wallets/WalletViewModel.cs
WalletWasabi.Fluent/ViewModels/Wallets/WalletViewModel.cs
@@ -23,13 +23,14 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets
{
Disposables = Disposables is null ? new CompositeDisposable() : throw new NotSupportedException($"Cannot open {GetType().Name} before closing it.");
- Observable.Merge(
+ var balanceChanged = Observable.Merge(
Observable.FromEventPattern(Wallet.TransactionProcessor, nameof(Wallet.TransactionProcessor.WalletRelevantTransactionProcessed)).Select(_ => Unit.Default))
.Throttle(TimeSpan.FromSeconds(0.1))
.Merge(uiConfig.WhenAnyValue(x => x.PrivacyMode).Select(_ => Unit.Default))
.Merge(Wallet.Synchronizer.WhenAnyValue(x => x.UsdExchangeRate).Select(_ => Unit.Default))
- .ObserveOn(RxApp.MainThreadScheduler)
- .Subscribe(
+ .ObserveOn(RxApp.MainThreadScheduler);
+
+ balanceChanged.Subscribe(
_ =>
{
try
@@ -47,7 +48,7 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets
.DisposeWith(Disposables);
History = new HistoryViewModel(wallet, uiConfig);
- BalanceTile = new WalletBalanceTileViewModel(wallet);
+ BalanceTile = new WalletBalanceTileViewModel(wallet, balanceChanged);
BalanceChartTile = new WalletBalanceChartTileViewModel(History.Transactions);
WalletPieChart = new WalletPieChartTileViewModel(wallet);
}

MODIFY
WalletWasabi.Fluent/Views/Wallets/WalletView.axaml
WalletWasabi.Fluent/Views/Wallets/WalletView.axaml
HorizontalAlignment="Left"
VerticalAlignment="Top"
UseLayoutRounding="False">
- <tiles:WalletBalanceTileView
+ <tiles:WalletBalanceTileView DataContext="{Binding BalanceTile}"
c:ResponsivePanel.ColumnSpan="1, 1, 1" c:ResponsivePanel.RowSpan="1, 1, 1" />
<Border CornerRadius="4" Margin="4" Background="Green"
c:ResponsivePanel.ColumnSpan="1, 1, 1" c:ResponsivePanel.RowSpan="1, 1, 1" />

working balance tile.