diff --git a/cw_monero/lib/ledger.dart b/cw_monero/lib/ledger.dart index 074975df3..c947d0944 100644 --- a/cw_monero/lib/ledger.dart +++ b/cw_monero/lib/ledger.dart @@ -47,10 +47,6 @@ void enableLedgerExchange(monero.wallet ptr, LedgerConnection connection) { void keepAlive(LedgerConnection connection) { if (connection.connectionType == ConnectionType.ble) { - UniversalBle.onConnectionChange = (String deviceId, bool isConnected) { - print("[Monero] Ledger Disconnected"); - _ledgerKeepAlive?.cancel(); - }; _ledgerKeepAlive = Timer.periodic(Duration(seconds: 10), (_) async { try { UniversalBle.setNotifiable( @@ -59,7 +55,7 @@ void keepAlive(LedgerConnection connection) { connection.device.deviceInfo.notifyCharacteristicKey, BleInputProperty.notification, ); - } catch (_){} + } catch (_) {} }); } } diff --git a/cw_monero/lib/monero_wallet_service.dart b/cw_monero/lib/monero_wallet_service.dart index b2089dfc7..6f49640be 100644 --- a/cw_monero/lib/monero_wallet_service.dart +++ b/cw_monero/lib/monero_wallet_service.dart @@ -146,6 +146,11 @@ class MoneroWalletService extends WalletService< password: password); final isValid = wallet.walletAddresses.validate(); + if (wallet.isHardwareWallet) { + wallet.setLedgerConnection(gLedger!); + gLedger = null; + } + if (!isValid) { await restoreOrResetWalletFiles(name); wallet.close(shouldCleanup: false); diff --git a/lib/monero/cw_monero.dart b/lib/monero/cw_monero.dart index 09d9889c5..89b1579fc 100644 --- a/lib/monero/cw_monero.dart +++ b/lib/monero/cw_monero.dart @@ -402,6 +402,10 @@ class CWMonero extends Monero { moneroWallet.setLedgerConnection(connection); } + void resetLedgerConnection() { + disableLedgerExchange(); + } + @override void setGlobalLedgerConnection(ledger.LedgerConnection connection) { gLedger = connection; diff --git a/lib/view_model/hardware_wallet/ledger_view_model.dart b/lib/view_model/hardware_wallet/ledger_view_model.dart index 96f5930c0..3cd131efa 100644 --- a/lib/view_model/hardware_wallet/ledger_view_model.dart +++ b/lib/view_model/hardware_wallet/ledger_view_model.dart @@ -98,7 +98,9 @@ abstract class LedgerViewModelBase with Store { print('Ledger Device State Changed: $event'); if (event == sdk.BleConnectionState.disconnected) { _connection = null; - _connectionChangeListener?.cancel(); + if (type == WalletType.monero) { + monero!.resetLedgerConnection(); + } } }); } diff --git a/tool/configure.dart b/tool/configure.dart index fb8291385..f0f79cfb1 100644 --- a/tool/configure.dart +++ b/tool/configure.dart @@ -415,6 +415,7 @@ abstract class Monero { WalletService createMoneroWalletService(Box walletInfoSource, Box unspentCoinSource); Map pendingTransactionInfo(Object transaction); void setLedgerConnection(Object wallet, ledger.LedgerConnection connection); + void resetLedgerConnection(); void setGlobalLedgerConnection(ledger.LedgerConnection connection); }