mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-26 06:08:40 +01:00
feat: enhance hardware wallet compatibility and improve transaction handling (#3517)
* feat: enhance hardware wallet compatibility and improve transaction handling - Updated hardware wallet services for Bitcoin and Litecoin (Ledger & Trezor). - Added `LitecoinTrezorService` for signing and managing Litecoin transactions. - Improved `PSBTTransaction` builder to handle change outputs and derivation paths. - Fixed exception handling in `wallet_hardware_restore_view_model`. - Refactored output and input structures to ensure consistency and extend compatibility. * refactor: address comments * refactor: address comments * refactor: address comments
This commit is contained in:
@@ -558,9 +558,9 @@ class CWBitcoin extends Bitcoin {
|
||||
|
||||
@override
|
||||
HardwareWalletService getTrezorHardwareWalletService(
|
||||
trezor.TrezorConnect connect, bool isBitcoin) {
|
||||
if (isBitcoin) return BitcoinTrezorService(connect);
|
||||
return LitecoinTrezorService(connect);
|
||||
trezor.TrezorConnect? connect, trezor.TrezorClient? client, bool isBitcoin) {
|
||||
if (isBitcoin) return BitcoinTrezorService(client!);
|
||||
return LitecoinTrezorService(connect!);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
+15
-10
@@ -361,9 +361,10 @@ Route<dynamic> createRoute(RouteSettings settings) {
|
||||
ConnectDevicePageParams(
|
||||
walletType: availableWalletTypes.first,
|
||||
hardwareWalletType: hardwareWalletType,
|
||||
onConnectDevice: (BuildContext context, _) => Navigator.of(context).pushNamed(
|
||||
Routes.chooseHardwareWalletAccount,
|
||||
arguments: [availableWalletTypes.first, hardwareWalletType]),
|
||||
onConnectDevice: (context, _) => Navigator.of(context).pushNamed(
|
||||
Routes.chooseHardwareWalletAccount,
|
||||
arguments: [availableWalletTypes.first, hardwareWalletType],
|
||||
),
|
||||
isReconnect: false,
|
||||
),
|
||||
getIt.get<HardwareWalletViewModel>(param1: hardwareWalletType),
|
||||
@@ -373,19 +374,23 @@ Route<dynamic> createRoute(RouteSettings settings) {
|
||||
return handleRouteWithPlatformAwareness(
|
||||
(_) => getIt.get<NewWalletTypePage>(
|
||||
param1: NewWalletTypeArguments(
|
||||
onTypeSelected: (BuildContext context, WalletType type) {
|
||||
if (hardwareWalletType == HardwareWalletType.trezor && type != WalletType.monero) {
|
||||
Navigator.of(context).pushNamed(Routes.chooseHardwareWalletAccount,
|
||||
arguments: [type, hardwareWalletType]);
|
||||
onTypeSelected: (context, type) {
|
||||
if (hardwareWalletType == HardwareWalletType.trezor &&
|
||||
!trezorUseNative.contains(type)) {
|
||||
Navigator.of(context).pushNamed(
|
||||
Routes.chooseHardwareWalletAccount,
|
||||
arguments: [type, hardwareWalletType],
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
final arguments = ConnectDevicePageParams(
|
||||
walletType: type,
|
||||
hardwareWalletType: hardwareWalletType,
|
||||
onConnectDevice: (BuildContext context, _) => Navigator.of(context).pushNamed(
|
||||
Routes.chooseHardwareWalletAccount,
|
||||
arguments: [type, hardwareWalletType]),
|
||||
onConnectDevice: (context, _) => Navigator.of(context).pushNamed(
|
||||
Routes.chooseHardwareWalletAccount,
|
||||
arguments: [type, hardwareWalletType],
|
||||
),
|
||||
isReconnect: false,
|
||||
);
|
||||
|
||||
|
||||
@@ -29,6 +29,8 @@ import "package:trezor_flutter/trezor_flutter.dart" as sdk;
|
||||
|
||||
part "trezor_connect_view_model.g.dart";
|
||||
|
||||
const trezorUseNative = [WalletType.bitcoin, WalletType.monero];
|
||||
|
||||
class TrezorConnectViewModel = TrezorConnectViewModelBase with _$TrezorConnectViewModel;
|
||||
|
||||
abstract class TrezorConnectViewModelBase extends HardwareWalletViewModel with Store {
|
||||
@@ -242,7 +244,7 @@ abstract class TrezorConnectViewModelBase extends HardwareWalletViewModel with S
|
||||
}
|
||||
|
||||
@override
|
||||
bool isConnected(WalletType type) => type == WalletType.monero
|
||||
bool isConnected(WalletType type) => trezorUseNative.contains(type)
|
||||
? _client != null && _client?.connection.isDisconnected == false
|
||||
: true;
|
||||
|
||||
@@ -252,9 +254,9 @@ abstract class TrezorConnectViewModelBase extends HardwareWalletViewModel with S
|
||||
case WalletType.monero:
|
||||
return monero!.getTrezorHardwareWalletService(_client!);
|
||||
case WalletType.bitcoin:
|
||||
return bitcoin!.getTrezorHardwareWalletService(trezorConnect, true);
|
||||
return bitcoin!.getTrezorHardwareWalletService(null, _client!, true);
|
||||
case WalletType.litecoin:
|
||||
return bitcoin!.getTrezorHardwareWalletService(trezorConnect, false);
|
||||
return bitcoin!.getTrezorHardwareWalletService(trezorConnect, null, false);
|
||||
case WalletType.ethereum:
|
||||
case WalletType.polygon:
|
||||
return evm!.getTrezorHardwareWalletService(trezorConnect);
|
||||
|
||||
@@ -56,7 +56,7 @@ abstract class WalletHardwareRestoreViewModelBase extends WalletCreationVM with
|
||||
|
||||
availableAccounts.addAll(accounts);
|
||||
_nextIndex += limit;
|
||||
} catch (e) {
|
||||
} on Exception catch (e) {
|
||||
printV(e);
|
||||
error =
|
||||
hardwareWalletVM.interpretErrorCode(e.toString()) ?? S.current.ledger_connection_error;
|
||||
|
||||
Reference in New Issue
Block a user