mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-26 21:50:27 +00:00
aedf310c9d
* Run Monero Synchronization task in background on Android * Add monero sync task in the load function to be registered/cancelled when user changes wallets * Revert unused file changes * Register Sync task on all monero wallets if any * Add Sync Modes and change task frequency based on user's choice * Register background task after current wallet is set * Add Sync All toggle and change task wallets to sync accordingly * Enable background notifications in release mode temporarily * Disable constraints and increase the frequency of tasks * Decrease frequency of background tasks * Delay the background task thread till the syncing thread finish (Dummy Trial-1) * Start Sync process and wait for it to finish * Wait for synchronization to finish before ending the background thread Add 10 minutes timeout duration for sync process * Connect to node before syncing wallet * replace testing configuration with the configurations agreed on * Fix Conflicts with main * Update and Migrate Background tasks to null safety * Update workmanager version in pubspec_base also * Move Sync options to Connection and sync page Show Sync options only for Monero and Haven Minor Enhancements * Remove debugging notifications Revert aggressive mode frequency to 6 hours [skip ci] * Add iOS configs * Revert debugging changes Fix conflicts with main * Add/Extract Sync configurations to/from backup file [skip ci]
94 lines
3.4 KiB
Dart
94 lines
3.4 KiB
Dart
import 'package:cake_wallet/core/wallet_creation_service.dart';
|
|
import 'package:cake_wallet/di.dart';
|
|
import 'package:cake_wallet/entities/background_tasks.dart';
|
|
import 'package:cake_wallet/view_model/restore/restore_wallet.dart';
|
|
import 'package:hive/hive.dart';
|
|
import 'package:mobx/mobx.dart';
|
|
import 'package:cake_wallet/core/execution_state.dart';
|
|
import 'package:cw_core/wallet_base.dart';
|
|
import 'package:cw_core/wallet_credentials.dart';
|
|
import 'package:cw_core/pathForWallet.dart';
|
|
import 'package:cw_core/wallet_info.dart';
|
|
import 'package:cw_core/wallet_type.dart';
|
|
import 'package:cake_wallet/store/app_store.dart';
|
|
import 'package:cake_wallet/entities/generate_name.dart';
|
|
|
|
part 'wallet_creation_vm.g.dart';
|
|
|
|
class WalletCreationVM = WalletCreationVMBase with _$WalletCreationVM;
|
|
|
|
abstract class WalletCreationVMBase with Store {
|
|
WalletCreationVMBase(this._appStore, this._walletInfoSource, this.walletCreationService,
|
|
{required this.type, required this.isRecovery})
|
|
: state = InitialExecutionState(),
|
|
name = '';
|
|
|
|
@observable
|
|
String name;
|
|
|
|
@observable
|
|
ExecutionState state;
|
|
|
|
WalletType type;
|
|
final bool isRecovery;
|
|
final WalletCreationService walletCreationService;
|
|
final Box<WalletInfo> _walletInfoSource;
|
|
final AppStore _appStore;
|
|
|
|
bool nameExists(String name)
|
|
=> walletCreationService.exists(name);
|
|
|
|
bool typeExists(WalletType type)
|
|
=> walletCreationService.typeExists(type);
|
|
|
|
Future<void> create({dynamic options, RestoredWallet? restoreWallet}) async {
|
|
final type = restoreWallet?.type ?? this.type;
|
|
try {
|
|
state = IsExecutingState();
|
|
if (name.isEmpty) {
|
|
name = await generateName();
|
|
}
|
|
|
|
walletCreationService.checkIfExists(name);
|
|
final dirPath = await pathForWalletDir(name: name, type: type);
|
|
final path = await pathForWallet(name: name, type: type);
|
|
final credentials = restoreWallet != null
|
|
? getCredentialsFromRestoredWallet(options, restoreWallet)
|
|
: getCredentials(options);
|
|
final walletInfo = WalletInfo.external(
|
|
id: WalletBase.idFor(name, type),
|
|
name: name,
|
|
type: type,
|
|
isRecovery: isRecovery,
|
|
restoreHeight: credentials.height ?? 0,
|
|
date: DateTime.now(),
|
|
path: path,
|
|
dirPath: dirPath,
|
|
address: '',
|
|
showIntroCakePayCard: (!walletCreationService.typeExists(type)) && type != WalletType.haven);
|
|
credentials.walletInfo = walletInfo;
|
|
final wallet = restoreWallet != null
|
|
? await processFromRestoredWallet(credentials, restoreWallet)
|
|
: await process(credentials);
|
|
walletInfo.address = wallet.walletAddresses.address;
|
|
await _walletInfoSource.add(walletInfo);
|
|
_appStore.changeCurrentWallet(wallet);
|
|
getIt.get<BackgroundTasks>().registerSyncTask();
|
|
_appStore.authenticationStore.allowed();
|
|
state = ExecutedSuccessfullyState();
|
|
} catch (e) {
|
|
state = FailureState(e.toString());
|
|
}
|
|
}
|
|
WalletCredentials getCredentials(dynamic options) =>
|
|
throw UnimplementedError();
|
|
|
|
Future<WalletBase> process(WalletCredentials credentials) =>
|
|
throw UnimplementedError();
|
|
|
|
WalletCredentials getCredentialsFromRestoredWallet(dynamic options, RestoredWallet restoreWallet) =>
|
|
throw UnimplementedError();
|
|
|
|
Future<WalletBase> processFromRestoredWallet(WalletCredentials credentials, RestoredWallet restoreWallet) =>
|
|
throw UnimplementedError();
|
|
}
|