Refactor AddressViewModel.
MODIFY
WalletWasabi.Gui/ViewModels/AddressViewModel.cs
WalletWasabi.Gui/ViewModels/AddressViewModel.cs
using Avalonia;
-using Avalonia.Threading;
using Gma.QrCodeNet.Encoding;
using ReactiveUI;
using System;
-using System.IO;
using System.Linq;
using System.Reactive;
using System.Reactive.Disposables;
@@ -42,21 +40,29 @@ namespace WalletWasabi.Gui.ViewModels
.ObserveOn(RxApp.TaskpoolScheduler)
.Where(x => x)
.Take(1)
- .Subscribe(_ =>
- {
- try
+ .Select(x =>
{
var encoder = new QrEncoder();
encoder.TryEncode(Address, out var qrCode);
- Dispatcher.UIThread.PostLogException(() => QrCode = qrCode.Matrix.InternalArray);
+ return qrCode.Matrix.InternalArray;
+ })
+ .ObserveOn(RxApp.MainThreadScheduler)
+ .Subscribe(qr =>
+ {
+ try
+ {
+ QrCode = qr;
}
catch (Exception ex)
{
Logger.LogError(ex);
}
- });
+ }, onError: ex => Logger.LogError(ex)); // Catch the exceptions everywhere (e.g.: Select) except in Subscribe.
- Global.UiConfig.WhenAnyValue(x => x.LurkingWifeMode).Subscribe(_ =>
+ Global.UiConfig
+ .WhenAnyValue(x => x.LurkingWifeMode)
+ .ObserveOn(RxApp.MainThreadScheduler)
+ .Subscribe(_ =>
{
this.RaisePropertyChanged(nameof(IsLurkingWifeMode));
this.RaisePropertyChanged(nameof(Address));
@@ -64,6 +70,7 @@ namespace WalletWasabi.Gui.ViewModels
}).DisposeWith(Disposables);
this.WhenAnyValue(x => x.Label)
+ .ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(newLabel =>
{
if (InEditMode)
@@ -78,7 +85,8 @@ namespace WalletWasabi.Gui.ViewModels
}
});
- _expandMenuCaption = this.WhenAnyValue(x => x.IsExpanded)
+ _expandMenuCaption = this
+ .WhenAnyValue(x => x.IsExpanded)
.Select(x => (x ? "Hide " : "Show ") + "QR Code")
.ObserveOn(RxApp.MainThreadScheduler)
.ToProperty(this, x => x.ExpandMenuCaption)
@@ -139,7 +147,7 @@ namespace WalletWasabi.Gui.ViewModels
public string ExpandMenuCaption => _expandMenuCaption?.Value ?? string.Empty;
- public CancellationTokenSource CancelClipboardNotification { get; set; }
+ private CancellationTokenSource CancelClipboardNotification { get; set; }
public async Task TryCopyToClipboardAsync()
{
@@ -195,6 +203,7 @@ namespace WalletWasabi.Gui.ViewModels
{
if (disposing)
{
+ CancelClipboardNotification?.Dispose();
Disposables?.Dispose();
}

Refactor AddressViewModel.