コード例 #1
0
        public void SubscribeEvents()
        {
            if (Disposables != null)
            {
                throw new Exception("Please report to Dan");
            }

            Disposables = new CompositeDisposable();

            //TODO defer subscription to when accessed (will be faster in ui.)
            _coinJoinInProgress = Model.WhenAnyValue(x => x.CoinJoinInProgress)
                                  .ToProperty(this, x => x.CoinJoinInProgress, scheduler: RxApp.MainThreadScheduler)
                                  .DisposeWith(Disposables);

            _unspent = Model.WhenAnyValue(x => x.Unspent)
                       .ToProperty(this, x => x.Unspent, scheduler: RxApp.MainThreadScheduler)
                       .DisposeWith(Disposables);

            _confirmed = Model.WhenAnyValue(x => x.Confirmed)
                         .ToProperty(this, x => x.Confirmed, scheduler: RxApp.MainThreadScheduler)
                         .DisposeWith(Disposables);

            _unavailable = Model.WhenAnyValue(x => x.Unavailable)
                           .ToProperty(this, x => x.Unavailable, scheduler: RxApp.MainThreadScheduler)
                           .DisposeWith(Disposables);

            this.WhenAnyValue(x => x.Status)
            .Subscribe(_ => this.RaisePropertyChanged(nameof(ToolTip)));

            this.WhenAnyValue(x => x.Confirmed, x => x.CoinJoinInProgress, x => x.Confirmations)
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(_ => RefreshSmartCoinStatus());

            this.WhenAnyValue(x => x.IsSelected)
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(_ => _owner.OnCoinIsSelectedChanged(this));

            this.WhenAnyValue(x => x.Status)
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(_ => _owner.OnCoinStatusChanged());

            this.WhenAnyValue(x => x.Unspent)
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(_ => _owner.OnCoinUnspentChanged(this));

            Model.WhenAnyValue(x => x.IsBanned, x => x.SpentAccordingToBackend)
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(_ => RefreshSmartCoinStatus())
            .DisposeWith(Disposables);

            Observable.FromEventPattern(
                Global.ChaumianClient,
                nameof(Global.ChaumianClient.StateUpdated))
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(_ =>
            {
                RefreshSmartCoinStatus();
            }).DisposeWith(Disposables);

            Global.BitcoinStore.HashChain.WhenAnyValue(x => x.ServerTipHeight)
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(_ =>
            {
                this.RaisePropertyChanged(nameof(Confirmations));
            }).DisposeWith(Disposables);

            Global.UiConfig.WhenAnyValue(x => x.LurkingWifeMode)
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(_ =>
            {
                this.RaisePropertyChanged(nameof(AmountBtc));
                this.RaisePropertyChanged(nameof(Clusters));
            }).DisposeWith(Disposables);
        }
コード例 #2
0
        public CoinViewModel(CoinListViewModel owner, SmartCoin model)
        {
            Model       = model;
            _owner      = owner;
            Disposables = new CompositeDisposable();

            _coinJoinInProgress = Model
                                  .WhenAnyValue(x => x.CoinJoinInProgress)
                                  .ToProperty(this, x => x.CoinJoinInProgress, scheduler: RxApp.MainThreadScheduler)
                                  .DisposeWith(Disposables);

            _unspent = Model
                       .WhenAnyValue(x => x.Unspent)
                       .ToProperty(this, x => x.Unspent, scheduler: RxApp.MainThreadScheduler)
                       .DisposeWith(Disposables);

            _confirmed = Model
                         .WhenAnyValue(x => x.Confirmed)
                         .ToProperty(this, x => x.Confirmed, scheduler: RxApp.MainThreadScheduler)
                         .DisposeWith(Disposables);

            _unavailable = Model
                           .WhenAnyValue(x => x.Unavailable)
                           .ToProperty(this, x => x.Unavailable, scheduler: RxApp.MainThreadScheduler)
                           .DisposeWith(Disposables);

            this.WhenAnyValue(x => x.Status)
            .Subscribe(_ => this.RaisePropertyChanged(nameof(ToolTip)));

            this.WhenAnyValue(x => x.Confirmed, x => x.CoinJoinInProgress, x => x.Confirmations)
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(_ => RefreshSmartCoinStatus());

            this.WhenAnyValue(x => x.IsSelected)
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(_ => _owner.OnCoinIsSelectedChanged(this));

            this.WhenAnyValue(x => x.Status)
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(_ => _owner.OnCoinStatusChanged());

            this.WhenAnyValue(x => x.Unspent)
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(_ => _owner.OnCoinUnspentChanged(this));

            Model.WhenAnyValue(x => x.IsBanned, x => x.SpentAccordingToBackend)
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(_ => RefreshSmartCoinStatus())
            .DisposeWith(Disposables);

            Observable
            .FromEventPattern(Global.ChaumianClient, nameof(Global.ChaumianClient.StateUpdated))
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(_ => RefreshSmartCoinStatus())
            .DisposeWith(Disposables);

            Global.BitcoinStore.HashChain
            .WhenAnyValue(x => x.TipHeight)
            .Throttle(TimeSpan.FromMilliseconds(100))
            .Select(x => new Height(x))
            .Merge(Model.WhenAnyValue(x => x.Height))
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(_ => this.RaisePropertyChanged(nameof(Confirmations)))
            .DisposeWith(Disposables);

            Global.UiConfig
            .WhenAnyValue(x => x.LurkingWifeMode)
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(_ =>
            {
                this.RaisePropertyChanged(nameof(AmountBtc));
                this.RaisePropertyChanged(nameof(Clusters));
            }).DisposeWith(Disposables);
        }