mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-11-16 17:27:37 +00:00
Better Ledger Connection handling (#1802)
This commit is contained in:
parent
c4698576a3
commit
0adb69d095
5 changed files with 14 additions and 6 deletions
|
@ -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 (_) {}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -402,6 +402,10 @@ class CWMonero extends Monero {
|
|||
moneroWallet.setLedgerConnection(connection);
|
||||
}
|
||||
|
||||
void resetLedgerConnection() {
|
||||
disableLedgerExchange();
|
||||
}
|
||||
|
||||
@override
|
||||
void setGlobalLedgerConnection(ledger.LedgerConnection connection) {
|
||||
gLedger = connection;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue