コード例 #1
0
        public AppBootstrapper()
        {
            Locator.CurrentMutable.InitializeSplat();
            Locator.CurrentMutable.InitializeReactiveUI();

            _mainView = new MainView(RxApp.TaskpoolScheduler, RxApp.MainThreadScheduler, ViewLocator.Current);
            var viewStackService = new ViewStackService(_mainView);

            Locator.CurrentMutable.RegisterConstant(viewStackService, typeof(IViewStackService));
            Locator.CurrentMutable.Register(() => new SignInPage(), typeof(IViewFor <ISignInViewModel>));
            Locator.CurrentMutable.Register(() => new PhoneAuthPhoneNumberEntryPage(), typeof(IViewFor <IPhoneAuthPhoneNumberEntryViewModel>));
            Locator.CurrentMutable.Register(() => new PhoneAuthVerificationCodeEntryPage(), typeof(IViewFor <IPhoneAuthVerificationCodeEntryViewModel>));
            Locator.CurrentMutable.Register(() => new MainPage(), typeof(IViewFor <IMainViewModel>));
            Locator.CurrentMutable.Register(() => new CatalogCategoryListPage(), typeof(IViewFor <ICatalogCategoryListViewModel>));
            Locator.CurrentMutable.Register(() => new CatalogCategoryCell(), typeof(IViewFor <ICatalogCategoryCellViewModel>));
            Locator.CurrentMutable.Register(() => new CatalogCategoryPage(), typeof(IViewFor <ICatalogCategoryViewModel>));
            Locator.CurrentMutable.Register(() => new CatalogItemCell(), typeof(IViewFor <ICatalogItemCellViewModel>));
            Locator.CurrentMutable.Register(() => new CatalogItemDetailsPage(), typeof(IViewFor <ICatalogItemDetailsViewModel>));
            Locator.CurrentMutable.Register(() => new StoreInfoPage(), typeof(IViewFor <IStoreInfoViewModel>));
            Locator.CurrentMutable.Register(() => new AlbumListPage(), typeof(IViewFor <IAlbumListViewModel>));
            Locator.CurrentMutable.Register(() => new AlbumCell(), typeof(IViewFor <IAlbumCellViewModel>));
            Locator.CurrentMutable.Register(() => new AlbumPage(), typeof(IViewFor <IAlbumViewModel>));
            Locator.CurrentMutable.Register(() => new RewardsPage(), typeof(IViewFor <IRewardsViewModel>));
            Locator.CurrentMutable.Register(() => new RewardsProgramActivationPage(), typeof(IViewFor <IRewardsProgramActivationViewModel>));

            Locator.CurrentMutable.Register(() => new AuthService(), typeof(IAuthService));
            IFirebaseAuthService firebaseAuthService = CrossFirebaseAuth.Current;

            Locator.CurrentMutable.RegisterConstant(firebaseAuthService, typeof(IFirebaseAuthService));
            Locator.CurrentMutable.RegisterLazySingleton(() => new FacebookPhotoService(), typeof(IFacebookPhotoService));

            var repoContainer = new RepositoryRegistrar(firebaseAuthService, Locator.CurrentMutable);

            //Square.Connect.Client.Configuration.Default.AccessToken = ApiKeys.SQUARE_CONNECT;

            //viewStackService.PushPage(new MainViewModel()).Subscribe();

            //return;

            if (firebaseAuthService.CurrentUser != null)
            {
                viewStackService.PushPage(new MainViewModel()).Subscribe();
            }
            else
            {
                viewStackService.PushPage(new SignInViewModel()).Subscribe();
            }
        }
コード例 #2
0
ファイル: RedViewModel.cs プロジェクト: rms81/Sextant
        public RedViewModel(IViewStackService viewStackService) : base(viewStackService)
        {
            PopModal = ReactiveCommand
                       .CreateFromObservable(() =>
                                             ViewStackService.PopModal(),
                                             outputScheduler: RxApp.MainThreadScheduler);

            PopPage = ReactiveCommand
                      .CreateFromObservable(() =>
                                            ViewStackService.PopPage(),
                                            outputScheduler: RxApp.MainThreadScheduler);

            PushPage = ReactiveCommand
                       .CreateFromObservable(() =>
                                             ViewStackService.PushPage(new RedViewModel(ViewStackService)),
                                             outputScheduler: RxApp.MainThreadScheduler);
            PopToRoot = ReactiveCommand
                        .CreateFromObservable(() =>
                                              ViewStackService.PopToRootPage(),
                                              outputScheduler: RxApp.MainThreadScheduler);

            PopModal.Subscribe(x => Debug.WriteLine("PagePushed"));
            PopModal.ThrownExceptions.Subscribe(error => Interactions.ErrorMessage.Handle(error).Subscribe());
            PopPage.ThrownExceptions.Subscribe(error => Interactions.ErrorMessage.Handle(error).Subscribe());
            PushPage.ThrownExceptions.Subscribe(error => Interactions.ErrorMessage.Handle(error).Subscribe());
            PopToRoot.ThrownExceptions.Subscribe(error => Interactions.ErrorMessage.Handle(error).Subscribe());
        }
コード例 #3
0
        public BackUpViewModel(List <string> seedWords)
            : base(Locator.Current.GetService <IViewStackService>())
        {
            Global    = Locator.Current.GetService <Global>();
            SeedWords = seedWords;

            IndexedWords = new string[SeedWords.Count()];
            for (int i = 0; i < SeedWords.Count(); i++)
            {
                IndexedWords[i] = $"{i+1}. {SeedWords[i]}";
            }

            VerifyCommand = ReactiveCommand.CreateFromObservable(() =>
            {
                if (Global.UiConfig.IsBackedUp)
                {
                    // pop back home
                    ViewStackService.PopPage();
                    ViewStackService.PopPage();
                }
                else
                {
                    // verify backup
                    ViewStackService.PushPage(new VerifyMnemonicViewModel(SeedWords, null)).Subscribe();
                }
                return(Observable.Return(Unit.Default));
            });
        }
コード例 #4
0
        public CatalogCategoryListViewModel(ICatalogCategoryRepo catalogCategoryRepo = null, IViewStackService viewStackService = null)
            : base(viewStackService)
        {
            catalogCategoryRepo = catalogCategoryRepo ?? Locator.Current.GetService <ICatalogCategoryRepo>();

            LoadCatalogCategories = ReactiveCommand.CreateFromObservable(
                () =>
            {
                return(catalogCategoryRepo.GetItems()
                       .SelectMany(x => x)
                       .Select(x => new CatalogCategoryCellViewModel(x) as ICatalogCategoryCellViewModel)
                       .ToList()
                       .Select(x => x as IReadOnlyList <ICatalogCategoryCellViewModel>)
                       .SubscribeOn(RxApp.TaskpoolScheduler));
            });

            _catalogCategories = LoadCatalogCategories
                                 .ToProperty(this, x => x.CatalogCategories, scheduler: RxApp.MainThreadScheduler);

            this
            .WhenAnyValue(vm => vm.SelectedItem)
            .Where(x => x != null)
            .SelectMany(x => ViewStackService.PushPage(new CatalogCategoryViewModel(x.Id)))
            .Subscribe();

            _isRefreshing = LoadCatalogCategories
                            .IsExecuting
                            .ToProperty(this, vm => vm.IsRefreshing, true);
        }
コード例 #5
0
        public static NavigationPage CreateMainView()
        {
            var mainView         = new MainView(RxApp.TaskpoolScheduler, RxApp.MainThreadScheduler, ViewLocator.Current);
            var viewStackService = new ViewStackService(mainView, Device.RuntimePlatform == Device.Android);

            Locator.CurrentMutable.RegisterConstant(viewStackService, typeof(IViewStackService));
            viewStackService.PushPage(new HomeViewModel(new FakeToyService())).Subscribe();
            return(mainView);
        }
コード例 #6
0
        public static IObservable <Unit> PushPage(this ViewStackService viewStackService, INavigable viewModel, string contract = null, int pages = 1)
        {
            for (var i = 0; i < pages; i++)
            {
                viewStackService.PushPage(viewModel, contract).Subscribe();
            }

            return(Observable.Return(Unit.Default));
        }
コード例 #7
0
        public WalletInfoViewModel(KeyManager keyManager) : base(Locator.Current.GetService <IViewStackService>())
        {
            Global      = Locator.Current.GetService <Global>();
            _keyManager = keyManager;

            Disposables = Disposables is null ? new CompositeDisposable() : throw new NotSupportedException($"Cannot open {GetType().Name} before closing it.");

            Closing = new CancellationTokenSource();

            Closing.DisposeWith(Disposables);

            ClearSensitiveData(true);

            // TODO turn bool
            ToggleSensitiveKeysCommand = ReactiveCommand.Create <Unit, bool>(_ =>
            {
                try
                {
                    if (ShowSensitiveKeys)
                    {
                        ClearSensitiveData(true);
                    }
                    else
                    {
                        var secret = PasswordHelper.GetMasterExtKey(_keyManager, Password, out string isCompatibilityPasswordUsed);
                        Password   = "";

                        //if (isCompatibilityPasswordUsed != null)
                        //{
                        //	SetWarningMessage(PasswordHelper.CompatibilityPasswordWarnMessage);
                        //}

                        string master   = secret.GetWif(Global.Network).ToWif();
                        string account  = secret.Derive(_keyManager.AccountKeyPath).GetWif(Global.Network).ToWif();
                        string masterZ  = secret.ToZPrv(Global.Network);
                        string accountZ = secret.Derive(_keyManager.AccountKeyPath).ToZPrv(Global.Network);
                        SetSensitiveData(master, account, masterZ, accountZ);
                    }
                    return(true);
                }
                catch (Exception ex)
                {
                    return(false);
                }
            });

            var canBackUp = this.WhenAnyValue(x => x.Global.UiConfig.HasSeed, hs => hs == true);

            NavBackUpCommand = ReactiveCommand.CreateFromObservable(() =>
            {
                ViewStackService.PushPage(new StartBackUpViewModel()).Subscribe();
                return(Observable.Return(Unit.Default));
            }, canBackUp);

            ShareLogsCommand    = ReactiveCommand.CreateFromTask(ShareLogs);
            ExportWalletCommand = ReactiveCommand.CreateFromTask(ExportWallet);
        }
コード例 #8
0
 private IObservable <Unit> HandleResult(AuthAction authAction, PhoneNumberSignInResult result, IObservable <Unit> completionObservable)
 {
     if (result.AuthResult != null)
     {
         return(completionObservable);
     }
     else
     {
         return(ViewStackService.PushPage(new PhoneAuthVerificationCodeEntryViewModel(authAction, result.VerificationId, completionObservable)));
     }
 }
コード例 #9
0
        public void Should_InvokeViewShellPushPage_When_PushPageIsInvoked(string contract, bool resetStack, bool animate)
        {
            // Arrange
            var sut = new ViewStackService(_viewShell);

            // Act
            sut.PushPage(_page, contract, resetStack, animate).Subscribe();

            // Assert
            _viewShell.Received(1).PushPage(_page, contract, resetStack, animate);
        }
コード例 #10
0
        public void Should_AddViewModelToPageStack_When_Pushed()
        {
            // Arrange
            var sut = new ViewStackService(_viewShell);

            // Act
            sut.PushPage(_page).Subscribe();

            // Assert
            sut.PageStack.FirstAsync().Wait().Count.Should().Be(1);
        }
コード例 #11
0
        public RewardsProgramActivationViewModel(IFirebaseAuthService firebaseAuthService = null, IViewStackService viewStackService = null)
            : base(viewStackService)
        {
            _firebaseAuthService = firebaseAuthService ?? Locator.Current.GetService <IFirebaseAuthService>();

            NavigateToPhoneNumberVerificationPage = ReactiveCommand.CreateFromObservable(
                () =>
            {
                return(ViewStackService
                       .PushPage(new PhoneAuthPhoneNumberEntryViewModel(AuthAction.LinkAccount, WhenLinked())));
            });
        }
コード例 #12
0
ファイル: MainViewModel.cs プロジェクト: cabauman/SSBakery
        public MainViewModel(IFirebaseAuthService authService = null, IViewStackService viewStackService = null)
            : base(viewStackService)
        {
            _authService = authService ?? Locator.Current.GetService <IFirebaseAuthService>();

            NavigateToCatalogPage = ReactiveCommand.CreateFromObservable(
                () =>
            {
                return(ViewStackService.PushPage(new CatalogCategoryListViewModel()));
            });
            NavigateToAlbumPage = ReactiveCommand.CreateFromObservable(
                () =>
            {
                return(ViewStackService.PushPage(new AlbumListViewModel()));
            });
            NavigateToStoreInfoPage = ReactiveCommand.CreateFromObservable(
                () =>
            {
                return(ViewStackService.PushPage(new StoreInfoViewModel()));
            });

            if (_authService.CurrentUser.Providers.Contains("phone"))
            {
                NavigateToRewardsPage = ReactiveCommand.CreateFromObservable(
                    () =>
                {
                    return(ViewStackService.PushPage(new RewardsViewModel()));
                });
            }
            else
            {
                NavigateToRewardsPage = ReactiveCommand.CreateFromObservable(
                    () =>
                {
                    return(ViewStackService.PushPage(new RewardsProgramActivationViewModel()));
                });
            }

            this.WhenActivated(
                d =>
            {
                Disposable.Empty.DisposeWith(d);
            });

            NavigateToCatalogPage.ThrownExceptions.Subscribe(
                ex =>
            {
                System.Console.WriteLine(ex.Message);
            });
        }
コード例 #13
0
        public LandingViewModel()
            : base(Locator.Current.GetService <IViewStackService>())
        {
            NewWalletCommand = ReactiveCommand.CreateFromObservable(() =>
            {
                ViewStackService.PushPage(new NewPasswordViewModel()).Subscribe();
                return(Observable.Return(Unit.Default));
            });

            LoadWalletCommand = ReactiveCommand.CreateFromObservable(() =>
            {
                ViewStackService.PushPage(new LoadWalletViewModel()).Subscribe();
                return(Observable.Return(Unit.Default));
            });
        }
コード例 #14
0
        public HomeViewModel(IViewStackService viewStackService)
            : base(viewStackService)
        {
            OpenModal = ReactiveCommand
                        .CreateFromObservable(() =>
                                              ViewStackService.PushModal(new FirstModalViewModel(ViewStackService)),
                                              outputScheduler: RxApp.MainThreadScheduler);

            PushPage = ReactiveCommand
                       .CreateFromObservable(() =>
                                             ViewStackService.PushPage(new RedViewModel(ViewStackService)),
                                             outputScheduler: RxApp.MainThreadScheduler);

            OpenModal.Subscribe(x => Debug.WriteLine("PagePushed"));
        }
コード例 #15
0
        public AppBootstrapper()
        {
            RegisterServices();
            RegisterViews();

            IViewShell mainView = new ViewShell(RxApp.TaskpoolScheduler, RxApp.MainThreadScheduler, new ReactiveUIViewLocator());

            _navigationPage = mainView as Xamarin.Forms.NavigationPage;
            IViewStackService viewStackService = new ViewStackService(mainView);

            Locator.CurrentMutable.RegisterConstant(viewStackService, typeof(IViewStackService));

            viewStackService
            .PushPage(new LoginViewModel(viewStackService))
            .Subscribe();
        }
コード例 #16
0
        public StartBackUpViewModel()
            : base(Locator.Current.GetService <IViewStackService>())
        {
            Global = Locator.Current.GetService <Global>();
            var hsm = Locator.Current.GetService <IHsmStorage>();

            NextCommand = ReactiveCommand.CreateFromObservable(() =>
            {
                List <string> seedWords = hsm.GetAsync($"{Global.Network}-seedWords").Result?.Split(' ').ToList();
                if (seedWords != null)
                {
                    ViewStackService.PushPage(new BackUpViewModel(seedWords)).Subscribe();
                }
                return(Observable.Return(Unit.Default));
            });
        }
コード例 #17
0
        // <param name="isFinal">
        // we verify 2 words, isFinal -> we verified 1 word already
        // </param>
        public VerifyMnemonicViewModel(List <string> seedWords, string previouslyVerified)
            : base(Locator.Current.GetService <IViewStackService>())
        {
            Global    = Locator.Current.GetService <Global>();
            SeedWords = seedWords;

            while (WordToVerify == null || WordToVerify == previouslyVerified)
            {
                // "random" check words were written. no need for CSPRNG
                WordToVerify = seedWords.RandomElement();
            }

            IndexToVerify = seedWords.IndexOf(WordToVerify);

            VerifiedCommand = ReactiveCommand.CreateFromObservable(() =>
            {
                if (previouslyVerified != null)
                {
                    Global.UiConfig.IsBackedUp = true;
                    Global.UiConfig.ToFile();                     // successfully backed up!
                    ViewStackService.PopPage(false);              // this
                    ViewStackService.PopPage(false);              // previouslyVerified
                    ViewStackService.PopPage(false);
                    ViewStackService.PopPage();                   // words
                }
                else
                {
                    ViewStackService.PushPage(new VerifyMnemonicViewModel(seedWords, WordToVerify)).Subscribe();
                }
                return(Observable.Return(Unit.Default));
            });

            FailedCommand = ReactiveCommand.CreateFromObservable(() =>
            {
                ViewStackService.PopPage(false);                  // this
                if (previouslyVerified != null)
                {
                    ViewStackService.PopPage(false);                  // previouslyVerified
                }
                return(Observable.Return(Unit.Default));
            });
        }
コード例 #18
0
        public NewPasswordViewModel()
            : base(Locator.Current.GetService <IViewStackService>())
        {
            Global = Locator.Current.GetService <Global>();
            Hsm    = Locator.Current.GetService <IHsmStorage>();

            SubmitCommand = ReactiveCommand.CreateFromObservable(() =>
            {
                PasswordHelper.Guard(Password);                 // Here we are not letting anything that will be autocorrected later. We need to generate the wallet exactly with the entered password bacause of compatibility.

                string walletFilePath = Path.Combine(Global.WalletManager.WalletDirectories.WalletsDir, $"{Global.Network}.json");
                KeyManager.CreateNew(out Mnemonic seedWords, Password, walletFilePath);

                Hsm.SetAsync($"{Global.Network}-seedWords", seedWords.ToString());                 // PROMPT
                Global.UiConfig.HasSeed = true;
                Global.UiConfig.ToFile();
                ViewStackService.PushPage(new MainViewModel()).Subscribe();
                return(Observable.Return(Unit.Default));
            });
        }
コード例 #19
0
        public SendWhoViewModel(SendAmountViewModel savm)
            : base(Locator.Current.GetService <IViewStackService>())
        {
            Global  = Locator.Current.GetService <Global>();
            Memo    = "";
            Address = "";

            SendAmountViewModel = savm;

            var canPromptPassword = this.WhenAnyValue(x => x.Memo, x => x.Address, x => x.IsBusy,
                                                      (memo, addr, isBusy) =>
            {
                BitcoinAddress address;
                try
                {
                    address = BitcoinAddress.Create(addr.Trim(), Global.Network);
                }
                catch (FormatException)
                {
                    // SetWarningMessage("Invalid address.");
                    return(false);
                }
                return(!isBusy && memo.Length > 0 && address is BitcoinAddress);
            });

            _promptViewModel = new PasswordPromptViewModel("SEND");
            _promptViewModel.ValidatePasswordCommand.Subscribe(async validPassword =>
            {
                if (validPassword != null)
                {
                    await ViewStackService.PopModal();
                    await BuildTransaction(validPassword);
                    await ViewStackService.PushPage(new SentViewModel());
                }
            });
            PromptCommand = ReactiveCommand.CreateFromObservable(() =>
            {
                ViewStackService.PushModal(_promptViewModel).Subscribe();
                return(Observable.Return(Unit.Default));
            }, canPromptPassword);
        }
コード例 #20
0
        public HomeViewModel()
            : base(Locator.Current.GetService <IViewStackService>())
        {
            OpenModal = ReactiveCommand
                        .CreateFromObservable(() =>
                                              ViewStackService.PushModal(new FirstModalViewModel(ViewStackService)),
                                              outputScheduler: RxApp.MainThreadScheduler);

            PushPage = ReactiveCommand
                       .CreateFromObservable(() =>
                                             ViewStackService.PushPage(new RedViewModel(ViewStackService)),
                                             outputScheduler: RxApp.MainThreadScheduler);

            PushGenericPage = ReactiveCommand
                              .CreateFromObservable(() =>
                                                    ViewStackService.PushPage <GreenViewModel>(),
                                                    outputScheduler: RxApp.MainThreadScheduler);

            PushPage.ThrownExceptions.Subscribe(error => Interactions.ErrorMessage.Handle(error).Subscribe());
            PushGenericPage.ThrownExceptions.Subscribe(error => Interactions.ErrorMessage.Handle(error).Subscribe());
            OpenModal.ThrownExceptions.Subscribe(error => Interactions.ErrorMessage.Handle(error).Subscribe());
        }
コード例 #21
0
ファイル: AppDelegate.cs プロジェクト: cabauman/RxNavigation
        public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            // Override point for customization after application launch.
            // If not required for your application you can safely delete this method

            Window = new UIWindow(UIScreen.MainScreen.Bounds);

            Locator.CurrentMutable.InitializeSplat();
            Locator.CurrentMutable.InitializeReactiveUI();

            Locator.CurrentMutable.Register(() => new HomeViewController(), typeof(IViewFor <HomeViewModel>));

            IViewShell        mainView         = new ViewShell(RxApp.TaskpoolScheduler, RxApp.MainThreadScheduler, ViewLocator.Current);
            IViewStackService viewStackService = new ViewStackService(mainView);

            viewStackService.PushPage(new HomeViewModel(viewStackService)).Subscribe();
            Locator.CurrentMutable.RegisterConstant(viewStackService, typeof(IViewStackService));

            Window.RootViewController = mainView as UIViewController;
            Window.MakeKeyAndVisible();

            return(true);
        }
コード例 #22
0
        public LoginViewModel(IViewStackService viewStackService)
            : base(viewStackService)
        {
            var canSignIn = this.WhenAnyValue(
                vm => vm.Email,
                vm => vm.Password,
                (email, password) => !string.IsNullOrEmpty(email) && !string.IsNullOrEmpty(password));

            SignIn = ReactiveCommand.CreateFromObservable(
                () =>
            {
                return(Observable
                       .Timer(TimeSpan.FromSeconds(1))
                       .SelectMany(_ => ViewStackService.PushPage(new HomeViewModel(ViewStackService), null, true))
                       .TakeUntil(Cancel));
            },
                canSignIn);

            SignIn
            .ThrownExceptions
            .Subscribe(
                x =>
            {
                System.Console.WriteLine(x);
            });

            var canCancel = SignIn.IsExecuting;

            Cancel = ReactiveCommand.CreateFromObservable(
                () =>
            {
                return(Observable
                       .Return(Unit.Default));
            },
                canCancel);
        }
コード例 #23
0
        //public ICatalogItemCellViewModel ItemAppearing
        //{
        //    get { return _itemAppearing; }
        //    set { this.RaiseAndSetIfChanged(ref _itemAppearing, value); }
        //}

        private IObservable <Unit> LoadSelectedPage(ICatalogItemCellViewModel viewModel)
        {
            return(ViewStackService.PushPage(new CatalogItemDetailsViewModel(viewModel.CatalogItem)));
        }
コード例 #24
0
        public MainViewModel()
            : base(Locator.Current.GetService <IViewStackService>())
        {
            Global = Locator.Current.GetService <Global>();
            Global.SetDefaultWallet();
            Task.Run(async() => await App.LoadWalletAsync());

            ShowWalletInfoCommand = ReactiveCommand.CreateFromObservable(() =>
            {
                ViewStackService.PushPage(new WalletInfoViewModel(Global.Wallet.KeyManager)).Subscribe();
                return(Observable.Return(Unit.Default));
            });

            if (Disposables != null)
            {
                throw new Exception("Wallet opened before it was closed.");
            }

            // init with UI config
            Balance = Global.UiConfig.Balance;

            Transactions = new ObservableCollection <TransactionViewModel>();

            OpenTransactionDetail = ReactiveCommand.CreateFromObservable((TransactionViewModel tvm) =>
            {
                ViewStackService.PushPage(tvm).Subscribe();
                return(Observable.Return(Unit.Default));
            });

            TryWriteTableFromCache();

            Initializing += OnInit;
            Initializing(this, EventArgs.Empty);

            StatusViewModel = new StatusViewModel();

            var coinListReady = this.WhenAnyValue(x => x.CoinList.IsCoinListLoading,
                                                  stillLoading => !stillLoading);

            _hasSeed = this.WhenAnyValue(x => x.Global.UiConfig.HasSeed)
                       .ToProperty(this, nameof(HasSeed));

            _isBackedUp = this.WhenAnyValue(x => x.Global.UiConfig.IsBackedUp)
                          .ToProperty(this, nameof(IsBackedUp));

            var canBackUp = this.WhenAnyValue(x => x.HasSeed, x => x.IsBackedUp,
                                              (hasSeed, isBackedUp) => hasSeed && !isBackedUp);

            canBackUp.ToProperty(this, x => x.CanBackUp, out _canBackUp);

            NavBackUpCommand = ReactiveCommand.CreateFromObservable(() =>
            {
                ViewStackService.PushPage(new StartBackUpViewModel()).Subscribe();
                return(Observable.Return(Unit.Default));
            }, canBackUp);

            NavReceiveCommand = ReactiveCommand.CreateFromObservable(() =>
            {
                ViewStackService.PushPage(new ReceiveViewModel()).Subscribe();
                return(Observable.Return(Unit.Default));
            });

            InitCoinJoin = ReactiveCommand.CreateFromObservable(() =>
            {
                CoinList.SelectOnlyPrivateCoins(false);
                ViewStackService.PushPage(CoinJoinViewModel).Subscribe();
                return(Observable.Return(Unit.Default));
            }, coinListReady);

            SendCommand = ReactiveCommand.CreateFromObservable(() =>
            {
                CoinList.SelectOnlyPrivateCoins(true);
                ViewStackService.PushPage(SendAmountViewModel).Subscribe();
                return(Observable.Return(Unit.Default));
            }, coinListReady);

            _hasCoins = this
                        .WhenAnyValue(x => x.Balance)
                        .Select(bal => Money.Parse(bal) > 0)
                        .ToProperty(this, nameof(HasCoins));
        }
コード例 #25
0
 private IObservable <Unit> LoadSelectedPage(AlbumCellViewModel viewModel)
 {
     return(ViewStackService.PushPage(new AlbumViewModel(viewModel.FacebookAlbum.Id)));
 }
コード例 #26
0
        public HomeViewModel(IViewStackService viewStackService)
            : base(viewStackService)
        {
            PushPage = ReactiveCommand.CreateFromObservable(
                () =>
            {
                return(ViewStackService.PushPage(new HomeViewModel(ViewStackService)));
            });

            PushModalWithNav = ReactiveCommand.CreateFromObservable(
                () =>
            {
                return(ViewStackService.PushModal(new NavigationPageViewModel(new HomeViewModel(ViewStackService))));
            });

            PushModalWithoutNav = ReactiveCommand.CreateFromObservable(
                () =>
            {
                return(ViewStackService.PushModal(new HomeViewModel(ViewStackService)));
            });

            PopModal = ReactiveCommand.CreateFromObservable(
                () =>
            {
                return(ViewStackService.PopModal());
            });

            var canPop = this.WhenAnyValue(
                vm => vm.PopCount,
                vm => vm.PageCount,
                (popCount, pageCount) => popCount > 0 && popCount < pageCount);

            PopPages = ReactiveCommand.CreateFromObservable(
                () =>
            {
                return(ViewStackService
                       .PopPages(_popCount ?? 0, true));
            },
                canPop);

            var canPopToNewPage = this.WhenAnyValue(
                vm => vm.PageIndex,
                pageIndex => pageIndex >= 0 && pageIndex < PageCount);

            PopToNewPage = ReactiveCommand.CreateFromObservable(
                () =>
            {
                return(Observable
                       .Start(() => ViewStackService.InsertPage(PageIndex ?? 0, new LoginViewModel(ViewStackService)), RxApp.MainThreadScheduler)
                       .SelectMany(_ => ViewStackService.PopToPage(PageIndex ?? 0)));
            },
                canPopToNewPage);

            this.WhenActivated(
                disposables =>
            {
                _pageCount = ViewStackService
                             .PageStack
                             .Select(
                    x =>
                {
                    return(x != null ? x.Count : 0);
                })
                             .ToProperty(this, vm => vm.PageCount, default(int), false, RxApp.MainThreadScheduler)
                             .DisposeWith(disposables);
            });
        }
コード例 #27
0
        public SendAmountViewModel(CoinListViewModel coinList)
            : base(Locator.Current.GetService <IViewStackService>())
        {
            Global            = Locator.Current.GetService <Global>();
            CoinList          = coinList;
            AmountText        = "0.0";
            AllSelectedAmount = Money.Zero;
            EstimatedBtcFee   = Money.Zero;

            this.WhenAnyValue(x => x.AmountText)
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(amount =>
            {
                // Correct amount
                if (IsMax)
                {
                    SetAmountIfMax();
                }
                else
                {
                    Regex digitsOnly    = new Regex(@"[^\d,.]");
                    string betterAmount = digitsOnly.Replace(amount, "");     // Make it digits , and . only.

                    betterAmount          = betterAmount.Replace(',', '.');
                    int countBetterAmount = betterAmount.Count(x => x == '.');
                    if (countBetterAmount > 1)     // Do not enable typing two dots.
                    {
                        var index = betterAmount.IndexOf('.', betterAmount.IndexOf('.') + 1);
                        if (index > 0)
                        {
                            betterAmount = betterAmount.Substring(0, index);
                        }
                    }
                    var dotIndex = betterAmount.IndexOf('.');
                    if (dotIndex != -1 && betterAmount.Length - dotIndex > 8)     // Enable max 8 decimals.
                    {
                        betterAmount = betterAmount.Substring(0, dotIndex + 1 + 8);
                    }

                    if (betterAmount != amount)
                    {
                        AmountText = betterAmount;
                    }
                }
            });

            _sendFromText = this
                            .WhenAnyValue(x => x.CoinList.SelectPrivateSwitchState, x => x.CoinList.SelectedCount)
                            .Select(tup =>
            {
                var coinGrammaticalNumber = tup.Item2 == 1 ? " Coin ▾" : " Coins ▾";
                return(tup.Item1 ? "Auto-Select Private ▾" : (tup.Item2.ToString() + coinGrammaticalNumber));
            })
                            .ToProperty(this, nameof(SendFromText));

            this.WhenAnyValue(x => x.IsMax)
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(isMax =>
            {
                if (isMax)
                {
                    SetAmountIfMax();
                }
            });

            Observable.FromEventPattern(CoinList, nameof(CoinList.SelectionChanged))
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(_ => SetFees());

            _minMaxFeeTargetsEqual = this.WhenAnyValue(x => x.MinimumFeeTarget, x => x.MaximumFeeTarget, (x, y) => x == y)
                                     .ToProperty(this, x => x.MinMaxFeeTargetsEqual, scheduler: RxApp.MainThreadScheduler);

            SetFeeTargetLimits();
            FeeTarget = Global.UiConfig.FeeTarget;
            FeeRate   = new FeeRate((decimal)50); //50 sat/vByte placeholder til loads
            SetFees();

            Observable
            .FromEventPattern <AllFeeEstimate>(Global.FeeProviders, nameof(Global.FeeProviders.AllFeeEstimateChanged))
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(_ =>
            {
                SetFeeTargetLimits();

                if (FeeTarget < MinimumFeeTarget)     // Should never happen.
                {
                    FeeTarget = MinimumFeeTarget;
                }
                else if (FeeTarget > MaximumFeeTarget)
                {
                    FeeTarget = MaximumFeeTarget;
                }

                SetFees();
            })
            .DisposeWith(Disposables);

            GoNext = ReactiveCommand.CreateFromObservable(() =>
            {
                ViewStackService.PushPage(new SendWhoViewModel(this)).Subscribe();
                return(Observable.Return(Unit.Default));
            }, this.WhenAnyValue(
                                                              x => x.AmountText,
                                                              x => x.CoinList.SelectedAmount,
                                                              (amountToSpend, selectedAmount) =>
            {
                return(AmountTextPositive(amountToSpend) &&
                       Money.Parse(amountToSpend.TrimStart('~', ' ')) + EstimatedBtcFee <= selectedAmount);
            }));

            SelectCoins = ReactiveCommand.CreateFromObservable(() =>
            {
                ViewStackService.PushModal(CoinList).Subscribe();
                return(Observable.Return(Unit.Default));
            });

            SelectFee = ReactiveCommand.CreateFromObservable(() =>
            {
                ViewStackService.PushModal(new FeeViewModel(this)).Subscribe();
                return(Observable.Return(Unit.Default));
            });

            this.WhenAnyValue(x => x.FeeTarget)
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(_ =>
            {
                SetFees();
            });
        }
コード例 #28
0
 private IObservable <Unit> ExecuteNavigate() => ViewStackService.PushPage(new BottomMenuViewModel(ViewStackService), resetStack: true);
コード例 #29
0
        public SignInViewModel(IAuthService authService = null, IFirebaseAuthService firebaseAuthService = null, IViewStackService viewStackService = null)
            : base(viewStackService)
        {
            _firebaseAuthService = firebaseAuthService ?? Locator.Current.GetService <IFirebaseAuthService>();
            authService          = authService ?? Locator.Current.GetService <IAuthService>();

            ContinueAsGuest = ReactiveCommand.CreateFromObservable(
                () =>
            {
                return(_firebaseAuthService
                       .SignInAnonymously()
                       .SelectMany(_ => ViewStackService.PushPage(new MainViewModel())));
            });

            ContinueAsGuest.ThrownExceptions.Subscribe(
                ex =>
            {
                Console.WriteLine(ex);
            });

            NavigateToPhoneNumberVerificationPage = ReactiveCommand.CreateFromObservable(
                () =>
            {
                IObservable <Unit> whenSignedIn = Observable
                                                  .Defer(
                    () =>
                {
                    return(ViewStackService
                           .PushPage(new MainViewModel(), null, true));
                });

                return(ViewStackService
                       .PushPage(new PhoneAuthPhoneNumberEntryViewModel(AuthAction.SignIn, whenSignedIn)));
            });

            TriggerGoogleAuthFlow = ReactiveCommand.Create(
                () =>
            {
                _provider = "google";
                authService.TriggerGoogleAuthFlow(
                    Config.GoogleAuthConfig.CLIENT_ID_ANDROID,
                    null,
                    Config.GoogleAuthConfig.SCOPE,
                    Config.GoogleAuthConfig.AUTHORIZE_URL,
                    Config.GoogleAuthConfig.REDIRECT_URL_ANDROID,
                    Config.GoogleAuthConfig.ACCESS_TOKEN_URL);
            });

            TriggerGoogleAuthFlow.ThrownExceptions.Subscribe(
                ex =>
            {
                this.Log().Debug(ex);
            });

            TriggerFacebookAuthFlow = ReactiveCommand.Create(
                () =>
            {
                _provider = "facebook";
                authService.TriggerFacebookAuthFlow(
                    Config.FacebookAuthConfig.CLIENT_ID,
                    null,
                    Config.FacebookAuthConfig.SCOPE,
                    Config.FacebookAuthConfig.AUTHORIZE_URL,
                    Config.FacebookAuthConfig.REDIRECT_URL,
                    string.Empty);
            });

            TriggerFacebookAuthFlow.ThrownExceptions.Subscribe(
                ex =>
            {
                this.Log().Debug(ex);
            });

            authService.SignInSuccessful
            .SelectMany(authToken => AuthenticateWithFirebase(authToken))
            .SelectMany(_ => ViewStackService.PushPage(new MainViewModel(), null, true))
            .Subscribe();

            authService.SignInCanceled
            .Subscribe(
                x =>
            {
                this.Log().Debug("");
            },
                ex => this.Log().Debug(""),
                () =>
            {
                this.Log().Debug("");
            });

            authService.SignInFailed
            .Subscribe(
                x =>
            {
                this.Log().Debug("");
            });
        }