From 8c609f09a1a3d170949246b742102ee1da0c0be9 Mon Sep 17 00:00:00 2001 From: Blazebrain Date: Wed, 17 May 2023 12:00:20 +0100 Subject: [PATCH] CW-328-Restore-wallet-from-QRCode-and-sweep-all-funds-in-a-new-wallet WIP --- cw_monero/lib/api/wallet_manager.dart | 2 +- lib/src/screens/restore/restore_options_page.dart | 8 +++++--- lib/view_model/restore/restore_from_qr_vm.dart | 12 ++++++++++++ lib/view_model/wallet_creation_vm.dart | 5 +++++ 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/cw_monero/lib/api/wallet_manager.dart b/cw_monero/lib/api/wallet_manager.dart index 8b8c01940..14f9ba338 100644 --- a/cw_monero/lib/api/wallet_manager.dart +++ b/cw_monero/lib/api/wallet_manager.dart @@ -250,7 +250,7 @@ Future sweepFundsToNewWallet({ }) async { final uri = Uri.http(node.uriRaw, ''); final path = '/json_rpc'; - final rpcUri = Uri.https(uri.authority, path); + final rpcUri = node.isSSL ? Uri.https(uri.authority, path) : Uri.http(uri.authority, path); final realm = 'monero-rpc'; final body = { 'method': 'sweep_all', diff --git a/lib/src/screens/restore/restore_options_page.dart b/lib/src/screens/restore/restore_options_page.dart index 93a44c752..49448bcea 100644 --- a/lib/src/screens/restore/restore_options_page.dart +++ b/lib/src/screens/restore/restore_options_page.dart @@ -67,12 +67,14 @@ class RestoreOptionsPage extends BasePage { } if (!isNewInstall || isPinSet) { try { + //! This gives us the restored wallet final restoreWallet = await WalletRestoreFromQRCode.scanQRCodeForRestoring(context); - final restoreFromQRViewModel = getIt.get(param1: restoreWallet.type); - - await restoreFromQRViewModel.create(restoreWallet: restoreWallet); + //! Next step will be to create a new wallet from this + final restoreFromQRViewModel = + getIt.get(param1: restoreWallet.type); + await restoreFromQRViewModel.create(restoreWallet: restoreWallet); if (restoreFromQRViewModel.state is FailureState) { _onWalletCreateFailure(context, 'Create wallet state: ${restoreFromQRViewModel.state.runtimeType.toString()}'); diff --git a/lib/view_model/restore/restore_from_qr_vm.dart b/lib/view_model/restore/restore_from_qr_vm.dart index 7efb92e69..82e385b52 100644 --- a/lib/view_model/restore/restore_from_qr_vm.dart +++ b/lib/view_model/restore/restore_from_qr_vm.dart @@ -83,6 +83,18 @@ abstract class WalletRestorationFromQRVMBase extends WalletCreationVM with Store default: throw Exception('Unexpected type: ${type.toString()}'); } + case WalletRestoreMode.txids: + switch (restoreWallet.type) { + case WalletType.monero: + return monero! + .createMoneroNewWalletCredentials(name: name, language: options as String); + case WalletType.bitcoin: + return bitcoin!.createBitcoinNewWalletCredentials(name: name); + case WalletType.litecoin: + return bitcoin!.createBitcoinNewWalletCredentials(name: name); + default: + throw Exception('Unexpected type: ${restoreWallet.type.toString()}'); + } default: throw Exception('Unexpected type: ${type.toString()}'); } diff --git a/lib/view_model/wallet_creation_vm.dart b/lib/view_model/wallet_creation_vm.dart index 323d1f911..78851e790 100644 --- a/lib/view_model/wallet_creation_vm.dart +++ b/lib/view_model/wallet_creation_vm.dart @@ -65,11 +65,16 @@ abstract class WalletCreationVMBase with Store { address: '', showIntroCakePayCard: (!walletCreationService.typeExists(type)) && type != WalletType.haven); credentials.walletInfo = walletInfo; + + //! Restored final wallet = restoreWallet != null ? await processFromRestoredWallet(credentials, restoreWallet) : await process(credentials); walletInfo.address = wallet.walletAddresses.address; await _walletInfoSource.add(walletInfo); + //---- Code to create new + + //! Before we switch _appStore.changeCurrentWallet(wallet); _appStore.authenticationStore.allowed(); state = ExecutedSuccessfullyState();