Ejemplo n.º 1
0
        public object CreateWallet(string walletName, string password)
        {
            var walletGenerator = new WalletGenerator(Global.WalletsDir, Global.Network);

            walletGenerator.TipHeight = Global.BitcoinStore.SmartHeaderChain.TipHeight;
            var(keyManager, mnemonic) = walletGenerator.GenerateWallet(walletName, password);
            keyManager.ToFile();
            return(mnemonic.ToString());
        }
Ejemplo n.º 2
0
        public AddWalletPageViewModel(
            LegalDocuments legalDocuments,
            WalletManager walletManager,
            BitcoinStore store,
            Network network)
        {
            Title           = "Add Wallet";
            SelectionMode   = NavBarItemSelectionMode.Button;
            _legalDocuments = legalDocuments;

            this.WhenAnyValue(x => x.WalletName)
            .ObserveOn(RxApp.MainThreadScheduler)
            .Select(x => !string.IsNullOrWhiteSpace(x))
            .Subscribe(x => OptionsEnabled = x && !Validations.Any);

            RecoverWalletCommand = ReactiveCommand.Create(
                () => { Navigate().To(new RecoverWalletViewModel(WalletName, network, walletManager)); });

            ImportWalletCommand = ReactiveCommand.Create(() => new ImportWalletViewModel(WalletName, walletManager));

            ConnectHardwareWalletCommand = ReactiveCommand.Create(() =>
            {
                Navigate().To(new ConnectHardwareWalletViewModel(WalletName, network, walletManager));
            });

            CreateWalletCommand = ReactiveCommand.CreateFromTask(
                async() =>
            {
                var result = await NavigateDialog(
                    new EnterPasswordViewModel("Type the password of the wallet and click Continue."));

                if (result is { } password)
                {
                    IsBusy = true;

                    var(km, mnemonic) = await Task.Run(
                        () =>
                    {
                        var walletGenerator = new WalletGenerator(
                            walletManager.WalletDirectories.WalletsDir,
                            network)
                        {
                            TipHeight = store.SmartHeaderChain.TipHeight
                        };
                        return(walletGenerator.GenerateWallet(WalletName, password));
                    });

                    Navigate().To(new RecoveryWordsViewModel(km, mnemonic, walletManager), NavigationMode.Clear);

                    IsBusy = false;
                }
            });

            this.ValidateProperty(x => x.WalletName, errors => ValidateWalletName(errors, walletManager, WalletName));
        }
 private void DoNextCommand()
 {
     try
     {
         var walletGenerator = new WalletGenerator(Global.WalletManager.WalletDirectories.WalletsDir, Global.Network);
         walletGenerator.TipHeight = Global.BitcoinStore.SmartHeaderChain.TipHeight;
         var(km, mnemonic)         = walletGenerator.GenerateWallet(WalletName, Password);
         Owner.CurrentView         = new GenerateWalletSuccessViewModel(Owner, km, mnemonic);
     }
     catch (Exception ex)
     {
         Logger.LogError(ex);
         NotificationHelpers.Error(ex.ToUserFriendlyString());
     }
 }
Ejemplo n.º 4
0
        public AddWalletPageViewModel(NavigationStateViewModel navigationState, WalletManager walletManager,
                                      BitcoinStore store, Network network) : base(navigationState, NavigationTarget.DialogScreen)
        {
            Title = "Add Wallet";

            this.WhenAnyValue(x => x.WalletName)
            .Select(x => !string.IsNullOrWhiteSpace(x))
            .Subscribe(x => OptionsEnabled = x && !Validations.Any);

            RecoverWalletCommand = ReactiveCommand.CreateFromTask(async() =>
            {
                NavigateTo(new RecoverWalletViewModel(navigationState, WalletName, network, walletManager), NavigationTarget.DialogScreen);
            });

            CreateWalletCommand = ReactiveCommand.CreateFromTask(
                async() =>
            {
                var enterPassword = new EnterPasswordViewModel(
                    navigationState,
                    NavigationTarget.DialogScreen,
                    "Type the password of the wallet and click Continue.");

                NavigateTo(enterPassword, NavigationTarget.DialogScreen);

                var result = await enterPassword.GetDialogResultAsync();

                if (result is { } password)
                {
                    var(km, mnemonic) = await Task.Run(
                        () =>
                    {
                        var walletGenerator = new WalletGenerator(
                            walletManager.WalletDirectories.WalletsDir,
                            network)
                        {
                            TipHeight = store.SmartHeaderChain.TipHeight
                        };
                        return(walletGenerator.GenerateWallet(WalletName, password));
                    });

                    NavigateTo(new RecoveryWordsViewModel(navigationState, km, mnemonic, walletManager), NavigationTarget.DialogScreen, true);
                }
Ejemplo n.º 5
0
        private async Task OnCreateWallet(WalletManager walletManager, BitcoinStore store, Network network)
        {
            var dialogResult = await NavigateDialog(
                new CreatePasswordDialogViewModel("Type the password of the wallet and click Continue."));

            if (dialogResult.Result is { } password)
            {
                var(km, mnemonic) = await Task.Run(
                    () =>
                {
                    var walletGenerator = new WalletGenerator(
                        walletManager.WalletDirectories.WalletsDir,
                        network)
                    {
                        TipHeight = store.SmartHeaderChain.TipHeight
                    };
                    return(walletGenerator.GenerateWallet(WalletName, password));
                });

                Navigate().To(new RecoveryWordsViewModel(km, mnemonic, walletManager));
            }
        }
        private async Task OnCreateWalletAsync(string walletName)
        {
            var dialogResult = await NavigateDialogAsync(
                new CreatePasswordDialogViewModel("Type the password of the wallet and click Continue.", enableEmpty : true, enableCancel : Services.WalletManager.HasWallet()));

            if (dialogResult.Result is { } password)
            {
                var(km, mnemonic) = await Task.Run(
                    () =>
                {
                    var walletGenerator = new WalletGenerator(
                        Services.WalletManager.WalletDirectories.WalletsDir,
                        Services.WalletManager.Network)
                    {
                        TipHeight = Services.BitcoinStore.SmartHeaderChain.TipHeight
                    };
                    return(walletGenerator.GenerateWallet(walletName, password));
                });

                Navigate().To(new RecoveryWordsViewModel(km, mnemonic));
            }
        }
        public AddWalletPageViewModel(IScreen screen, WalletManager walletManager, BitcoinStore store, Network network) : base(screen)
        {
            Title = "Add Wallet";

            this.WhenAnyValue(x => x.WalletName)
            .Select(x => !string.IsNullOrWhiteSpace(x))
            .Subscribe(x => OptionsEnabled = x);

            RecoverWalletCommand = ReactiveCommand.Create(() => screen.Router.Navigate.Execute(new RecoveryPageViewModel(screen)));

            CreateWalletCommand = ReactiveCommand.CreateFromTask(
                async() =>
            {
                var result = await PasswordInteraction.Handle("").ToTask();

                if (result is { } password)
                {
                    var(km, mnemonic) = await Task.Run(
                        () =>
                    {
                        var walletGenerator = new WalletGenerator(walletManager.WalletDirectories.WalletsDir, network)
                        {
                            TipHeight = store.SmartHeaderChain.TipHeight
                        };
                        return(walletGenerator.GenerateWallet(WalletName, password));
                    });

                    await screen.Router.Navigate.Execute(
                        new RecoveryWordsViewModel(screen, km, mnemonic, walletManager));
                }
            });

            PasswordInteraction = new Interaction <string, string?>();
            PasswordInteraction.RegisterHandler(
                async interaction => interaction.SetOutput(await new EnterPasswordViewModel().ShowDialogAsync()));
        }
Ejemplo n.º 8
0
        public AddWalletPageViewModel(
            WalletManagerViewModel walletManagerViewModel,
            BitcoinStore store)
        {
            Title         = "Add Wallet";
            SelectionMode = NavBarItemSelectionMode.Button;
            var walletManager = walletManagerViewModel.Model;
            var network       = walletManager.Network;

            var enableBack = default(IDisposable);

            this.WhenAnyValue(x => x.CurrentTarget)
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(x =>
            {
                enableBack?.Dispose();
                enableBack = Navigate()
                             .WhenAnyValue(y => y.CanNavigateBack)
                             .Subscribe(y => EnableBack = y);
            });

            this.WhenAnyValue(x => x.WalletName)
            .ObserveOn(RxApp.MainThreadScheduler)
            .Select(x => !string.IsNullOrWhiteSpace(x))
            .Subscribe(x => OptionsEnabled = x && !Validations.Any);

            RecoverWalletCommand = ReactiveCommand.Create(
                () => Navigate().To(new RecoverWalletViewModel(WalletName, walletManagerViewModel)));

            ImportWalletCommand = ReactiveCommand.CreateFromTask(async() =>
            {
                try
                {
                    var filePath = await FileDialogHelper.ShowOpenFileDialogAsync("Import wallet file", new[] { "json" });

                    if (filePath is null)
                    {
                        return;
                    }

                    var keyManager = await ImportWalletHelper.ImportWalletAsync(walletManager, WalletName, filePath);

                    // TODO: get the type from the wallet file
                    Navigate().To(new AddedWalletPageViewModel(walletManager, keyManager));
                }
                catch (Exception ex)
                {
                    Logger.LogError(ex);
                    await ShowErrorAsync(ex.ToUserFriendlyString(), "The wallet file was not valid or compatible with Wasabi.");
                }
            });

            ConnectHardwareWalletCommand = ReactiveCommand.Create(() => Navigate().To(new ConnectHardwareWalletViewModel(WalletName, walletManagerViewModel)));

            CreateWalletCommand = ReactiveCommand.CreateFromTask(
                async() =>
            {
                var dialogResult = await NavigateDialog(
                    new EnterPasswordViewModel("Type the password of the wallet and click Continue."));

                if (dialogResult.Result is { } password)
                {
                    var(km, mnemonic) = await Task.Run(
                        () =>
                    {
                        var walletGenerator = new WalletGenerator(
                            walletManager.WalletDirectories.WalletsDir,
                            network)
                        {
                            TipHeight = store.SmartHeaderChain.TipHeight
                        };
                        return(walletGenerator.GenerateWallet(WalletName, password));
                    });

                    Navigate().To(new RecoveryWordsViewModel(km, mnemonic, walletManager));
                }
            });

            this.ValidateProperty(x => x.WalletName, errors => ValidateWalletName(errors, walletManager, WalletName));

            EnableAutoBusyOn(CreateWalletCommand);
        }