Give WalletService to wallet dependent ViewModels
MODIFY
WalletWasabi.Gui/CommandLine/CommandInterpreter.cs
WalletWasabi.Gui/CommandLine/CommandInterpreter.cs
@@ -17,7 +17,7 @@ namespace WalletWasabi.Gui.CommandLine
var showHelp = false;
var showVersion = false;
var daemon = new Daemon(global);
- Logger.InitializeDefaults(Path.Combine(daemon.Global.DataDir, "Logs.txt"));
+ Logger.InitializeDefaults(Path.Combine(global.DataDir, "Logs.txt"));
if (args.Length == 0)
{

MODIFY
WalletWasabi.Gui/Controls/SuggestLabelViewModel.cs
WalletWasabi.Gui/Controls/SuggestLabelViewModel.cs
@@ -7,6 +7,7 @@ using System.Linq;
using System.Reactive.Linq;
using WalletWasabi.Gui.Tabs.WalletManager;
using WalletWasabi.Gui.ViewModels;
+using WalletWasabi.Services;
namespace WalletWasabi.Gui.Controls
{
@@ -16,7 +17,7 @@ namespace WalletWasabi.Gui.Controls
private int _caretIndex;
private string _label;
- public SuggestLabelViewModel()
+ public SuggestLabelViewModel(WalletService walletService)
{
_suggestions = new ObservableCollection<SuggestionViewModel>();
@@ -24,6 +25,7 @@ namespace WalletWasabi.Gui.Controls
.Throttle(TimeSpan.FromMilliseconds(100))
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(UpdateSuggestions);
+ WalletService = walletService;
}
public void Reset()
@@ -51,6 +53,8 @@ namespace WalletWasabi.Gui.Controls
set => this.RaiseAndSetIfChanged(ref _suggestions, value);
}
+ public WalletService WalletService { get; }
+
private void UpdateSuggestions(string words)
{
if (string.IsNullOrWhiteSpace(words))
@@ -68,9 +72,7 @@ namespace WalletWasabi.Gui.Controls
return;
}
- var global = Locator.Current.GetService<Global>();
-
- var labels = global.WalletService.GetLabels();
+ var labels = WalletService.GetLabels();
IEnumerable<string> suggestedWords = labels.Where(w => w.StartsWith(lastWord, StringComparison.InvariantCultureIgnoreCase))
.Union(labels.Where(w => w.Contains(lastWord, StringComparison.InvariantCultureIgnoreCase)))
.Except(enteredWordList)

MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/CoinJoinTabViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/CoinJoinTabViewModel.cs
@@ -59,7 +59,7 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
Password = "";
TimeLeftTillRoundTimeout = TimeSpan.Zero;
- CoinsList = new CoinListViewModel(canDequeueCoins: true);
+ CoinsList = new CoinListViewModel(WalletService, canDequeueCoins: true);
Observable
.FromEventPattern<SmartCoin>(CoinsList, nameof(CoinsList.DequeueCoinsPressed))

MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/CoinListViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/CoinListViewModel.cs
@@ -19,6 +19,7 @@ using WalletWasabi.Logging;
using WalletWasabi.Blockchain.TransactionOutputs;
using WalletWasabi.Blockchain.TransactionProcessing;
using Splat;
+using WalletWasabi.Services;
namespace WalletWasabi.Gui.Controls.WalletExplorer
{
@@ -72,6 +73,7 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
public ReadOnlyObservableCollection<CoinViewModel> Coins => _coinViewModels;
public bool DisplayCommonOwnershipWarning { get; set; } = false;
+ public WalletService WalletService { get; }
public bool CanDequeueCoins { get; set; } = false;
private SortExpressionComparer<CoinViewModel> MyComparer
@@ -248,13 +250,14 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
}
}
- public CoinListViewModel(bool canDequeueCoins = false, bool displayCommonOwnershipWarning = false)
+ public CoinListViewModel(WalletService walletService, bool canDequeueCoins = false, bool displayCommonOwnershipWarning = false)
{
Global = Locator.Current.GetService<Global>();
AmountSortDirection = SortOrder.Decreasing;
CoinJoinStatusWidth = new GridLength(0);
+ WalletService = walletService;
CanDequeueCoins = canDequeueCoins;
DisplayCommonOwnershipWarning = displayCommonOwnershipWarning;
@@ -422,7 +425,7 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
.DisposeWith(Disposables);
Observable
- .Merge(Observable.FromEventPattern<ProcessedResult>(Global.WalletService.TransactionProcessor, nameof(Global.WalletService.TransactionProcessor.WalletRelevantTransactionProcessed)).Select(_ => Unit.Default))
+ .Merge(Observable.FromEventPattern<ProcessedResult>(WalletService.TransactionProcessor, nameof(WalletService.TransactionProcessor.WalletRelevantTransactionProcessed)).Select(_ => Unit.Default))
.Throttle(TimeSpan.FromSeconds(1)) // Throttle TransactionProcessor events adds/removes.
.Merge(Observable.FromEventPattern(this, nameof(CoinListShown), RxApp.MainThreadScheduler).Select(_ => Unit.Default)) // Load the list immediately.
.ObserveOn(RxApp.MainThreadScheduler)
@@ -430,7 +433,7 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
{
try
{
- var actual = Global.WalletService.TransactionProcessor.Coins.ToHashSet();
+ var actual = WalletService.TransactionProcessor.Coins.ToHashSet();
var old = RootList.Items.ToDictionary(c => c.Model, c => c);
var coinToRemove = old.Where(c => !actual.Contains(c.Key)).ToArray();
@@ -438,7 +441,7 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
RootList.RemoveMany(coinToRemove.Select(kp => kp.Value));
- var newCoinViewModels = coinToAdd.Select(c => new CoinViewModel(this, c)).ToArray();
+ var newCoinViewModels = coinToAdd.Select(c => new CoinViewModel(WalletService, this, c)).ToArray();
foreach (var cvm in newCoinViewModels)
{
SubscribeToCoinEvents(cvm);
@@ -519,7 +522,7 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
Observable
.Merge(cvm.Model.WhenAnyValue(x => x.IsBanned, x => x.SpentAccordingToBackend, x => x.Confirmed, x => x.CoinJoinInProgress).Select(_ => Unit.Default))
- .Merge(Observable.FromEventPattern(Global.WalletService.ChaumianClient, nameof(Global.WalletService.ChaumianClient.StateUpdated)).Select(_ => Unit.Default))
+ .Merge(Observable.FromEventPattern(WalletService.ChaumianClient, nameof(WalletService.ChaumianClient.StateUpdated)).Select(_ => Unit.Default))
.Synchronize(StateChangedLock) // Use the same lock to ensure thread safety.
.Throttle(TimeSpan.FromSeconds(1))
.ObserveOn(RxApp.MainThreadScheduler)

MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/CoinViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/CoinViewModel.cs
@@ -18,6 +18,7 @@ using WalletWasabi.Logging;
using AvalonStudio.Extensibility;
using AvalonStudio.Shell;
using Avalonia;
+using WalletWasabi.Services;
namespace WalletWasabi.Gui.Controls.WalletExplorer
{
@@ -33,6 +34,7 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
private ObservableAsPropertyHelper<bool> _unavailable;
private ObservableAsPropertyHelper<string> _cluster;
+ public WalletService WalletService { get; }
public CoinListViewModel Owner { get; }
private Global Global { get; }
public bool CanBeDequeued => Owner.CanDequeueCoins;
@@ -40,11 +42,12 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
public ReactiveCommand<Unit, Unit> OpenCoinInfo { get; }
public ReactiveCommand<Unit, Unit> CopyClusters { get; }
- public CoinViewModel(CoinListViewModel owner, SmartCoin model)
+ public CoinViewModel(WalletService walletService, CoinListViewModel owner, SmartCoin model)
{
Global = Locator.Current.GetService<Global>();
Model = model;
+ WalletService = walletService;
Owner = owner;
RefreshSmartCoinStatus();
@@ -83,7 +86,7 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
Observable
.Merge(Model.WhenAnyValue(x => x.IsBanned, x => x.SpentAccordingToBackend, x => x.Confirmed, x => x.CoinJoinInProgress).Select(_ => Unit.Default))
- .Merge(Observable.FromEventPattern(Global.WalletService.ChaumianClient, nameof(Global.WalletService.ChaumianClient.StateUpdated)).Select(_ => Unit.Default))
+ .Merge(Observable.FromEventPattern(WalletService.ChaumianClient, nameof(WalletService.ChaumianClient.StateUpdated)).Select(_ => Unit.Default))
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(_ => RefreshSmartCoinStatus())
.DisposeWith(Disposables);
@@ -208,9 +211,9 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
return SmartCoinStatus.MixingBanned;
}
- if (Model.CoinJoinInProgress && Global.WalletService.ChaumianClient != null)
+ if (Model.CoinJoinInProgress && WalletService.ChaumianClient != null)
{
- ClientState clientState = Global.WalletService.ChaumianClient.State;
+ ClientState clientState = WalletService.ChaumianClient.State;
foreach (var round in clientState.GetAllMixingRounds())
{
if (round.CoinsRegistered.Contains(Model))

MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/HistoryTabViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/HistoryTabViewModel.cs
@@ -57,8 +57,8 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
Disposables = Disposables is null ? new CompositeDisposable() : throw new NotSupportedException($"Cannot open {GetType().Name} before closing it.");
- Observable.FromEventPattern(Global.WalletService, nameof(Global.WalletService.NewBlockProcessed))
- .Merge(Observable.FromEventPattern(Global.WalletService.TransactionProcessor, nameof(Global.WalletService.TransactionProcessor.WalletRelevantTransactionProcessed)))
+ Observable.FromEventPattern(WalletService, nameof(WalletService.NewBlockProcessed))
+ .Merge(Observable.FromEventPattern(WalletService.TransactionProcessor, nameof(WalletService.TransactionProcessor.WalletRelevantTransactionProcessed)))
.Throttle(TimeSpan.FromSeconds(3))
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(async _ => await TryRewriteTableAsync())
@@ -85,7 +85,7 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
{
try
{
- var historyBuilder = new TransactionHistoryBuilder(Global.WalletService);
+ var historyBuilder = new TransactionHistoryBuilder(WalletService);
var txRecordList = await Task.Run(historyBuilder.BuildHistorySummary);
var rememberSelectedTransactionId = SelectedTransaction?.TransactionId;

MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/ReceiveTabViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/ReceiveTabViewModel.cs
@@ -37,7 +37,7 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
: base("Receive", walletViewModel)
{
Global = Locator.Current.GetService<Global>();
- LabelSuggestion = new SuggestLabelViewModel();
+ LabelSuggestion = new SuggestLabelViewModel(WalletService);
_addresses = new ObservableCollection<AddressViewModel>();
LabelSuggestion.Label = "";
@@ -100,7 +100,7 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
Disposables = Disposables is null ? new CompositeDisposable() : throw new NotSupportedException($"Cannot open {GetType().Name} before closing it.");
Observable
- .FromEventPattern(Global.WalletService.TransactionProcessor, nameof(Global.WalletService.TransactionProcessor.WalletRelevantTransactionProcessed))
+ .FromEventPattern(WalletService.TransactionProcessor, nameof(WalletService.TransactionProcessor.WalletRelevantTransactionProcessed))
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(_ => InitializeAddresses())
.DisposeWith(Disposables);

MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/SendControlViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/SendControlViewModel.cs
@@ -103,13 +103,13 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
: base(title, walletViewModel)
{
Global = Locator.Current.GetService<Global>();
- LabelSuggestion = new SuggestLabelViewModel();
+ LabelSuggestion = new SuggestLabelViewModel(WalletService);
BuildTransactionButtonText = DoButtonText;
ResetUi();
SetAmountWatermark(Money.Zero);
- CoinList = new CoinListViewModel(displayCommonOwnershipWarning: true);
+ CoinList = new CoinListViewModel(WalletService, displayCommonOwnershipWarning: true);
Observable.FromEventPattern(CoinList, nameof(CoinList.SelectionChanged))
.ObserveOn(RxApp.MainThreadScheduler)
@@ -302,7 +302,7 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
TxoRef[] toDequeue = selectedCoinViewModels.Where(x => x.CoinJoinInProgress).Select(x => x.Model.GetTxoRef()).ToArray();
if (toDequeue != null && toDequeue.Any())
{
- await Global.WalletService.ChaumianClient.DequeueCoinsFromMixAsync(toDequeue, DequeueReason.TransactionBuilding);
+ await WalletService.ChaumianClient.DequeueCoinsFromMixAsync(toDequeue, DequeueReason.TransactionBuilding);
}
}
catch
@@ -339,7 +339,7 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
}
}
- BuildTransactionResult result = await Task.Run(() => Global.WalletService.BuildTransaction(Password, intent, feeStrategy, allowUnconfirmed: true, allowedInputs: selectedCoinReferences));
+ BuildTransactionResult result = await Task.Run(() => WalletService.BuildTransaction(Password, intent, feeStrategy, allowUnconfirmed: true, allowedInputs: selectedCoinReferences));
await DoAfterBuildTransaction(result);
}

MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/WalletExplorerViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/WalletExplorerViewModel.cs
@@ -50,7 +50,7 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
return;
}
- WalletViewModel walletViewModel = new WalletViewModel(receiveDominant);
+ WalletViewModel walletViewModel = new WalletViewModel(walletService, receiveDominant);
_wallets.Add(walletViewModel);
walletViewModel.OnWalletOpened();

MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/WalletViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/WalletViewModel.cs
@@ -38,13 +38,13 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
set => this.RaiseAndSetIfChanged(ref _title, value);
}
- public WalletViewModel(bool receiveDominant)
+ public WalletViewModel(WalletService walletService, bool receiveDominant)
{
var global = Locator.Current.GetService<Global>();
+ WalletService = walletService;
- Title = Path.GetFileNameWithoutExtension(global.WalletService.KeyManager.FilePath);
+ Title = Path.GetFileNameWithoutExtension(WalletService.KeyManager.FilePath);
- WalletService = global.WalletService;
var keyManager = WalletService.KeyManager;
Name = Path.GetFileNameWithoutExtension(keyManager.FilePath);
@@ -123,7 +123,7 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
var global = Locator.Current.GetService<Global>();
Observable.Merge(
- Observable.FromEventPattern(global.WalletService.TransactionProcessor, nameof(Global.WalletService.TransactionProcessor.WalletRelevantTransactionProcessed)).Select(_ => Unit.Default))
+ Observable.FromEventPattern(WalletService.TransactionProcessor, nameof(WalletService.TransactionProcessor.WalletRelevantTransactionProcessed)).Select(_ => Unit.Default))
.Throttle(TimeSpan.FromSeconds(0.1))
.Merge(global.UiConfig.WhenAnyValue(x => x.LurkingWifeMode).Select(_ => Unit.Default))
.ObserveOn(RxApp.MainThreadScheduler)

Give WalletService to wallet dependent ViewModels