Skip to content

Commit

Permalink
Merge pull request #11644 from ichthus1604/UI-Decoupling50
Browse files Browse the repository at this point in the history
[VDG] UI Decoupling #50
  • Loading branch information
soosr committed Oct 25, 2023
2 parents f0b884d + 98f8f15 commit d998765
Show file tree
Hide file tree
Showing 27 changed files with 726 additions and 671 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,12 @@ private void Execute(ClassDeclarationSyntax cls)
if (member is IPropertySymbol property)
{
var accessors =
property.SetMethod is { }
? "{ get; set; }"
: "{ get; }";
property.SetMethod switch
{
IMethodSymbol s when s.IsInitOnly => "{ get; init; }",
IMethodSymbol s => "{ get; set; }",
_ => "{ get; }"
};

var type = property.Type.SimplifyType(namespaces);
properties.Add($"\t{type} {property.Name} {accessors}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private void InvalidateSeparator(Control control, TreeDataGridRowsPresenter pres
return;
}

if (currentHistoryItem.IsConfirmed)
if (currentHistoryItem.Transaction.IsConfirmed)
{
if (control.Classes.Contains(ClassName))
{
Expand All @@ -76,7 +76,7 @@ static bool IsSeparator(TreeDataGridRowsPresenter presenter, int index)
{
return presenter.Items is { } items
&& items.Count > index + 1
&& presenter.Items[index + 1].Model is HistoryItemViewModelBase { IsConfirmed: true };
&& presenter.Items[index + 1].Model is HistoryItemViewModelBase vm && vm.Transaction.IsConfirmed;
}
}
}
12 changes: 3 additions & 9 deletions WalletWasabi.Fluent/Controls/TreeDataGrid.axaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui"
<ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="clr-namespace:Avalonia.Xaml.Interactivity;assembly=Avalonia.Xaml.Interactivity"
xmlns:historyItems="clr-namespace:WalletWasabi.Fluent.ViewModels.Wallets.Home.History.HistoryItems"
Expand Down Expand Up @@ -51,7 +51,6 @@
</Border>
</ControlTemplate>
</Setter>

</ControlTheme>

<!-- TreeDataGridExpanderCell: SelectCoinsDialogView.axaml -->
Expand All @@ -76,7 +75,6 @@
</Border>
</ControlTemplate>
</Setter>

</ControlTheme>

<!-- TreeDataGridRow: Generic -->
Expand Down Expand Up @@ -156,7 +154,7 @@
Items="{TemplateBinding Columns}"
Rows="{TemplateBinding Rows}"
Margin="0,0,-2,0"
Classes.isChild="{Binding IsChild}" />
Classes.isChild="{Binding Transaction.IsChild}" />
<Rectangle Name="PART_Separator"
Margin="-2,0,0,0"
HorizontalAlignment="Stretch"
Expand Down Expand Up @@ -209,7 +207,6 @@
<Style Selector="^:pointerover /template/ TreeDataGridCellsPresenter#PART_CellsPresenter.isChild">
<Setter Property="Background" Value="Transparent" />
</Style>

</ControlTheme>

<!-- TreeDataGridRow: SelectCoinsDialogView.axaml -->
Expand Down Expand Up @@ -248,7 +245,6 @@
</DockPanel>
</ControlTemplate>
</Setter>

</ControlTheme>

<!-- TreeDataGridRow: ReceiveAddressesView.axaml -->
Expand All @@ -264,7 +260,7 @@
Background="Transparent"
x:CompileBindings="True" x:DataType="receive:AddressViewModel">
<i:Interaction.Behaviors>
<behaviors:ExecuteCommandOnDoubleTappedBehavior Command="{Binding NavigateCommand, Mode=OneWay}"/>
<behaviors:ExecuteCommandOnDoubleTappedBehavior Command="{Binding NavigateCommand, Mode=OneWay}" />
</i:Interaction.Behaviors>
<Border Name="PART_SelectionIndicator"
BorderThickness="2 0 0 0"
Expand All @@ -281,7 +277,5 @@
</DockPanel>
</ControlTemplate>
</Setter>

</ControlTheme>

</ResourceDictionary>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Avalonia.Data.Converters;
using WalletWasabi.Fluent.Extensions;
using WalletWasabi.Fluent.Helpers;
using WalletWasabi.Fluent.Models.Wallets;
using WalletWasabi.Fluent.ViewModels.Wallets.Home.History.HistoryItems;

namespace WalletWasabi.Fluent.Converters;
Expand All @@ -19,34 +20,34 @@ public object Convert(object? value, Type targetType, object? parameter, Culture
{
if (value is HistoryItemViewModelBase vm)
{
if (vm.ItemStatus == HistoryItemStatus.Confirmed)
if (vm.Transaction.Status == TransactionStatus.Confirmed)
{
return vm.ConfirmedToolTip;
return vm.Transaction.ConfirmedTooltip;
}

if (vm.TransactionSummary.TryGetConfirmationTime(out var estimate))
if (vm.Transaction.TransactionSummary.TryGetConfirmationTime(out var estimate))
{
var friendlyString = TextHelpers.TimeSpanToFriendlyString(estimate.Value);
if (friendlyString != "")
{
if (vm.ItemStatus == HistoryItemStatus.SpeedUp)
if (vm.Transaction.Status == TransactionStatus.SpeedUp)
{
return $"Pending (accelerated, confirming in ≈ {friendlyString})";
}

if (vm.ItemStatus == HistoryItemStatus.Pending)
if (vm.Transaction.Status == TransactionStatus.Pending)
{
return $"Pending (confirming in ≈ {friendlyString})";
}
}
}

if (vm.ItemStatus == HistoryItemStatus.SpeedUp)
if (vm.Transaction.Status == TransactionStatus.SpeedUp)
{
return "Pending (accelerated)";
}

if (vm.ItemStatus == HistoryItemStatus.Pending)
if (vm.Transaction.Status == TransactionStatus.Pending)
{
return "Pending";
}
Expand Down
2 changes: 2 additions & 0 deletions WalletWasabi.Fluent/Extensions/ObservableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public static class ObservableExtensions
.Select(x => Observable.FromAsync(() => onNextAsync(x)))
.Concat();

public static IObservable<Unit> Do(this IObservable<Unit> source, Action onNext) => source.Do(_ => onNext());

public static IObservable<Unit> ToSignal<T>(this IObservable<T> source) => source.Select(_ => Unit.Default);

public static IObservable<T> ReplayLastActive<T>(this IObservable<T> observable)
Expand Down
30 changes: 30 additions & 0 deletions WalletWasabi.Fluent/Helpers/SignaledFetcher.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Collections.Generic;
using System.Reactive;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using DynamicData;
#pragma warning disable CA2000

namespace WalletWasabi.Fluent.Helpers;

public class SignaledFetcher<TObject, TKey> : IDisposable where TKey : notnull
{
private readonly CompositeDisposable _disposable = new();

public SignaledFetcher(IObservable<Unit> retrieveSignal, Func<TObject, TKey> keySelector, Func<IEnumerable<TObject>> retrieve)
{
var sourceCache = new SourceCache<TObject, TKey>(keySelector)
.DisposeWith(_disposable);

retrieveSignal
.Select(_ => retrieve()).Do(items => sourceCache.Edit(updater => updater.Load(items)))
.Subscribe()
.DisposeWith(_disposable);

Changes = sourceCache.Connect();
}

public IObservable<IChangeSet<TObject, TKey>> Changes { get; }

public void Dispose() => _disposable.Dispose();
}
5 changes: 5 additions & 0 deletions WalletWasabi.Fluent/Helpers/TextHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ public static string GetPrivacyMask(int repeatCount)
return new string(UiConstants.PrivacyChar, repeatCount);
}

public static string GetConfirmationText(int confirmations)
{
return $"Confirmed ({confirmations} confirmation{AddSIfPlural(confirmations)})";
}

public static string FormatPercentageDiff(double n)
{
var precision = 0.01m;
Expand Down
2 changes: 1 addition & 1 deletion WalletWasabi.Fluent/Models/Wallets/CoinModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public CoinModel(SmartCoin coin, int anonScoreTarget)
this.WhenAnyValue(c => c.Coin.Height).Select(_ => Coin.GetConfirmations()).Subscribe(x =>
{
Confirmations = x;
ConfirmedToolTip = $"{x} confirmation{TextHelpers.AddSIfPlural(x)}";
ConfirmedToolTip = TextHelpers.GetConfirmationText(x);
});
}

Expand Down
90 changes: 90 additions & 0 deletions WalletWasabi.Fluent/Models/Wallets/TransactionModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using NBitcoin;
using ReactiveUI;
using System.Collections.Generic;
using WalletWasabi.Blockchain.Analysis.Clustering;
using WalletWasabi.Blockchain.TransactionBuilding;
using WalletWasabi.Blockchain.Transactions;
using WalletWasabi.Wallets;

namespace WalletWasabi.Fluent.Models.Wallets;

public enum TransactionType
{
Unknown,
IncomingTransaction,
OutgoingTransaction,
SelfTransferTransaction,
Coinjoin,
CoinjoinGroup,
Cancellation,
CPFP
}

public enum TransactionStatus
{
Unknown,
Confirmed,
Pending,
SpeedUp,
}

public partial class TransactionModel : ReactiveObject
{
private readonly List<TransactionModel> _children = new();

public int OrderIndex { get; init; }

public uint256 Id { get; init; }

public LabelsArray Labels { get; init; }

public DateTimeOffset Date { get; set; }

public string DateString { get; set; }

public int Confirmations { get; init; }

public string ConfirmedTooltip { get; set; }

public TransactionType Type { get; init; }

public TransactionStatus Status { get; set; }

public TransactionSummary TransactionSummary { get; init; }

public bool IsChild { get; set; }

public Money? Balance { get; set; }

public Money? IncomingAmount { get; set; }

public Money? OutgoingAmount { get; set; }

public Money? Fee { get; init; }

public Money Amount => Math.Abs(IncomingAmount ?? OutgoingAmount ?? Money.Zero);

public bool CanCancelTransaction { get; init; }

public bool CanSpeedUpTransaction { get; init; }

public IReadOnlyList<TransactionModel> Children => _children;

public bool IsConfirmed => Status == TransactionStatus.Confirmed;

public bool IsCoinjoin => Type is TransactionType.Coinjoin or TransactionType.CoinjoinGroup;

public bool IsCoinjoinGroup => Type == TransactionType.CoinjoinGroup;

public bool IsCancellation => Type == TransactionType.Cancellation;

public void Add(TransactionModel child)
{
_children.Add(child);
}

public override string ToString()
{
return $"{Type} {Status} {DateString} {Amount} {Balance}";
}
}
Loading

0 comments on commit d998765

Please sign in to comment.