Skip to content

Commit

Permalink
fix(mobile): fix ledger on android (#837)
Browse files Browse the repository at this point in the history
  • Loading branch information
sorokin0andrey authored May 9, 2024
1 parent c268e96 commit 484bb5a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
19 changes: 15 additions & 4 deletions packages/mobile/src/ledger/useBluetoothAvailable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
showBluetoothPoweredOffAlert,
} from '$utils/bluetoothPermissions';
import TransportBLE from '@ledgerhq/react-native-hw-transport-ble';
import { delay } from '@tonkeeper/core';
import { isIOS } from '@tonkeeper/uikit';
import { useEffect, useState } from 'react';
import { Observable } from 'rxjs';
Expand All @@ -14,20 +15,30 @@ export const useBluetoothAvailable = () => {
useEffect(() => {
const subscription = new Observable(TransportBLE.observeState).subscribe({
next: async (event) => {
setAvailable(event.available);

if (event.type === 'Unauthorized') {
console.log('Bluetooth Unauthorized');
if (isIOS) {
showBluetoothPermissionsAlert();
} else {
await checkAndRequestAndroidBluetooth();
}
}
if (event.type === 'PoweredOff') {
console.log('Bluetooth Powered Off');
showBluetoothPoweredOffAlert();
}

if (event.type === 'PoweredOn') {
if (isIOS) {
setAvailable(event.available);
} else {
try {
await delay(1000);
const granted = await checkAndRequestAndroidBluetooth();
setAvailable(granted);
} catch {
setAvailable(false);
}
}
}
},
complete: () => {},
error: () => {},
Expand Down
21 changes: 21 additions & 0 deletions patches/react-native-ble-plx+2.0.3.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
diff --git a/node_modules/react-native-ble-plx/android/src/main/java/com/polidea/reactnativeble/BleClientManager.java b/node_modules/react-native-ble-plx/android/src/main/java/com/polidea/reactnativeble/BleClientManager.java
index 48f946d..d97919d 100644
--- a/node_modules/react-native-ble-plx/android/src/main/java/com/polidea/reactnativeble/BleClientManager.java
+++ b/node_modules/react-native-ble-plx/android/src/main/java/com/polidea/reactnativeble/BleClientManager.java
@@ -925,6 +925,16 @@ public class BleClientManager extends ReactContextBaseJavaModule {
);
}

+ @ReactMethod
+ public void addListener(String eventName) {
+ // Keep: Required for RN built in Event Emitter Calls.
+ }
+
+ @ReactMethod
+ public void removeListeners(int count) {
+ // Keep: Required for RN built in Event Emitter Calls.
+ }
+
private void sendEvent(@NonNull Event event, @Nullable Object params) {
getReactApplicationContext()
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)

0 comments on commit 484bb5a

Please sign in to comment.