Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(mobile): fix ledger on android #837

Merged
merged 1 commit into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)