Files
hash-wallet/lib/view_model/wallet_hardware_restore_view_model.dart
T
jwinterm dd449f2594 Merge upstream Cake Wallet v6.5.0
Catches up from the May 12 fork point (v6.1.2+23) through v6.5.0: 535
upstream commits, including the Monero silent-open fix, Monero on Trezor,
Ledger/Trezor BLE fixes, the new seed and history screens, quick Bitcoin
sync, git-pinned dependencies (pubspec_overrides.yaml), frozen Hive
adapters (*.part.dart), monero_c v0.18.4.6-RC2 and Flutter 3.41.9.

Merged with both sides normalized first (import rename, 100-column
format), which took the conflict count from 614 paths to 322. The
procedure is now scripts/upstream_sync.sh.

Kept from Hash Bags:
- WalletType enum order and Hive IDs. SQLite stores WalletType.index and
  our order differs from upstream's; taking theirs would reread saved
  wallets as other chains. Our frozen adapter keeps the shipped IDs.
- The 1.0.2 legacy PIN and wallet-password decode and self-heal.
- Removed chains (Solana, Tron, Zano, Zcash, Decred, Haven) and the new
  Robinhood chain stay out; Cake Pay and non-Trocador swaps stay out.
- Default nodes (node.wownero.org, sethforprivacy, Blockstream, bysh.me),
  converted to upstream's isDefault node-list key; Wownero is back in the
  node reset list.
- Privacy: address resolvers limited to domain-anchored sources again;
  prices.neroswap.com for fiat; upstream's charts tab, which reads
  prices.cakewallet.com, sits behind FeatureFlag.isChartsEnabled = false.
- Lightning stays behind FeatureFlag.isLightningEnabled, including
  upstream's new post-seed Lightning username step.
- Our icon pipeline, branding and bundle identifiers.

Twelve new upstream widget tests are skipped: test and code are unchanged
from v6.5.0 apart from renames (not rerun on a pristine upstream checkout;
upstream's top_bar_test does not compile against its own TopBar).
flutter analyze lib: 0 errors; flutter test: 345 passed, 12 skipped;
flutter build bundle compiles. Built with Flutter 3.41.9.
2026-10-24 23:49:29 -04:00

116 lines
4.1 KiB
Dart

import 'package:hash_wallet/bitcoin/bitcoin.dart';
import 'package:hash_wallet/core/generate_wallet_password.dart';
import 'package:hash_wallet/core/wallet_creation_service.dart';
import 'package:hash_wallet/evm/evm.dart';
import 'package:hash_wallet/generated/i18n.dart';
import 'package:hash_wallet/monero/monero.dart';
import 'package:hash_wallet/store/app_store.dart';
import 'package:hash_wallet/view_model/hardware_wallet/hardware_wallet_view_model.dart';
import 'package:hash_wallet/view_model/hardware_wallet/trezor_connect_view_model.dart';
import 'package:hash_wallet/view_model/seed_settings_view_model.dart';
import 'package:hash_wallet/view_model/wallet_creation_vm.dart';
import 'package:cw_core/hardware/hardware_account_data.dart';
import 'package:cw_core/utils/print_verbose.dart';
import 'package:cw_core/wallet_base.dart';
import 'package:cw_core/wallet_credentials.dart';
import 'package:cw_core/wallet_info.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:mobx/mobx.dart';
part 'wallet_hardware_restore_view_model.g.dart';
class WalletHardwareRestoreViewModel = WalletHardwareRestoreViewModelBase
with _$WalletHardwareRestoreViewModel;
abstract class WalletHardwareRestoreViewModelBase extends WalletCreationVM with Store {
final HardwareWalletViewModel hardwareWalletVM;
int _nextIndex = 0;
WalletHardwareRestoreViewModelBase(this.hardwareWalletVM, AppStore appStore,
WalletCreationService walletCreationService, SeedSettingsViewModel seedSettingsViewModel,
{required WalletType type})
: super(appStore, walletCreationService, seedSettingsViewModel, type: type, isRecovery: true);
@observable
String name = "";
@observable
HardwareAccountData? selectedAccount = null;
@observable
bool isLoadingMoreAccounts = false;
@observable
String? error = null;
bool get passphraseAvailable => hardwareWalletVM.hardwareWalletType == HardwareWalletType.trezor;
// @observable
ObservableList<HardwareAccountData> availableAccounts = ObservableList();
@action
Future<void> getNextAvailableAccounts(int limit) async {
try {
final service = await hardwareWalletVM.getHardwareWalletService(type);
final accounts = await service.getAvailableAccounts(index: _nextIndex, limit: limit);
availableAccounts.addAll(accounts);
_nextIndex += limit;
} on Exception catch (e) {
printV(e);
error =
hardwareWalletVM.interpretErrorCode(e.toString()) ?? S.current.ledger_connection_error;
}
isLoadingMoreAccounts = false;
}
@override
WalletCredentials getCredentials(dynamic _options) {
WalletCredentials credentials;
switch (type) {
case WalletType.bitcoin:
case WalletType.litecoin:
credentials = bitcoin!
.createBitcoinHardwareWalletCredentials(name: name, accountData: selectedAccount!);
break;
case WalletType.ethereum:
case WalletType.polygon:
credentials = evm!.createEVMHardwareWalletCredentials(
name: name,
hwAccountData: selectedAccount!,
);
break;
case WalletType.monero:
final password = walletPassword ?? generateWalletPassword();
credentials = monero!.createMoneroRestoreWalletFromHardwareCredentials(
name: name,
hardwareWalletService: hardwareWalletVM.getHardwareWalletService(type),
password: password,
height: _options['height'] as int? ?? 0,
passphrase: _options['passphrase'] as String?,
);
default:
throw Exception('Unexpected type: ${type.toString()}');
}
credentials.hardwareWalletType = hardwareWalletVM.hardwareWalletType;
return credentials;
}
@override
Future<WalletBase> process(WalletCredentials credentials) async {
walletCreationService.changeWalletType(type: type);
final wallet = await walletCreationService.restoreFromHardwareWallet(credentials);
final hardwareWalletVM = this.hardwareWalletVM;
if (hardwareWalletVM is TrezorConnectViewModel && type == WalletType.bitcoin) {
hardwareWalletVM.bindSessionToWallet(wallet);
}
return wallet;
}
}