mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-06-28 12:29:51 +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) {
|
void keepAlive(LedgerConnection connection) {
|
||||||
if (connection.connectionType == ConnectionType.ble) {
|
if (connection.connectionType == ConnectionType.ble) {
|
||||||
UniversalBle.onConnectionChange = (String deviceId, bool isConnected) {
|
|
||||||
print("[Monero] Ledger Disconnected");
|
|
||||||
_ledgerKeepAlive?.cancel();
|
|
||||||
};
|
|
||||||
_ledgerKeepAlive = Timer.periodic(Duration(seconds: 10), (_) async {
|
_ledgerKeepAlive = Timer.periodic(Duration(seconds: 10), (_) async {
|
||||||
try {
|
try {
|
||||||
UniversalBle.setNotifiable(
|
UniversalBle.setNotifiable(
|
||||||
|
@ -59,7 +55,7 @@ void keepAlive(LedgerConnection connection) {
|
||||||
connection.device.deviceInfo.notifyCharacteristicKey,
|
connection.device.deviceInfo.notifyCharacteristicKey,
|
||||||
BleInputProperty.notification,
|
BleInputProperty.notification,
|
||||||
);
|
);
|
||||||
} catch (_){}
|
} catch (_) {}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -146,6 +146,11 @@ class MoneroWalletService extends WalletService<
|
||||||
password: password);
|
password: password);
|
||||||
final isValid = wallet.walletAddresses.validate();
|
final isValid = wallet.walletAddresses.validate();
|
||||||
|
|
||||||
|
if (wallet.isHardwareWallet) {
|
||||||
|
wallet.setLedgerConnection(gLedger!);
|
||||||
|
gLedger = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (!isValid) {
|
if (!isValid) {
|
||||||
await restoreOrResetWalletFiles(name);
|
await restoreOrResetWalletFiles(name);
|
||||||
wallet.close(shouldCleanup: false);
|
wallet.close(shouldCleanup: false);
|
||||||
|
|
|
@ -402,6 +402,10 @@ class CWMonero extends Monero {
|
||||||
moneroWallet.setLedgerConnection(connection);
|
moneroWallet.setLedgerConnection(connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void resetLedgerConnection() {
|
||||||
|
disableLedgerExchange();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void setGlobalLedgerConnection(ledger.LedgerConnection connection) {
|
void setGlobalLedgerConnection(ledger.LedgerConnection connection) {
|
||||||
gLedger = connection;
|
gLedger = connection;
|
||||||
|
|
|
@ -98,7 +98,9 @@ abstract class LedgerViewModelBase with Store {
|
||||||
print('Ledger Device State Changed: $event');
|
print('Ledger Device State Changed: $event');
|
||||||
if (event == sdk.BleConnectionState.disconnected) {
|
if (event == sdk.BleConnectionState.disconnected) {
|
||||||
_connection = null;
|
_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);
|
WalletService createMoneroWalletService(Box<WalletInfo> walletInfoSource, Box<UnspentCoinsInfo> unspentCoinSource);
|
||||||
Map<String, String> pendingTransactionInfo(Object transaction);
|
Map<String, String> pendingTransactionInfo(Object transaction);
|
||||||
void setLedgerConnection(Object wallet, ledger.LedgerConnection connection);
|
void setLedgerConnection(Object wallet, ledger.LedgerConnection connection);
|
||||||
|
void resetLedgerConnection();
|
||||||
void setGlobalLedgerConnection(ledger.LedgerConnection connection);
|
void setGlobalLedgerConnection(ledger.LedgerConnection connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue