Implement recent transaction for balance tile
MODIFY
WalletWasabi.Fluent/ViewModels/Wallets/Home/Tiles/WalletBalanceTileViewModel.cs
WalletWasabi.Fluent/ViewModels/Wallets/Home/Tiles/WalletBalanceTileViewModel.cs
using System;
+using System.Collections.ObjectModel;
+using System.Linq;
using System.Reactive;
using System.Reactive.Disposables;
+using DynamicData.Binding;
using NBitcoin;
using WalletWasabi.Wallets;
using WalletWasabi.Fluent.Helpers;
+using WalletWasabi.Fluent.ViewModels.Wallets.Home.History;
+using WalletWasabi.Models;
namespace WalletWasabi.Fluent.ViewModels.Wallets.Home.Tiles
{
@@ -11,18 +16,21 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets.Home.Tiles
{
private readonly Wallet _wallet;
private readonly IObservable<Unit> _balanceChanged;
- [AutoNotify] private string? _balanceBtc;
- [AutoNotify] private string? _balanceFiat;
- [AutoNotify] private string? _balancePrivateBtc;
- [AutoNotify] private string? _balanceNonPrivateBtc;
- [AutoNotify] private string? _recentTransactionName;
- [AutoNotify] private string? _recentTransactionDate;
- [AutoNotify] private string? _recentTransactionStatus;
-
- public WalletBalanceTileViewModel(Wallet wallet, IObservable<Unit> balanceChanged)
+ private readonly ObservableCollection<HistoryItemViewModel> _history;
+ [AutoNotify(SetterModifier = AccessModifier.Private)] private bool _showRecentTransaction;
+ [AutoNotify(SetterModifier = AccessModifier.Private)] private string? _balanceBtc;
+ [AutoNotify(SetterModifier = AccessModifier.Private)] private string? _balanceFiat;
+ [AutoNotify(SetterModifier = AccessModifier.Private)] private string? _balancePrivateBtc;
+ [AutoNotify(SetterModifier = AccessModifier.Private)] private string? _balanceNonPrivateBtc;
+ [AutoNotify(SetterModifier = AccessModifier.Private)] private string? _recentTransactionName;
+ [AutoNotify(SetterModifier = AccessModifier.Private)] private DateTimeOffset? _recentTransactionDate;
+ [AutoNotify(SetterModifier = AccessModifier.Private)] private string? _recentTransactionStatus;
+
+ public WalletBalanceTileViewModel(Wallet wallet, IObservable<Unit> balanceChanged, ObservableCollection<HistoryItemViewModel> history)
{
_wallet = wallet;
_balanceChanged = balanceChanged;
+ _history = history;
}
protected override void OnActivated(CompositeDisposable disposables)
@@ -33,6 +41,10 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets.Home.Tiles
.Subscribe(_ => UpdateBalance())
.DisposeWith(disposables);
+ _history.ToObservableChangeSet()
+ .Subscribe(_ => UpdateRecentTransaction())
+ .DisposeWith(disposables);
+
UpdateBalance();
}
@@ -55,11 +67,38 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets.Home.Tiles
.FormattedBtc() + " BTC";
}
- private void UpdateTransaction()
+ private void UpdateRecentTransaction()
+ {
+ var recent = _history.FirstOrDefault();
+ if (recent is { })
{
- // TODO: Update RecentTransactionName
- // TODO: Update RecentTransactionDate
- // TODO: Update RecentTransactionStatus
+ var transactionSummary = recent.TransactionSummary;
+ var confirmations = transactionSummary.Height.Type == HeightType.Chain ? (int)_wallet.BitcoinStore.SmartHeaderChain.TipHeight - transactionSummary.Height.Value + 1 : 0;
+ var isConfirmed = confirmations > 0;
+ var isIncoming = true;
+ var amount = transactionSummary.Amount;
+ if (amount < Money.Zero)
+ {
+ amount *= -1;
+ isIncoming = false;
+ }
+
+ RecentTransactionName = isIncoming ? "Incoming" : "Outgoing";
+
+ RecentTransactionDate = transactionSummary.DateTime.ToLocalTime();
+
+ RecentTransactionStatus = $"{(amount.ToDecimal(MoneyUnit.BTC).FormattedBtc() + " BTC")}" +
+ $" - {(isConfirmed ? "Confirmed" : "Pending")}";
+
+ ShowRecentTransaction = true;
+ }
+ else
+ {
+ RecentTransactionName = default;
+ RecentTransactionDate = default;
+ RecentTransactionStatus = default;
+ ShowRecentTransaction = false;
+ }
}
}
}
\ No newline at end of file

MODIFY
WalletWasabi.Fluent/ViewModels/Wallets/WalletViewModel.cs
WalletWasabi.Fluent/ViewModels/Wallets/WalletViewModel.cs
@@ -75,7 +75,7 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets
LayoutIndex = _normalLayoutIndex;
- BalanceTile = new WalletBalanceTileViewModel(wallet, balanceChanged)
+ BalanceTile = new WalletBalanceTileViewModel(wallet, balanceChanged, History.UnfilteredTransactions)
{
TilePresets = new ObservableCollection<TilePresetViewModel>()
{

MODIFY
WalletWasabi.Fluent/Views/Wallets/Home/Tiles/WalletBalance/WalletBalanceWideTileView.axaml
WalletWasabi.Fluent/Views/Wallets/Home/Tiles/WalletBalance/WalletBalanceWideTileView.axaml
</StackPanel>
</StackPanel>
</DockPanel>
- <DockPanel VerticalAlignment="Top" DockPanel.Dock="Left">
+ <DockPanel VerticalAlignment="Top" DockPanel.Dock="Left"
+ IsVisible="{Binding ShowRecentTransaction, FallbackValue=True}">
<!-- Recent transaction name -->
<StackPanel DockPanel.Dock="Top" Orientation="Horizontal" Spacing="16" Margin="0,12">
<Panel Height="47" Width="47" DockPanel.Dock="Left"/>
<Viewbox Height="14" Width="14" DockPanel.Dock="Left">
<PathIcon Data="{StaticResource transaction_date}" Height="14" Width="14" Foreground="{DynamicResource SystemAccentColor}" />
</Viewbox>
- <TextBlock Text="{Binding RecentTransactionDate, FallbackValue='7/12/2020'}"
+ <TextBlock Text="{Binding RecentTransactionDate, StringFormat='{}{0:MM/dd/yyyy HH:mm}', FallbackValue='7/12/2020'}"
Opacity="0.8" FontSize="12" Margin="10,0,0,0"/>
</DockPanel>
<!-- Recent transaction status -->

Implement recent transaction for balance tile