mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-20 06:08:34 +02:00
* feat: initial hive -> SQLite Includes migration script and initial work done to remove dependency on hive generators. Also contains some refactoring to make sync code async. Features new dev screen that lists all SQLite tables Aspects that need testing: - backups (from this version, and from previous versions as well) - wallet loading / wallet list - almost everything else - renaming - deletion - sorting in wallet list - wallet groups - wallet seed/keys - wallet switching - wallet creation / restore - all methods - wallet address page - hardware wallet connection (and prompts from mall screens) - contacts - advanced settings in wallet creation - derivation paths - some minor wownero fixes - base, hardware wallets * fix: build errors * fix: Bad state: No element in backup restore * address comments from review * fix: HardwareWalletType
62 lines
1.5 KiB
Dart
62 lines
1.5 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:cake_wallet/store/app_store.dart';
|
|
import 'package:cake_wallet/core/wallet_loading_service.dart';
|
|
import 'package:cw_core/wallet_info.dart';
|
|
import 'package:cw_core/wallet_type.dart';
|
|
import 'package:cw_core/utils/print_verbose.dart';
|
|
import 'package:mobx/mobx.dart';
|
|
|
|
part 'wallet_switcher_view_model.g.dart';
|
|
|
|
class WalletSwitcherViewModel = WalletSwitcherViewModelBase with _$WalletSwitcherViewModel;
|
|
|
|
abstract class WalletSwitcherViewModelBase with Store {
|
|
WalletSwitcherViewModelBase({
|
|
required this.appStore,
|
|
required this.walletLoadingService,
|
|
});
|
|
|
|
final AppStore appStore;
|
|
final WalletLoadingService walletLoadingService;
|
|
|
|
@observable
|
|
WalletInfo? selectedWallet;
|
|
|
|
@observable
|
|
bool isProcessing = false;
|
|
|
|
@action
|
|
Future<List<WalletInfo>> getWallets(WalletType? walletType) async {
|
|
final wiList = await WalletInfo.getAll();
|
|
if (walletType == null) {
|
|
return wiList;
|
|
}
|
|
|
|
return wiList.where((wallet) => wallet.type == walletType).toList();
|
|
}
|
|
|
|
@action
|
|
void selectWallet(WalletInfo walletInfo) => selectedWallet = walletInfo;
|
|
|
|
@action
|
|
Future<bool> switchToSelectedWallet() async {
|
|
if (selectedWallet == null) return false;
|
|
|
|
try {
|
|
isProcessing = true;
|
|
|
|
final wallet = await walletLoadingService.load(selectedWallet!.type, selectedWallet!.name);
|
|
|
|
await appStore.changeCurrentWallet(wallet);
|
|
|
|
return true;
|
|
} catch (e) {
|
|
printV('Failed to switch wallet: $e');
|
|
return false;
|
|
} finally {
|
|
isProcessing = false;
|
|
}
|
|
}
|
|
}
|