mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-03-21 22:58:45 +00:00
Restore Wallet WIP [skip-ci]
This commit is contained in:
parent
f8f682dea3
commit
6d7a384a98
8 changed files with 107 additions and 25 deletions
|
@ -175,9 +175,9 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance,
|
||||||
|
|
||||||
PendingTransactionDescription pendingTransactionDescription;
|
PendingTransactionDescription pendingTransactionDescription;
|
||||||
|
|
||||||
if (!(syncStatus is SyncedSyncStatus)) {
|
// if (!(syncStatus is SyncedSyncStatus)) {
|
||||||
throw MoneroTransactionCreationException('The wallet is not synced.');
|
// throw MoneroTransactionCreationException('The wallet is not synced.');
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (hasMultiDestination) {
|
if (hasMultiDestination) {
|
||||||
if (outputs.any((item) => item.sendAll
|
if (outputs.any((item) => item.sendAll
|
||||||
|
|
10
lib/di.dart
10
lib/di.dart
|
@ -298,7 +298,7 @@ Future setup({
|
||||||
(WalletType type) => getIt.get<WalletService>(param1: type)));
|
(WalletType type) => getIt.get<WalletService>(param1: type)));
|
||||||
|
|
||||||
getIt.registerFactoryParam<WalletNewVM, WalletType, void>((type, _) => WalletNewVM(
|
getIt.registerFactoryParam<WalletNewVM, WalletType, void>((type, _) => WalletNewVM(
|
||||||
getIt.get<AppStore>(), getIt.get<WalletCreationService>(param1: type), _walletInfoSource,
|
getIt.get<AppStore>(), getIt.get<WalletCreationService>(param1: type),getIt.get<FiatConversionStore>(), _walletInfoSource,
|
||||||
type: type));
|
type: type));
|
||||||
|
|
||||||
getIt.registerFactoryParam<WalletRestorationFromSeedVM, List, void>((args, _) {
|
getIt.registerFactoryParam<WalletRestorationFromSeedVM, List, void>((args, _) {
|
||||||
|
@ -307,7 +307,7 @@ Future setup({
|
||||||
final mnemonic = args[2] as String;
|
final mnemonic = args[2] as String;
|
||||||
|
|
||||||
return WalletRestorationFromSeedVM(
|
return WalletRestorationFromSeedVM(
|
||||||
getIt.get<AppStore>(), getIt.get<WalletCreationService>(param1: type), _walletInfoSource,
|
getIt.get<AppStore>(), getIt.get<WalletCreationService>(param1: type), _walletInfoSource , getIt.get<FiatConversionStore>(),
|
||||||
type: type, language: language, seed: mnemonic);
|
type: type, language: language, seed: mnemonic);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -316,13 +316,13 @@ Future setup({
|
||||||
final language = args[1] as String;
|
final language = args[1] as String;
|
||||||
|
|
||||||
return WalletRestorationFromKeysVM(
|
return WalletRestorationFromKeysVM(
|
||||||
getIt.get<AppStore>(), getIt.get<WalletCreationService>(param1: type), _walletInfoSource,
|
getIt.get<AppStore>(), getIt.get<WalletCreationService>(param1: type), _walletInfoSource, getIt.get<FiatConversionStore>(),
|
||||||
type: type, language: language);
|
type: type, language: language);
|
||||||
});
|
});
|
||||||
|
|
||||||
getIt.registerFactoryParam<WalletRestorationFromQRVM, WalletType, void>((WalletType type, _) {
|
getIt.registerFactoryParam<WalletRestorationFromQRVM, WalletType, void>((WalletType type, _) {
|
||||||
return WalletRestorationFromQRVM(getIt.get<AppStore>(),
|
return WalletRestorationFromQRVM(getIt.get<AppStore>(),
|
||||||
getIt.get<WalletCreationService>(param1: type), _walletInfoSource, type);
|
getIt.get<WalletCreationService>(param1: type), getIt.get<FiatConversionStore>(), _walletInfoSource, type);
|
||||||
});
|
});
|
||||||
|
|
||||||
getIt.registerFactory<WalletAddressListViewModel>(() => WalletAddressListViewModel(
|
getIt.registerFactory<WalletAddressListViewModel>(() => WalletAddressListViewModel(
|
||||||
|
@ -739,7 +739,7 @@ Future setup({
|
||||||
|
|
||||||
getIt.registerFactoryParam<WalletRestoreViewModel, WalletType, void>((type, _) =>
|
getIt.registerFactoryParam<WalletRestoreViewModel, WalletType, void>((type, _) =>
|
||||||
WalletRestoreViewModel(
|
WalletRestoreViewModel(
|
||||||
getIt.get<AppStore>(), getIt.get<WalletCreationService>(param1: type), _walletInfoSource,
|
getIt.get<AppStore>(), getIt.get<WalletCreationService>(param1: type),getIt.get<FiatConversionStore>(), _walletInfoSource,
|
||||||
type: type));
|
type: type));
|
||||||
|
|
||||||
getIt.registerFactoryParam<WalletRestorePage, WalletType, void>(
|
getIt.registerFactoryParam<WalletRestorePage, WalletType, void>(
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import 'package:cake_wallet/bitcoin/bitcoin.dart';
|
import 'package:cake_wallet/bitcoin/bitcoin.dart';
|
||||||
|
import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart';
|
||||||
import 'package:cake_wallet/view_model/restore/restore_mode.dart';
|
import 'package:cake_wallet/view_model/restore/restore_mode.dart';
|
||||||
import 'package:cake_wallet/view_model/restore/restore_wallet.dart';
|
import 'package:cake_wallet/view_model/restore/restore_wallet.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive/hive.dart';
|
||||||
|
@ -18,14 +19,14 @@ part 'restore_from_qr_vm.g.dart';
|
||||||
class WalletRestorationFromQRVM = WalletRestorationFromQRVMBase with _$WalletRestorationFromQRVM;
|
class WalletRestorationFromQRVM = WalletRestorationFromQRVMBase with _$WalletRestorationFromQRVM;
|
||||||
|
|
||||||
abstract class WalletRestorationFromQRVMBase extends WalletCreationVM with Store {
|
abstract class WalletRestorationFromQRVMBase extends WalletCreationVM with Store {
|
||||||
WalletRestorationFromQRVMBase(AppStore appStore, WalletCreationService walletCreationService,
|
WalletRestorationFromQRVMBase(AppStore appStore, WalletCreationService walletCreationService,FiatConversionStore fiatConversationStore,
|
||||||
Box<WalletInfo> walletInfoSource, WalletType type)
|
Box<WalletInfo> walletInfoSource, WalletType type)
|
||||||
: height = 0,
|
: height = 0,
|
||||||
viewKey = '',
|
viewKey = '',
|
||||||
spendKey = '',
|
spendKey = '',
|
||||||
wif = '',
|
wif = '',
|
||||||
address = '',
|
address = '',
|
||||||
super(appStore, walletInfoSource, walletCreationService, type: type, isRecovery: true);
|
super(appStore, walletInfoSource, walletCreationService, fiatConversationStore, type: type, isRecovery: true);
|
||||||
|
|
||||||
@observable
|
@observable
|
||||||
int height;
|
int height;
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:cake_wallet/core/wallet_creation_service.dart';
|
import 'package:cake_wallet/core/wallet_creation_service.dart';
|
||||||
|
import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart';
|
||||||
import 'package:cake_wallet/view_model/restore/restore_wallet.dart';
|
import 'package:cake_wallet/view_model/restore/restore_wallet.dart';
|
||||||
|
import 'package:cake_wallet/view_model/send/output.dart';
|
||||||
import 'package:cw_core/balance.dart';
|
import 'package:cw_core/balance.dart';
|
||||||
|
import 'package:cw_core/pending_transaction.dart';
|
||||||
import 'package:cw_core/transaction_history.dart';
|
import 'package:cw_core/transaction_history.dart';
|
||||||
import 'package:cw_core/transaction_info.dart';
|
import 'package:cw_core/transaction_info.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive/hive.dart';
|
||||||
|
@ -22,7 +27,7 @@ part 'wallet_creation_vm.g.dart';
|
||||||
class WalletCreationVM = WalletCreationVMBase with _$WalletCreationVM;
|
class WalletCreationVM = WalletCreationVMBase with _$WalletCreationVM;
|
||||||
|
|
||||||
abstract class WalletCreationVMBase with Store {
|
abstract class WalletCreationVMBase with Store {
|
||||||
WalletCreationVMBase(this._appStore, this._walletInfoSource, this.walletCreationService,
|
WalletCreationVMBase(this._appStore, this._walletInfoSource, this.walletCreationService, this._fiatConversationStore,
|
||||||
{required this.type, required this.isRecovery})
|
{required this.type, required this.isRecovery})
|
||||||
: state = InitialExecutionState(),
|
: state = InitialExecutionState(),
|
||||||
name = '';
|
name = '';
|
||||||
|
@ -33,11 +38,17 @@ abstract class WalletCreationVMBase with Store {
|
||||||
@observable
|
@observable
|
||||||
ExecutionState state;
|
ExecutionState state;
|
||||||
|
|
||||||
|
@observable
|
||||||
|
PendingTransaction? pendingTransaction;
|
||||||
|
|
||||||
WalletType type;
|
WalletType type;
|
||||||
final bool isRecovery;
|
final bool isRecovery;
|
||||||
final WalletCreationService walletCreationService;
|
final WalletCreationService walletCreationService;
|
||||||
final Box<WalletInfo> _walletInfoSource;
|
final Box<WalletInfo> _walletInfoSource;
|
||||||
final AppStore _appStore;
|
final AppStore _appStore;
|
||||||
|
final FiatConversionStore _fiatConversationStore;
|
||||||
|
|
||||||
|
Completer<void> syncCompleter = Completer<void>();
|
||||||
|
|
||||||
bool nameExists(String name) => walletCreationService.exists(name);
|
bool nameExists(String name) => walletCreationService.exists(name);
|
||||||
|
|
||||||
|
@ -64,8 +75,10 @@ abstract class WalletCreationVMBase with Store {
|
||||||
//! Switch to the restoredWallet in order to activate the node connection
|
//! Switch to the restoredWallet in order to activate the node connection
|
||||||
_appStore.changeCurrentWallet(restoredWallet);
|
_appStore.changeCurrentWallet(restoredWallet);
|
||||||
|
|
||||||
|
await restoredWallet.startSync();
|
||||||
|
|
||||||
//! Sweep all funds from restoredWallet to newWallet
|
//! Sweep all funds from restoredWallet to newWallet
|
||||||
await sweepAllFundsToNewWallet(type, newWalletAddress, restoreWallet?.txId ?? '');
|
await sweepAllFundsToNewWallet(restoredWallet, type, newWalletAddress, restoreWallet?.txId ?? '');
|
||||||
|
|
||||||
//! Switch back to new wallet
|
//! Switch back to new wallet
|
||||||
_appStore.changeCurrentWallet(newWallet);
|
_appStore.changeCurrentWallet(newWallet);
|
||||||
|
@ -118,14 +131,77 @@ abstract class WalletCreationVMBase with Store {
|
||||||
: await process(credentials);
|
: await process(credentials);
|
||||||
walletInfo.address = wallet.walletAddresses.address;
|
walletInfo.address = wallet.walletAddresses.address;
|
||||||
|
|
||||||
|
|
||||||
return wallet;
|
return wallet;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Map<String, dynamic>> sweepAllFundsToNewWallet(
|
Future<void> sweepAllFundsToNewWallet(WalletBase<Balance, TransactionHistoryBase<TransactionInfo>, TransactionInfo> wallet,
|
||||||
WalletType type, String address, String paymentId) async {
|
WalletType type, String newWalletAddress, String paymentId) async {
|
||||||
final currentNode = _appStore.settingsStore.getCurrentNode(type);
|
final output = Output(wallet, _appStore.settingsStore, _fiatConversationStore, () => wallet.currency);
|
||||||
final result = await walletCreationService.sweepAllFunds(currentNode, address, paymentId);
|
output.address = newWalletAddress;
|
||||||
return result;
|
output.sendAll = true;
|
||||||
|
output.note = 'testing the sweep all function';
|
||||||
|
final credentials = _credentials(type, wallet.currency.title, output);
|
||||||
|
print('About to enter create function');
|
||||||
|
await createTransaction(wallet, credentials);
|
||||||
|
// final currentNode = _appStore.settingsStore.getCurrentNode(type);
|
||||||
|
// final result = await walletCreationService.sweepAllFunds(currentNode, newWalletAddress, paymentId);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Object _credentials(WalletType type,String cryptoCurrencyTitle,Output output ) {
|
||||||
|
switch (type) {
|
||||||
|
case WalletType.bitcoin:
|
||||||
|
final priority = _appStore.settingsStore.priority[type];
|
||||||
|
|
||||||
|
if (priority == null) {
|
||||||
|
throw Exception('Priority is null for wallet type: ${type}');
|
||||||
|
}
|
||||||
|
|
||||||
|
return bitcoin!.createBitcoinTransactionCredentials([output], priority: priority);
|
||||||
|
case WalletType.litecoin:
|
||||||
|
final priority = _appStore.settingsStore.priority[type];
|
||||||
|
|
||||||
|
if (priority == null) {
|
||||||
|
throw Exception('Priority is null for wallet type: ${type}');
|
||||||
|
}
|
||||||
|
|
||||||
|
return bitcoin!.createBitcoinTransactionCredentials([output], priority: priority);
|
||||||
|
case WalletType.monero:
|
||||||
|
final priority = _appStore.settingsStore.priority[type];
|
||||||
|
|
||||||
|
if (priority == null) {
|
||||||
|
throw Exception('Priority is null for wallet type: ${type}');
|
||||||
|
}
|
||||||
|
|
||||||
|
return monero!.createMoneroTransactionCreationCredentials(
|
||||||
|
outputs:[output], priority: priority);
|
||||||
|
case WalletType.haven:
|
||||||
|
final priority = _appStore.settingsStore.priority[type];
|
||||||
|
|
||||||
|
if (priority == null) {
|
||||||
|
throw Exception('Priority is null for wallet type: ${type}');
|
||||||
|
}
|
||||||
|
|
||||||
|
return haven!.createHavenTransactionCreationCredentials(
|
||||||
|
outputs: [output], priority: priority, assetType: cryptoCurrencyTitle);
|
||||||
|
default:
|
||||||
|
throw Exception('Unexpected wallet type: ${type}');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@action
|
||||||
|
Future<void> createTransaction(WalletBase wallet, Object credentials) async {
|
||||||
|
try {
|
||||||
|
print('in here');
|
||||||
|
state = IsExecutingState();
|
||||||
|
print('about to enter wallet create transaction function');
|
||||||
|
pendingTransaction = await wallet.createTransaction(credentials);
|
||||||
|
state = ExecutedSuccessfullyState();
|
||||||
|
} catch (e) {
|
||||||
|
state = FailureState(e.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WalletCredentials getCredentials(dynamic options) {
|
WalletCredentials getCredentials(dynamic options) {
|
||||||
|
|
|
@ -11,16 +11,18 @@ import 'package:cake_wallet/monero/monero.dart';
|
||||||
import 'package:cake_wallet/bitcoin/bitcoin.dart';
|
import 'package:cake_wallet/bitcoin/bitcoin.dart';
|
||||||
import 'package:cake_wallet/haven/haven.dart';
|
import 'package:cake_wallet/haven/haven.dart';
|
||||||
|
|
||||||
|
import '../store/dashboard/fiat_conversion_store.dart';
|
||||||
|
|
||||||
part 'wallet_new_vm.g.dart';
|
part 'wallet_new_vm.g.dart';
|
||||||
|
|
||||||
class WalletNewVM = WalletNewVMBase with _$WalletNewVM;
|
class WalletNewVM = WalletNewVMBase with _$WalletNewVM;
|
||||||
|
|
||||||
abstract class WalletNewVMBase extends WalletCreationVM with Store {
|
abstract class WalletNewVMBase extends WalletCreationVM with Store {
|
||||||
WalletNewVMBase(AppStore appStore, WalletCreationService walletCreationService,
|
WalletNewVMBase(AppStore appStore, WalletCreationService walletCreationService,FiatConversionStore fiatConversationStore,
|
||||||
Box<WalletInfo> walletInfoSource,
|
Box<WalletInfo> walletInfoSource,
|
||||||
{required WalletType type})
|
{required WalletType type})
|
||||||
: selectedMnemonicLanguage = '',
|
: selectedMnemonicLanguage = '',
|
||||||
super(appStore, walletInfoSource, walletCreationService, type: type, isRecovery: false);
|
super(appStore, walletInfoSource, walletCreationService,fiatConversationStore, type: type, isRecovery: false);
|
||||||
|
|
||||||
@observable
|
@observable
|
||||||
String selectedMnemonicLanguage;
|
String selectedMnemonicLanguage;
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart';
|
||||||
import 'package:cake_wallet/view_model/restore/restore_wallet.dart';
|
import 'package:cake_wallet/view_model/restore/restore_wallet.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive/hive.dart';
|
||||||
|
@ -21,14 +22,14 @@ class WalletRestorationFromKeysVM = WalletRestorationFromKeysVMBase
|
||||||
abstract class WalletRestorationFromKeysVMBase extends WalletCreationVM
|
abstract class WalletRestorationFromKeysVMBase extends WalletCreationVM
|
||||||
with Store {
|
with Store {
|
||||||
WalletRestorationFromKeysVMBase(AppStore appStore,
|
WalletRestorationFromKeysVMBase(AppStore appStore,
|
||||||
WalletCreationService walletCreationService, Box<WalletInfo> walletInfoSource,
|
WalletCreationService walletCreationService, Box<WalletInfo> walletInfoSource,FiatConversionStore fiatConversationStore,
|
||||||
{required WalletType type, required this.language})
|
{required WalletType type, required this.language})
|
||||||
: height = 0,
|
: height = 0,
|
||||||
viewKey = '',
|
viewKey = '',
|
||||||
spendKey = '',
|
spendKey = '',
|
||||||
wif = '',
|
wif = '',
|
||||||
address = '',
|
address = '',
|
||||||
super(appStore, walletInfoSource, walletCreationService, type: type, isRecovery: true);
|
super(appStore, walletInfoSource, walletCreationService, fiatConversationStore, type: type, isRecovery: true);
|
||||||
|
|
||||||
@observable
|
@observable
|
||||||
int height;
|
int height;
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart';
|
||||||
import 'package:cake_wallet/view_model/restore/restore_wallet.dart';
|
import 'package:cake_wallet/view_model/restore/restore_wallet.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive/hive.dart';
|
||||||
|
@ -21,10 +22,10 @@ class WalletRestorationFromSeedVM = WalletRestorationFromSeedVMBase
|
||||||
abstract class WalletRestorationFromSeedVMBase extends WalletCreationVM
|
abstract class WalletRestorationFromSeedVMBase extends WalletCreationVM
|
||||||
with Store {
|
with Store {
|
||||||
WalletRestorationFromSeedVMBase(AppStore appStore,
|
WalletRestorationFromSeedVMBase(AppStore appStore,
|
||||||
WalletCreationService walletCreationService, Box<WalletInfo> walletInfoSource,
|
WalletCreationService walletCreationService, Box<WalletInfo> walletInfoSource,FiatConversionStore fiatConversationStore,
|
||||||
{required WalletType type, required this.language, this.seed = ''})
|
{required WalletType type, required this.language, this.seed = ''})
|
||||||
: height = 0,
|
: height = 0,
|
||||||
super(appStore, walletInfoSource, walletCreationService, type: type, isRecovery: true);
|
super(appStore, walletInfoSource, walletCreationService ,fiatConversationStore, type: type, isRecovery: true);
|
||||||
|
|
||||||
@observable
|
@observable
|
||||||
String seed;
|
String seed;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import 'package:cake_wallet/bitcoin/bitcoin.dart';
|
import 'package:cake_wallet/bitcoin/bitcoin.dart';
|
||||||
import 'package:cake_wallet/core/mnemonic_length.dart';
|
import 'package:cake_wallet/core/mnemonic_length.dart';
|
||||||
|
import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart';
|
||||||
import 'package:cake_wallet/view_model/restore/restore_wallet.dart';
|
import 'package:cake_wallet/view_model/restore/restore_wallet.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive/hive.dart';
|
||||||
|
@ -23,7 +24,7 @@ class WalletRestoreViewModel = WalletRestoreViewModelBase
|
||||||
with _$WalletRestoreViewModel;
|
with _$WalletRestoreViewModel;
|
||||||
|
|
||||||
abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
|
abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
|
||||||
WalletRestoreViewModelBase(AppStore appStore, WalletCreationService walletCreationService,
|
WalletRestoreViewModelBase(AppStore appStore, WalletCreationService walletCreationService,FiatConversionStore fiatConversationStore,
|
||||||
Box<WalletInfo> walletInfoSource,
|
Box<WalletInfo> walletInfoSource,
|
||||||
{required WalletType type})
|
{required WalletType type})
|
||||||
: availableModes = (type == WalletType.monero || type == WalletType.haven)
|
: availableModes = (type == WalletType.monero || type == WalletType.haven)
|
||||||
|
@ -33,7 +34,7 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
|
||||||
hasBlockchainHeightLanguageSelector = type == WalletType.monero || type == WalletType.haven,
|
hasBlockchainHeightLanguageSelector = type == WalletType.monero || type == WalletType.haven,
|
||||||
isButtonEnabled = false,
|
isButtonEnabled = false,
|
||||||
mode = WalletRestoreMode.seed,
|
mode = WalletRestoreMode.seed,
|
||||||
super(appStore, walletInfoSource, walletCreationService, type: type, isRecovery: true) {
|
super(appStore, walletInfoSource, walletCreationService, fiatConversationStore, type: type, isRecovery: true) {
|
||||||
isButtonEnabled =
|
isButtonEnabled =
|
||||||
!hasSeedLanguageSelector && !hasBlockchainHeightLanguageSelector;
|
!hasSeedLanguageSelector && !hasBlockchainHeightLanguageSelector;
|
||||||
walletCreationService.changeWalletType(type: type);
|
walletCreationService.changeWalletType(type: type);
|
||||||
|
|
Loading…
Reference in a new issue