mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-22 11:39:22 +00:00
More Ledger Monero Fixes (#1888)
Some checks are pending
Cache Dependencies / test (push) Waiting to run
Some checks are pending
Cache Dependencies / test (push) Waiting to run
* More Ledger Monero Fixes * Minor fixes
This commit is contained in:
parent
b1751f1fd6
commit
77c4eaaf4f
2 changed files with 47 additions and 32 deletions
|
@ -92,6 +92,7 @@ class ConnectDevicePageBodyState extends State<ConnectDevicePageBody> {
|
|||
late StreamSubscription<LedgerDevice>? _bleRefresh = null;
|
||||
|
||||
bool longWait = false;
|
||||
Timer? _longWaitTimer;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
|
@ -108,7 +109,7 @@ class ConnectDevicePageBodyState extends State<ConnectDevicePageBody> {
|
|||
Timer.periodic(Duration(seconds: 1), (_) => _refreshUsbDevices());
|
||||
}
|
||||
|
||||
Future.delayed(Duration(seconds: 10), () {
|
||||
_longWaitTimer = Timer(Duration(seconds: 10), () {
|
||||
if (widget.ledgerVM.bleIsEnabled && bleDevices.isEmpty)
|
||||
setState(() => longWait = true);
|
||||
});
|
||||
|
@ -121,6 +122,7 @@ class ConnectDevicePageBodyState extends State<ConnectDevicePageBody> {
|
|||
_bleStateTimer?.cancel();
|
||||
_usbRefreshTimer?.cancel();
|
||||
_bleRefresh?.cancel();
|
||||
_longWaitTimer?.cancel();
|
||||
|
||||
widget.ledgerVM.stopScanning();
|
||||
super.dispose();
|
||||
|
@ -206,7 +208,8 @@ class ConnectDevicePageBodyState extends State<ConnectDevicePageBody> {
|
|||
offstage: !longWait,
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(left: 20, right: 20, bottom: 20),
|
||||
child: Text(S.of(context).if_you_dont_see_your_device,
|
||||
child: Text(
|
||||
S.of(context).if_you_dont_see_your_device,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
|
@ -235,7 +238,6 @@ class ConnectDevicePageBodyState extends State<ConnectDevicePageBody> {
|
|||
),
|
||||
),
|
||||
),
|
||||
|
||||
if (bleDevices.length > 0) ...[
|
||||
Padding(
|
||||
padding: EdgeInsets.only(left: 20, right: 20, bottom: 20),
|
||||
|
@ -277,7 +279,9 @@ class ConnectDevicePageBodyState extends State<ConnectDevicePageBody> {
|
|||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w400,
|
||||
color: Theme.of(context).extension<CakeTextTheme>()!.titleColor,
|
||||
color: Theme.of(context)
|
||||
.extension<CakeTextTheme>()!
|
||||
.titleColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
@ -299,8 +303,12 @@ class ConnectDevicePageBodyState extends State<ConnectDevicePageBody> {
|
|||
if (widget.allowChangeWallet) ...[
|
||||
PrimaryButton(
|
||||
text: S.of(context).wallets,
|
||||
color: Theme.of(context).extension<WalletListTheme>()!.createNewWalletButtonBackgroundColor,
|
||||
textColor: Theme.of(context).extension<WalletListTheme>()!.restoreWalletButtonTextColor,
|
||||
color: Theme.of(context)
|
||||
.extension<WalletListTheme>()!
|
||||
.createNewWalletButtonBackgroundColor,
|
||||
textColor: Theme.of(context)
|
||||
.extension<WalletListTheme>()!
|
||||
.restoreWalletButtonTextColor,
|
||||
onPressed: _onChangeWallet,
|
||||
)
|
||||
],
|
||||
|
|
|
@ -99,24 +99,38 @@ abstract class LedgerViewModelBase with Store {
|
|||
}
|
||||
|
||||
Future<void> connectLedger(sdk.LedgerDevice device, WalletType type) async {
|
||||
_isConnecting = true;
|
||||
_connectingWalletType = type;
|
||||
if (isConnected) {
|
||||
try {
|
||||
await _connectionChangeListener?.cancel();
|
||||
_connectionChangeListener = null;
|
||||
await _connection!.disconnect().catchError((_) {});
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
final ledger = device.connectionType == sdk.ConnectionType.ble
|
||||
? ledgerPlusBLE
|
||||
: ledgerPlusUSB;
|
||||
|
||||
if (_connectionChangeSubscription == null) {
|
||||
_connectionChangeSubscription = ledger.deviceStateChanges
|
||||
.listen(_connectionChangeListener);
|
||||
}
|
||||
|
||||
if (_connectionChangeListener == null) {
|
||||
_connectionChangeListener = ledger.deviceStateChanges.listen((event) {
|
||||
_connection = await ledger.connect(device);
|
||||
_isConnecting = false;
|
||||
}
|
||||
|
||||
StreamSubscription<sdk.BleConnectionState>? _connectionChangeSubscription;
|
||||
sdk.LedgerConnection? _connection;
|
||||
bool _isConnecting = true;
|
||||
WalletType? _connectingWalletType;
|
||||
|
||||
void _connectionChangeListener(
|
||||
sdk.BleConnectionState event, ) {
|
||||
printV('Ledger Device State Changed: $event');
|
||||
if (event == sdk.BleConnectionState.disconnected) {
|
||||
if (event == sdk.BleConnectionState.disconnected && !_isConnecting) {
|
||||
_connection = null;
|
||||
if (type == WalletType.monero) {
|
||||
if (_connectingWalletType == WalletType.monero) {
|
||||
monero!.resetLedgerConnection();
|
||||
|
||||
Navigator.of(navigatorKey.currentContext!).pushNamed(
|
||||
|
@ -132,15 +146,8 @@ abstract class LedgerViewModelBase with Store {
|
|||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
_connection = await ledger.connect(device);
|
||||
}
|
||||
|
||||
StreamSubscription<sdk.BleConnectionState>? _connectionChangeListener;
|
||||
sdk.LedgerConnection? _connection;
|
||||
|
||||
bool get isConnected => _connection != null && !(_connection!.isDisconnected);
|
||||
|
||||
sdk.LedgerConnection get connection => _connection!;
|
||||
|
|
Loading…
Reference in a new issue