private async Task OnImportWalletAsync(string walletName)
        {
            try
            {
                var filePath = await FileDialogHelper.ShowOpenFileDialogAsync("Import wallet file", new[] { "json" });

                if (filePath is null)
                {
                    return;
                }

                var keyManager = await ImportWalletHelper.ImportWalletAsync(Services.WalletManager, walletName, filePath);

                Navigate().To(new AddedWalletPageViewModel(keyManager));
            }
            catch (Exception ex)
            {
                Logger.LogError(ex);
                await ShowErrorAsync(Title, ex.ToUserFriendlyString(),
                                     "The wallet file was not valid or compatible with Wasabi.");
            }
        }
Exemplo n.º 2
0
    private async Task OnImportWalletAsync()
    {
        try
        {
            var filePath = await FileDialogHelper.ShowOpenFileDialogAsync("Import wallet file", new[] { "json" });

            if (filePath is null)
            {
                return;
            }

            var walletName = Path.GetFileNameWithoutExtension(filePath);

            var validationError = WalletHelpers.ValidateWalletName(walletName);
            if (validationError is { })
            {
                Navigate().To(new WalletNamePageViewModel(WalletCreationOption.ImportWallet, filePath));
                return;
            }

            var keyManager = await ImportWalletHelper.ImportWalletAsync(Services.WalletManager, walletName, filePath);

            Navigate().To(new AddedWalletPageViewModel(keyManager));
        }
Exemplo n.º 3
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);
        }