Better Ledger Connection handling (#1802)

This commit is contained in:
Konstantin Ullrich 2024-11-13 10:44:43 +01:00 committed by GitHub
parent c4698576a3
commit 0adb69d095
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 14 additions and 6 deletions

View file

@ -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 (_) {}
});
}
}

View file

@ -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);

View file

@ -402,6 +402,10 @@ class CWMonero extends Monero {
moneroWallet.setLedgerConnection(connection);
}
void resetLedgerConnection() {
disableLedgerExchange();
}
@override
void setGlobalLedgerConnection(ledger.LedgerConnection connection) {
gLedger = connection;

View file

@ -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();
}
}
});
}

View file

@ -415,6 +415,7 @@ abstract class Monero {
WalletService createMoneroWalletService(Box<WalletInfo> walletInfoSource, Box<UnspentCoinsInfo> unspentCoinSource);
Map<String, String> pendingTransactionInfo(Object transaction);
void setLedgerConnection(Object wallet, ledger.LedgerConnection connection);
void resetLedgerConnection();
void setGlobalLedgerConnection(ledger.LedgerConnection connection);
}