Files
hash-wallet/lib/view_model/wallet_switcher_view_model.dart
T
13a74133f5 feat: Pay Anything from Any Wallet (#2450)
* feat: Pay Anything from Any Wallet

* feat: Trigger payment flow when address is pasted

* chore: Remove unneeded changes

* feat Expand address checks and fix scanning bch qrs

* fix: Add support for dogecoin

* feat: More modifications for Pay from Any Wallet

This change:
- Adds the pay from any wallet flow to externally signed QR codes
- Adds fixes for review comments
- Fixes failing tests

---------

Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
2025-08-21 18:37:50 +03:00

64 lines
1.6 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:hive/hive.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,
required this.walletInfoSource,
});
final AppStore appStore;
final WalletLoadingService walletLoadingService;
final Box<WalletInfo> walletInfoSource;
@observable
WalletInfo? selectedWallet;
@observable
bool isProcessing = false;
@action
List<WalletInfo> getWallets(WalletType? walletType) {
if (walletType == null) {
return walletInfoSource.values.toList();
}
return walletInfoSource.values.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;
}
}
}