Implement fees and exchange rates
MODIFY
WalletWasabi/Models/AllFeeEstimate.cs
WalletWasabi/Models/AllFeeEstimate.cs
@@ -10,7 +10,7 @@ using WalletWasabi.Helpers;
namespace WalletWasabi.Models
{
[JsonObject(MemberSerialization.OptIn)]
- public class AllFeeEstimate
+ public class AllFeeEstimate : IEquatable<AllFeeEstimate>
{
[JsonProperty]
public EstimateSmartFeeMode Type { get; }
@@ -36,6 +36,68 @@ namespace WalletWasabi.Models
Estimations.TryAdd(estimation.Key, estimation.Value);
}
}
+ _hashCode = null;
}
+
+ #region Equality
+
+ public override bool Equals(object obj) => obj is AllFeeEstimate && this == (AllFeeEstimate)obj;
+
+ public bool Equals(AllFeeEstimate other) => this == other;
+
+ private int? _hashCode;
+
+ public override int GetHashCode()
+ {
+ if (!_hashCode.HasValue)
+ {
+ int hash = Type.GetHashCode();
+ foreach (KeyValuePair<int, int> est in Estimations)
+ {
+ hash = hash ^ est.Key.GetHashCode() ^ est.Value.GetHashCode();
+ }
+ _hashCode = hash;
+ }
+
+ return _hashCode.Value;
+ }
+
+ public static bool operator ==(AllFeeEstimate x, AllFeeEstimate y)
+ {
+ if (ReferenceEquals(x, y)) return true;
+ if (x is null ^ y is null) return false;
+
+ if (x.Type != y.Type) return false;
+
+ bool equal = false;
+ if (x.Estimations.Count == y.Estimations.Count) // Require equal count.
+ {
+ equal = true;
+ foreach (var pair in x.Estimations)
+ {
+ if (y.Estimations.TryGetValue(pair.Key, out int value))
+ {
+ // Require value be equal.
+ if (value != pair.Value)
+ {
+ equal = false;
+ break;
+ }
+ }
+ else
+ {
+ // Require key be present.
+ equal = false;
+ break;
+ }
+ }
+ }
+
+ return equal;
+ }
+
+ public static bool operator !=(AllFeeEstimate x, AllFeeEstimate y) => !(x == y);
+
+ #endregion Equality
}
}

MODIFY
WalletWasabi/Services/WasabiSynchronizer.cs
WalletWasabi/Services/WasabiSynchronizer.cs
@@ -44,6 +44,41 @@ namespace WalletWasabi.Services
}
}
+ private decimal _usdExchangeRate;
+
+ /// <summary>
+ /// The Bitcoin price in USD.
+ /// </summary>
+ public decimal UsdExchangeRate
+ {
+ get => _usdExchangeRate;
+
+ private set
+ {
+ if (_usdExchangeRate != value)
+ {
+ _usdExchangeRate = value;
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(UsdExchangeRate)));
+ }
+ }
+ }
+
+ private AllFeeEstimate _allFeeEstimate;
+
+ public AllFeeEstimate AllFeeEstimate
+ {
+ get => _allFeeEstimate;
+
+ private set
+ {
+ if (_allFeeEstimate != value)
+ {
+ _allFeeEstimate = value;
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(AllFeeEstimate)));
+ }
+ }
+ }
+
private FilterModel _bestKnownFilter;
public FilterModel BestKnownFilter
@@ -254,6 +289,7 @@ namespace WalletWasabi.Services
if (response.AllFeeEstimate != null && response.AllFeeEstimate.Estimations.Any())
{
lastFeeQueried = DateTimeOffset.UtcNow;
+ AllFeeEstimate = response.AllFeeEstimate;
}
if (response.Filters.Count() == maxFiltersToSyncAtInitialization)
@@ -266,6 +302,11 @@ namespace WalletWasabi.Services
}
BestBlockchainHeight = response.BestHeight;
+ ExchangeRate exchangeRate = response.ExchangeRates.FirstOrDefault();
+ if (exchangeRate != default && exchangeRate.Rate != 0)
+ {
+ UsdExchangeRate = exchangeRate.Rate;
+ }
if (response.FiltersResponseState == FiltersResponseState.NewFilters)
{

Implement fees and exchange rates