public ConnectHardwareWalletViewModel(WalletManagerViewModel owner) : base("Hardware Wallet") { Global = Locator.Current.GetService <Global>(); WalletManager = Global.WalletManager; Owner = owner; _wallets = new ObservableCollection <HardwareWalletViewModel>(); IsHwWalletSearchTextVisible = false; this.WhenAnyValue(x => x.SelectedWallet) .Where(x => x is null) .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(_ => { SelectedWallet = Wallets.FirstOrDefault(); SetLoadButtonText(); }); Wallets .ToObservableChangeSet() .ToCollection() .Where(items => items.Any() && SelectedWallet is null) .Select(items => items.First()) .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(x => SelectedWallet = x); this.WhenAnyValue(x => x.IsBusy, x => x.IsHardwareBusy) .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(_ => SetLoadButtonText()); LoadCommand = ReactiveCommand.CreateFromTask(LoadWalletAsync, this.WhenAnyValue(x => x.SelectedWallet, x => x.IsBusy).Select(x => x.Item1 is { } && !x.Item2));
public MainWindowViewModel() { foreach (var wallet in WalletViewModel.Load(App.AppDir)) { Wallets.Add(wallet); wallet.Update(); } SelectedWallet = Wallets.FirstOrDefault(); StartConnecting(); }
private bool _disposedValue = false; // To detect redundant calls public LoadWalletViewModel(WalletManagerViewModel owner, LoadWalletType loadWalletType) : base(loadWalletType == LoadWalletType.Password ? "Test Password" : "Load Wallet") { Global = Locator.Current.GetService <Global>(); Owner = owner; Password = ""; LoadWalletType = loadWalletType; this.ValidateProperty(x => x.Password, ValidatePassword); RootList = new SourceList <WalletViewModelBase>(); RootList.Connect() .AutoRefresh(model => model.WalletState) .Filter(x => (!IsPasswordRequired || !x.Wallet.KeyManager.IsWatchOnly)) .Sort(SortExpressionComparer <WalletViewModelBase> .Descending(p => p.Wallet.KeyManager.GetLastAccessTime()), resort: ResortTrigger.AsObservable()) .ObserveOn(RxApp.MainThreadScheduler) .Bind(out _wallets) .DisposeMany() .Subscribe() .DisposeWith(Disposables); Observable.FromEventPattern <Wallet>(Global.WalletManager, nameof(Global.WalletManager.WalletAdded)) .ObserveOn(RxApp.MainThreadScheduler) .Select(x => x.EventArgs) .Subscribe(wallet => RootList.Add(new WalletViewModelBase(wallet))) .DisposeWith(Disposables); this.WhenAnyValue(x => x.SelectedWallet) .Where(x => x is null) .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(_ => SelectedWallet = Wallets.FirstOrDefault()); Wallets .ToObservableChangeSet() .ToCollection() .Where(items => items.Any() && SelectedWallet is null) .Select(items => items.First()) .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(x => SelectedWallet = x); LoadCommand = ReactiveCommand.Create(() => RxApp.MainThreadScheduler .Schedule(async() => await LoadWalletAsync()) .DisposeWith(Disposables), this.WhenAnyValue(x => x.SelectedWallet, x => x?.WalletState) .Select(x => x == WalletState.Uninitialized)); TestPasswordCommand = ReactiveCommand.Create(LoadKeyManager, this.WhenAnyValue(x => x.SelectedWallet).Select(x => x is { }));