mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-26 06:08:40 +01:00
* refactor: migrate hardware wallet resources to `new-ui`, add Trezor model support, and streamline hardware wallet handling across services * refactor: migrate hardware wallet resources to `new-ui`, add Trezor model support, and streamline hardware wallet handling across services * fix: correctly check for Ledger hardware wallet type in `isHardwareWallet` logic * refactor: unify `isConnected` method for hardware wallets, add Trezor-specific support, and update Monero sync logic * refactor: add Trezor transaction signing support, streamline hardware wallet handling, and update Monero dependency * refactor: improve Trezor transaction handling, adjust hardware wallet state logic, and update Monero dependency references * fix: non-hww tx commit() in xmr fix: prod monero_c fix: keyImage import workaround for Trezor/Cupcake chore: add kotlin's .salive to .gitignore * fix: universal_ble builds on iOS chore: remove prints fix: proper CI prebuilt for linux * new trezor connection ui * fix page title * typo * fix page title anim * refactor: enhance Trezor pairing flow, update state management, and simplify UI logic in hardware wallet integration * fix: correct widget indentation in Trezor pairing failure state UI * fix: extract Trezor pairing failure state UI to `_errorBox` widget and update Trezor dependency reference * refactor: simplify hardware wallet pairing error UI, optimize `_errorBox` layout, and streamline widget logic * Update cw_monero/lib/pending_monero_transaction.dart Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com> * Update lib/buy/robinhood/robinhood_buy_provider.dart Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com> * feat: add USB intent filters, device filter for hardware wallets, and update Trezor dependency reference * Update cw_monero/pubspec.yaml [skip ci] * Update cw_wownero/pubspec.yaml [skip ci] * Update cw_zano/pubspec.yaml [skip ci] * fix: use CryptoCurrency.title instead of amount-refactor-only .symbol getter new_wallet_type_page used curr.symbol, which only exists on the amount-refactor branch (String get symbol => title). On dev the equivalent is curr.title. Adapts the Trezor feature to dev's API without pulling in amount-refactor. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * Fix wallet list screen not scrollable minor fixes --------- Co-authored-by: Konstantin Ullrich <konstantinullrich12@gmail.com> Co-authored-by: Czarek Nakamoto <cyjan@mrcyjanek.net> Co-authored-by: Robert Malikowski <malikowskirobert@gmail.com> Co-authored-by: Konstantin Ullrich <konstantin@cakewallet.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
112 lines
3.5 KiB
Dart
112 lines
3.5 KiB
Dart
import 'dart:async';
|
|
import 'dart:io';
|
|
|
|
import 'package:cake_wallet/bitcoin/bitcoin.dart';
|
|
import 'package:cake_wallet/entities/hardware_wallet/hardware_wallet_device.dart';
|
|
import 'package:cake_wallet/evm/evm.dart';
|
|
import 'package:cake_wallet/view_model/hardware_wallet/hardware_wallet_view_model.dart';
|
|
import 'package:cake_wallet/wallet_type_utils.dart';
|
|
import 'package:cw_core/hardware/hardware_wallet_service.dart';
|
|
import 'package:cw_core/root_dir.dart';
|
|
import 'package:cw_core/utils/print_verbose.dart';
|
|
import 'package:cw_core/wallet_base.dart';
|
|
import 'package:cw_core/wallet_info.dart';
|
|
import 'package:cw_core/wallet_type.dart';
|
|
import 'package:bitbox_flutter/bitbox_flutter.dart' as sdk;
|
|
import 'package:mobx/mobx.dart';
|
|
|
|
part 'bitbox_view_model.g.dart';
|
|
|
|
class BitboxViewModel = BitboxViewModelBase with _$BitboxViewModel;
|
|
|
|
abstract class BitboxViewModelBase extends HardwareWalletViewModel with Store {
|
|
late final sdk.BitboxManager bitboxManager;
|
|
|
|
BitboxViewModelBase() {
|
|
if (!Platform.isIOS && !isMoneroOnly) {
|
|
bitboxManager = sdk.BitboxManager();
|
|
}
|
|
}
|
|
|
|
@override
|
|
HardwareWalletType get hardwareWalletType => HardwareWalletType.bitbox;
|
|
|
|
@override
|
|
@observable
|
|
bool isBleEnabled = false;
|
|
|
|
@override
|
|
bool get hasBluetooth => Platform.isIOS && false; // TODO: remove when we enable bluetooth
|
|
|
|
@override
|
|
Future<void> updateBleState() async {}
|
|
|
|
@override
|
|
Stream<HardwareWalletDevice> scanForBleDevices() => throw UnimplementedError();
|
|
|
|
@override
|
|
Future<List<HardwareWalletDevice>> getAllUsbDevices() => bitboxManager.devices
|
|
.then((devices) => devices.map((d) => BitboxHardwareWalletDevice(d)).toList());
|
|
|
|
@override
|
|
Future<void> stopScanning() async {}
|
|
|
|
@override
|
|
Future<bool> connectDevice(HardwareWalletDevice device, WalletType type) async {
|
|
if (!(device is BitboxHardwareWalletDevice)) return false;
|
|
if (_isConnecting) return false;
|
|
_isConnecting = true;
|
|
|
|
try {
|
|
final appDocDir = await getAppDir();
|
|
|
|
await bitboxManager.connect(device.device);
|
|
printV("Got Connection", file: '${appDocDir.path}/error.txt');
|
|
await bitboxManager.initBitBox();
|
|
printV("Bitbox initialized!", file: '${appDocDir.path}/error.txt');
|
|
await bitboxManager.channelHashVerify();
|
|
printV("Bitbox channel-hash verified!", file: '${appDocDir.path}/error.txt');
|
|
_isConnecting = false;
|
|
return true;
|
|
} catch (e) {
|
|
printV(e);
|
|
}
|
|
_isConnecting = false;
|
|
return false;
|
|
}
|
|
|
|
bool _isConnecting = false;
|
|
|
|
@override
|
|
bool isConnected(WalletType type) => false;
|
|
|
|
@override
|
|
HardwareWalletService getHardwareWalletService(WalletType type) {
|
|
switch (type) {
|
|
case WalletType.bitcoin:
|
|
return bitcoin!.getBitboxHardwareWalletService(bitboxManager, true);
|
|
case WalletType.litecoin:
|
|
return bitcoin!.getBitboxHardwareWalletService(bitboxManager, false);
|
|
case WalletType.ethereum:
|
|
case WalletType.polygon:
|
|
return evm!.getBitboxHardwareWalletService(bitboxManager);
|
|
default:
|
|
throw UnimplementedError();
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future<void> initWallet(WalletBase wallet) async {
|
|
switch (wallet.type) {
|
|
case WalletType.bitcoin:
|
|
case WalletType.litecoin:
|
|
return bitcoin!.setHardwareWalletService(wallet, await getHardwareWalletService(wallet.type));
|
|
case WalletType.ethereum:
|
|
case WalletType.polygon:
|
|
return evm!.setHardwareWalletService(wallet, await getHardwareWalletService(wallet.type));
|
|
default:
|
|
throw Exception('Unexpected wallet type: ${wallet.type} for bitbox');
|
|
}
|
|
}
|
|
}
|