Hook to the Wallet Service
MODIFY
WalletWasabi.Gui/Global.cs
WalletWasabi.Gui/Global.cs
@@ -158,7 +158,7 @@ namespace WalletWasabi.Gui
Logger.LogInfo("WalletService started.");
}
CancelWalletServiceInitialization = null; // Must make it null explicitly, because dispose won't make it null.
- Notifier.Current.Start();;
+ Notifier.Current.Start();
}
public static async Task DisposeInWalletDependentServicesAsync()

MODIFY
WalletWasabi.Gui/TransactionWatcher.cs
WalletWasabi.Gui/TransactionWatcher.cs
@@ -7,89 +7,25 @@ using WalletWasabi.Models;
namespace WalletWasabi.Gui
{
- class CoinEventArgs : EventArgs
- {
- public SmartCoin Coin { get; }
-
- public CoinEventArgs(SmartCoin coin)
- {
- Coin = coin;
- }
- }
-
- class CoinsWatcher
- {
- private List<SmartCoin> _trackedCoins;
- private bool _isSynchronized = false;
- public EventHandler<CoinEventArgs> CoinReceived;
-
- public CoinsWatcher()
- {
- _trackedCoins = new List<SmartCoin>();
- OnBestHeightChanged(this, Height.Unknown);
- }
-
- public void Start()
- {
- Global.IndexDownloader.BestHeightChanged += OnBestHeightChanged;
- Global.WalletService.Coins.HashSetChanged += OnCoinsArrives;
- }
-
- public void Stop()
- {
- Global.IndexDownloader.BestHeightChanged -= OnBestHeightChanged;
- Global.WalletService.Coins.HashSetChanged -= OnCoinsArrives;
- }
- private void OnBestHeightChanged(object sender, Height e)
- {
- var filterLeft = Global.IndexDownloader.GetFiltersLeft();
- if(filterLeft == 0)
- {
- Global.IndexDownloader.BestHeightChanged -= OnBestHeightChanged;
- _trackedCoins = Global.WalletService.Coins.ToList();
- _isSynchronized = true;
- }
- }
-
- private void OnCoinsArrives(object sender, EventArgs e)
- {
- var allCoins = Global.WalletService.Coins;
-
- foreach(var coin in allCoins)
- {
- if( !_trackedCoins.Contains(coin) && _isSynchronized)
- {
- CoinReceived?.Invoke(this, new CoinEventArgs(coin));
- }
- }
- _trackedCoins = allCoins.ToList();
- }
- }
-
class Notifier
{
- private CoinsWatcher _watcher;
-
- public static readonly Notifier Current = new Notifier();
+ public readonly static Notifier Current = new Notifier();
private Notifier()
{
- _watcher = new CoinsWatcher();
}
public void Start()
{
- _watcher.Start();
- _watcher.CoinReceived += NotifyIncomingCoin;
+ Global.WalletService.CoinReceived += OnCoinReceived;
}
public void Stop()
{
- _watcher.CoinReceived -= NotifyIncomingCoin;
- _watcher.Stop();
+ Global.WalletService.CoinReceived -= OnCoinReceived;
}
- private void NotifyIncomingCoin(object sender, CoinEventArgs e)
+ private void OnCoinReceived(object sender, SmartCoin coin)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
@@ -98,7 +34,7 @@ namespace WalletWasabi.Gui
{
Process.Start(new ProcessStartInfo {
FileName = "notify-send",
- Arguments = $"\"Wasabi Wallet\" \"You have received an incoming transaction {e.Coin.Amount} BTC\"",
+ Arguments = $"\"Wasabi Wallet\" \"You have received an incoming transaction {coin.Amount} BTC\"",
CreateNoWindow = true
});
}
@@ -106,7 +42,7 @@ namespace WalletWasabi.Gui
{
Process.Start(new ProcessStartInfo {
FileName = "osascript",
- Arguments = $"-e display notification \"You have received an incoming transaction {e.Coin.Amount} BTC\" with title \"Wasabi Wallet\"",
+ Arguments = $"-e display notification \"You have received an incoming transaction {coin.Amount} BTC\" with title \"Wasabi Wallet\"",
CreateNoWindow = true
});
}

MODIFY
WalletWasabi/Services/WalletService.cs
WalletWasabi/Services/WalletService.cs
@@ -62,6 +62,8 @@ namespace WalletWasabi.Services
public event EventHandler<SmartCoin> CoinSpentOrSpenderConfirmed;
+ public event EventHandler<SmartCoin> CoinReceived;
+
public event EventHandler<Block> NewBlockProcessed;
public Network Network => IndexDownloader.Network;
@@ -481,6 +483,7 @@ namespace WalletWasabi.Services
ChaumianClient.State.UpdateCoin(coin);
Coins.TryAdd(coin);
TransactionCache.Add(tx);
+ CoinReceived?.Invoke(this, coin);
if (coin.Unspent && coin.Label == "ZeroLink Change" && ChaumianClient.OnePiece != null)
{
Task.Run(async () =>

Hook to the Wallet Service