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

πŸ“¦ (mobile) [DSDK-610]: Setup sample app + rn ble transport #666

Open
wants to merge 35 commits into
base: develop
Choose a base branch
from

Conversation

jdabbech-ledger
Copy link
Contributor

@jdabbech-ledger jdabbech-ledger commented Feb 6, 2025

πŸ“ Description

  • Add RN mobile app in apps/ folder
  • Add rn-ble transport with:
    • StartDiscovering
    • StopDiscovering
    • Connect
    • Disconnect
    • Reconnect

❓ Context

  • Feature:

βœ… Checklist

Pull Requests must pass CI checks and undergo code review. Set the PR as Draft if it is not yet ready for review.

  • Covered by automatic tests
  • Changeset is provided
  • Impact of the changes:
    • list of the changes

🧐 Checklist for the PR Reviewers

  • The code aligns with the requirements described in the linked JIRA or GitHub issue.
  • The PR description clearly documents the changes made and explains any technical trade-offs or design decisions.
  • There are no undocumented trade-offs, technical debt, or maintainability issues.
  • The PR has been tested thoroughly, and any potential edge cases have been considered and handled.
  • Any new dependencies have been justified and documented.

@jdabbech-ledger jdabbech-ledger requested a review from a team as a code owner February 6, 2025 16:59
Copy link

vercel bot commented Feb 6, 2025

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Name Status Preview Comments Updated (UTC)
device-sdk-ts-sample βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback Feb 20, 2025 10:24am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
doc-device-management-kit ⬜️ Ignored (Inspect) Visit Preview Feb 20, 2025 10:24am

Copy link

socket-security bot commented Feb 6, 2025

New, updated, and removed dependencies detected. Learn more about Socket for GitHub β†—οΈŽ

Package New capabilities Transitives Size Publisher
gem/[email protected] environment, eval, filesystem, network, shell, unsafe +11 3.52 MB
gem/[email protected] environment, filesystem, network, shell, unsafe Transitive: eval +26 12.3 MB
gem/[email protected] environment, eval, filesystem, network, shell, unsafe +83 39.8 MB
gem/[email protected] environment, filesystem, shell, unsafe Transitive: eval, network +8 2.2 MB
npm/@babel/[email protected] πŸ” npm/@babel/[email protected] Transitive: shell +39 11.5 MB existentialism, hzoo, jlhwung, ...1 more
npm/@babel/[email protected] πŸ” npm/@babel/[email protected] Transitive: shell, unsafe +133 19.8 MB existentialism, hzoo, jlhwung, ...1 more
npm/@ledgerhq/[email protected] Transitive: environment +31 15.2 MB ldg-github-ci
npm/@react-native-community/[email protected] πŸ” npm/@react-native-community/[email protected] Transitive: network +112 3.78 MB thymikee
npm/@react-native-community/[email protected] πŸ” npm/@react-native-community/[email protected] Transitive: environment, filesystem, network, shell +82 2.5 MB thymikee
npm/@react-native-community/[email protected] πŸ” npm/@react-native-community/[email protected] network Transitive: eval, unsafe +175 10.1 MB thymikee
npm/@react-native/[email protected] πŸ” npm/@react-native/[email protected] Transitive: filesystem, shell, unsafe +120 21 MB fb, react-native-bot
npm/@react-native/[email protected] πŸ” npm/@react-native/[email protected] Transitive: environment, filesystem, unsafe +129 21.3 MB fb, react-native-bot
npm/@react-native/[email protected] Transitive: environment, eval, filesystem +185 19.5 MB react-native-bot
npm/@react-native/[email protected] πŸ” npm/@react-native/[email protected] None 0 362 kB react-native-bot
npm/@react-native/[email protected] Transitive: environment, eval, filesystem, network, shell, unsafe +156 27.5 MB react-native-bot
npm/@react-native/[email protected] None 0 2.01 kB react-native-bot
npm/@react-navigation/[email protected] Transitive: environment +7 912 kB satya164
npm/@react-navigation/[email protected] Transitive: environment +9 1.02 MB satya164
npm/@react-navigation/[email protected] Transitive: environment +8 900 kB satya164
npm/@react-navigation/[email protected] environment +13 2.11 MB satya164
npm/@react-navigation/[email protected] Transitive: environment +7 1.37 MB satya164
npm/@tsconfig/[email protected] None 0 3.41 kB typescript-deploys
npm/@types/[email protected] None 0 8.45 kB types
npm/@types/[email protected] None +1 397 kB types
npm/[email protected] environment, filesystem +25 3.3 MB tleunen
npm/[email protected] environment, filesystem Transitive: eval, shell, unsafe +98 10.8 MB eslintbot
npm/[email protected] None 0 38.6 kB dankogai
npm/[email protected] None 0 814 kB aliberski
npm/[email protected] Transitive: environment +7 5.09 MB jakub.piasecki, jgonet, kmag, ...2 more
npm/[email protected] None +1 22.5 kB linusu
npm/[email protected] None 0 216 kB trozee
npm/[email protected] environment, eval Transitive: filesystem, shell +73 20.6 MB tomekzaw
npm/[email protected] None 0 242 kB janicduplessis
npm/[email protected] environment +2 1.69 MB kkafar
npm/[email protected] πŸ” npm/[email protected] None +13 7.44 MB jake7
npm/[email protected] πŸ” npm/[email protected] Transitive: eval, filesystem, shell, unsafe +307 174 MB cortinico, eliwhite, fb, ...4 more
npm/[email protected] environment +6 1.77 MB react-bot
npm/[email protected] None 0 39.2 MB typescript-bot
npm/[email protected] environment Transitive: eval +29 610 kB goto-bus-stop
npm/[email protected] None 0 168 kB broofa

View full reportβ†—οΈŽ

Copy link
Contributor

github-actions bot commented Feb 6, 2025

Messages
βœ… Danger: All checks passed successfully! πŸŽ‰

Generated by 🚫 dangerJS against 9275d00

@jdabbech-ledger jdabbech-ledger force-pushed the feat/dsdk-610-rn-mobile-ble branch from 3c32096 to eb57fca Compare February 7, 2025 14:16
@jdabbech-ledger jdabbech-ledger changed the title πŸ“¦ (mobile): Setup sample app + rn ble transport πŸ“¦ (mobile) [DSDK-610]: Setup sample app + rn ble transport Feb 7, 2025
@jdabbech-ledger jdabbech-ledger force-pushed the feat/dsdk-610-rn-mobile-ble branch from 2413323 to 2e4aaba Compare February 7, 2025 17:16
@jdabbech-ledger jdabbech-ledger force-pushed the feat/dsdk-610-rn-mobile-ble branch from 2e4aaba to 46c4748 Compare February 10, 2025 11:10
@jdabbech-ledger jdabbech-ledger force-pushed the feat/dsdk-610-rn-mobile-ble branch from 29e8b53 to 2537264 Compare February 11, 2025 09:02
@jdabbech-ledger jdabbech-ledger force-pushed the feat/dsdk-610-rn-mobile-ble branch from 2537264 to 5b7543c Compare February 11, 2025 10:43
@jdabbech-ledger jdabbech-ledger force-pushed the feat/dsdk-610-rn-mobile-ble branch from 5b7543c to 5790b8c Compare February 11, 2025 12:47
@jdabbech-ledger jdabbech-ledger force-pushed the feat/dsdk-610-rn-mobile-ble branch from 642fe2c to a1eb875 Compare February 12, 2025 14:14
@jdabbech-ledger jdabbech-ledger force-pushed the feat/dsdk-610-rn-mobile-ble branch from 70fb8f1 to bda6d37 Compare February 12, 2025 14:59
@jdabbech-ledger jdabbech-ledger force-pushed the feat/dsdk-610-rn-mobile-ble branch from bda6d37 to 696eb28 Compare February 12, 2025 15:01
@@ -0,0 +1,79 @@
This is a new [**React Native**](https://reactnative.dev) project, bootstrapped using [`@react-native-community/cli`](https://github.com/react-native-community/cli).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[COULD] update the readme

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that it is necessary, otherwise we should probably take time to update web sample app readme as well

"react-native": "0.76.6",
"react-native-ble-plx": "^3.4.0",
"react-native-gesture-handler": "^2.22.0",
"react-native-pager-view": "^6.7.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[ASK] not sure we are using this package, check all deps to remove if not used ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a package required by @react-navigation/material-top-tabs https://reactnavigation.org/docs/material-top-tab-navigator/


const getHexString = useCallback((raw: Uint8Array): string => {
return raw
.reduce((acc, curr) => acc + " " + curr.toString(16).padStart(2, "0"), "")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[COULD] we have some utils doing this on dmk: bufferToHexaString

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This hook isn't used, will delete it in mobile

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[SHOULD] rename the file to DeviceSessionsProvider

Copy link
Contributor Author

@jdabbech-ledger jdabbech-ledger Feb 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about it, in web sample app provider naming is in PascalCase as they are folders with index file.
In mobile sample app we can't import this way actually (probably need to rework bundle things, didn't took time to do so).
IMO it's clearer with this kind of naming, as the file doesn't have a default export (and the cache computing is faster on my IDE without index file nor default export ^^)

@jdabbech-ledger jdabbech-ledger force-pushed the feat/dsdk-610-rn-mobile-ble branch from c980479 to 9b1a744 Compare February 19, 2025 13:33
readonly deviceModel: DeviceModel;
readonly transport: TransportIdentifier;
readonly rssi?: number | null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the future we should try to find a better solution to expose this kind of transport specific data...
Maybe a function getDiscoveredDeviceMetadata(discoveredDevice) that can be implemented by each transport?

Comment on lines +108 to +115
closeConnection(connectedDevice: TransportConnectedDevice) {
const transport = this.getTransport(connectedDevice.transport);
transport.map((t) =>
t.disconnect({
connectedDevice,
}),
);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ‘

Comment on lines 152 to 163
this._isDeviceReady.next(false);
const requestMtuApdu = Uint8Array.from([0x08, 0x00, 0x00, 0x00, 0x00]);
await this.write(Base64.fromUint8Array(requestMtuApdu));
let sub: Subscription;
await new Promise<void>((resolve) => {
sub = this._isDeviceReady.subscribe((isReady) => {
if (isReady) {
resolve();
sub.unsubscribe();
}
});
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[ASK] Have we tested without this ? From my understanding, react-native-ble-plx does the MTU negociation and then stores the result in device.mtu.
Are there known cases where there's a difference between the value of device.mtu and the value obtained by sending this frame?
If no (we should test on multiple devices & at least android and iOS), then we can skip this whole part and remove the isDeviceReady logic, as the MTU will already be known from scratch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I tested without this (flex/stax only) and I'm pretty sure that it's not necessary, but it could have side effect that I haven't seen yet and I prefered to let it.
I'll create a task about it

},
);
this._isDeviceReady.next(false);
const requestMtuApdu = Uint8Array.from([0x08, 0x00, 0x00, 0x00, 0x00]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[COMMENT] this is not an APDU, it's an entire BLE frame.

Comment on lines 1 to 2
import React, { useEffect, useRef } from "react";
import { createContext, type PropsWithChildren, useContext } from "react";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[SHOULD] be one import from "react"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants