Make sure percentages can be added to the statuses.
MODIFY
WalletWasabi.Gui/Models/StatusBarStatuses/Status.cs
WalletWasabi.Gui/Models/StatusBarStatuses/Status.cs
@@ -5,9 +5,9 @@ using WalletWasabi.Helpers;
namespace WalletWasabi.Gui.Models.StatusBarStatuses
{
- public class Status
+ public class Status : IEquatable<Status>
{
- public static Status Started(StatusType type) => new Status(type, 0);
+ public static Status Set(StatusType type) => new Status(type, 0);
public static Status Completed(StatusType type) => new Status(type, 100);
@@ -20,6 +20,8 @@ namespace WalletWasabi.Gui.Models.StatusBarStatuses
public StatusType Type { get; }
public int Percentage { get; }
+ public bool IsCompleted => Percentage == 100;
+
public override string ToString()
{
var friendlyName = Type switch
@@ -50,5 +52,19 @@ namespace WalletWasabi.Gui.Models.StatusBarStatuses
return $"{friendlyName} {Percentage}%";
}
}
+
+ #region EqualityAndComparison
+
+ public override bool Equals(object obj) => obj is Status rpcStatus && this == rpcStatus;
+
+ public bool Equals(Status other) => this == other;
+
+ public override int GetHashCode() => Type.GetHashCode() ^ Percentage.GetHashCode();
+
+ public static bool operator ==(Status x, Status y) => y?.Type == x?.Type && y?.Percentage == x?.Percentage;
+
+ public static bool operator !=(Status x, Status y) => !(x == y);
+
+ #endregion EqualityAndComparison
}
}

MODIFY
WalletWasabi.Gui/Models/StatusBarStatuses/StatusSet.cs
WalletWasabi.Gui/Models/StatusBarStatuses/StatusSet.cs
@@ -10,62 +10,81 @@ namespace WalletWasabi.Gui.Models.StatusBarStatuses
{
public class StatusSet : ReactiveObject
{
- private StatusType _status;
+ private Status _status;
- private HashSet<StatusType> ActiveStatuses { get; }
+ private HashSet<Status> ActiveStatuses { get; }
private object ActiveStatusesLock { get; }
public StatusSet()
{
- ActiveStatuses = new HashSet<StatusType>() { StatusType.Ready };
+ ActiveStatuses = new HashSet<Status>() { Status.Set(StatusType.Ready) };
ActiveStatusesLock = new object();
- CurrentStatus = StatusType.Loading;
+ CurrentStatus = Status.Set(StatusType.Loading);
}
- public StatusType CurrentStatus
+ public Status CurrentStatus
{
get => _status;
set => this.RaiseAndSetIfChanged(ref _status, value);
}
- public bool TryAddStatus(StatusType status)
+ public void Complete(params StatusType[] statuses)
+ => Complete(statuses as IEnumerable<StatusType>);
+
+ public void Complete(IEnumerable<StatusType> statuses)
+ => Set(statuses.Select(x => Status.Completed(x)));
+
+ public void Set(params StatusType[] statuses)
+ => Set(statuses as IEnumerable<StatusType>);
+
+ public void Set(IEnumerable<StatusType> statuses)
+ => Set(statuses.Select(x => Status.Set(x)));
+
+ public void Set(params Status[] statuses)
+ => Set(statuses as IEnumerable<Status>);
+
+ public void Set(IEnumerable<Status> statuses)
{
- bool ret;
+ Status updateWith = null;
lock (ActiveStatusesLock)
{
- ret = ActiveStatuses.Add(status);
- }
+ var updated = false;
- if (ret)
+ foreach (var status in statuses)
{
- AdjustCurrentStatus();
- }
-
- return ret;
- }
-
- private void AdjustCurrentStatus()
+ if (status.IsCompleted)
{
- Dispatcher.UIThread.PostLogException(() => CurrentStatus = ActiveStatuses.Min());
+ updated = ActiveStatuses.RemoveWhere(x => x.Type == status.Type) == 1 || updated;
}
-
- public bool TryRemoveStatus(params StatusType[] statuses)
+ else
{
- bool ret = false;
- lock (ActiveStatusesLock)
+ var found = ActiveStatuses.FirstOrDefault(x => x.Type == status.Type);
+ if (found is { Percentage: var perc })
+ {
+ if (perc != status.Percentage)
{
- foreach (StatusType status in statuses.ToHashSet())
+ ActiveStatuses.Remove(found);
+ updated = ActiveStatuses.Add(status) || updated;
+ }
+ }
+ else
{
- ret = ActiveStatuses.Remove(status) || ret;
+ updated = ActiveStatuses.Add(status) || updated;
+ }
}
}
- if (ret)
+ if (updated && ActiveStatuses.Any())
{
- AdjustCurrentStatus();
+ var priority = ActiveStatuses.Min(x => x.Type);
+ updateWith = ActiveStatuses.First(x => x.Type == priority);
+ }
}
- return ret;
+ if (updateWith is { })
+ {
+ Dispatcher.UIThread.PostLogException(() => CurrentStatus = updateWith);
+ }
}
}
}

MODIFY
WalletWasabi.Gui/ViewModels/StatusBarViewModel.cs
WalletWasabi.Gui/ViewModels/StatusBarViewModel.cs
@@ -331,7 +331,7 @@ namespace WalletWasabi.Gui.ViewModels
{
try
{
- ActiveStatuses.TryAddStatus(status);
+ ActiveStatuses.Set(status);
}
catch (Exception ex)
{
@@ -343,7 +343,7 @@ namespace WalletWasabi.Gui.ViewModels
{
try
{
- ActiveStatuses.TryRemoveStatus(statuses);
+ ActiveStatuses.Complete(statuses);
}
catch (Exception ex)
{

Make sure percentages can be added to the statuses.