Skip to content

Commit

Permalink
🎭 Add more descriptive mobile device name to the trustchain (#7651)
Browse files Browse the repository at this point in the history
* Add `react-native-device-info`

* Add more descriptive mobile device name to the trustchain

* Update the changelog

* Ensure `getDeviceNameSync` is called only once

* Fix failing tests

---------

Co-authored-by: Theophile Sandoz <Theophile Sandoz>
  • Loading branch information
thesan authored Aug 23, 2024
1 parent e85f65b commit 6f781da
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/nine-toes-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"live-mobile": patch
---

Add more descriptive mobile device name to the trustchain
4 changes: 4 additions & 0 deletions apps/ledger-live-mobile/__tests__/jest-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ jest.mock("@braze/react-native-sdk", () => ({}));

jest.mock("react-native-webview", () => jest.fn());

jest.mock("react-native-device-info", () => ({
getDeviceNameSync: jest.fn(() => "Mocked Device"),
}));

const originalError = console.error;
const originalWarn = console.warn;

Expand Down
6 changes: 6 additions & 0 deletions apps/ledger-live-mobile/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,8 @@ PODS:
- React-Core
- RNCMaskedView (0.2.9):
- React-Core
- RNDeviceInfo (11.1.0):
- React-Core
- RNFastImage (8.6.3):
- React-Core
- SDWebImage (~> 5.11.1)
Expand Down Expand Up @@ -1524,6 +1526,7 @@ DEPENDENCIES:
- "RNCAsyncStorage (from `../node_modules/@react-native-async-storage/async-storage`)"
- "RNCClipboard (from `../node_modules/@react-native-clipboard/clipboard`)"
- "RNCMaskedView (from `../node_modules/@react-native-masked-view/masked-view`)"
- RNDeviceInfo (from `../node_modules/react-native-device-info`)
- RNFastImage (from `../node_modules/react-native-fast-image`)
- "RNFBApp (from `../node_modules/@react-native-firebase/app`)"
- "RNFBMessaging (from `../node_modules/@react-native-firebase/messaging`)"
Expand Down Expand Up @@ -1768,6 +1771,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/@react-native-clipboard/clipboard"
RNCMaskedView:
:path: "../node_modules/@react-native-masked-view/masked-view"
RNDeviceInfo:
:path: "../node_modules/react-native-device-info"
RNFastImage:
:path: "../node_modules/react-native-fast-image"
RNFBApp:
Expand Down Expand Up @@ -1930,6 +1935,7 @@ SPEC CHECKSUMS:
RNCAsyncStorage: 826b603ae9c0f88b5ac4e956801f755109fa4d5c
RNCClipboard: 60fed4b71560d7bfe40e9d35dea9762b024da86d
RNCMaskedView: 949696f25ec596bfc697fc88e6f95cf0c79669b6
RNDeviceInfo: b899ce37a403a4dea52b7cb85e16e49c04a5b88e
RNFastImage: 5c9c9fed9c076e521b3f509fe79e790418a544e8
RNFBApp: e4439717c23252458da2b41b81b4b475c86f90c4
RNFBMessaging: 40dac204b4197a2661dec5be964780c6ec39bf65
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@
"${PODS_CONFIGURATION_BUILD_DIR}/GoogleUtilities/GoogleUtilities_Privacy.bundle",
"${PODS_CONFIGURATION_BUILD_DIR}/PromisesObjC/FBLPromises_Privacy.bundle",
"${PODS_CONFIGURATION_BUILD_DIR}/RNCAsyncStorage/RNCAsyncStorage_resources.bundle",
"${PODS_CONFIGURATION_BUILD_DIR}/RNDeviceInfo/RNDeviceInfoPrivacyInfo.bundle",
"${PODS_ROOT}/../../node_modules/react-native-vector-icons/Fonts/AntDesign.ttf",
"${PODS_ROOT}/../../node_modules/react-native-vector-icons/Fonts/Entypo.ttf",
"${PODS_ROOT}/../../node_modules/react-native-vector-icons/Fonts/EvilIcons.ttf",
Expand Down Expand Up @@ -496,6 +497,7 @@
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/GoogleUtilities_Privacy.bundle",
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/FBLPromises_Privacy.bundle",
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/RNCAsyncStorage_resources.bundle",
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/RNDeviceInfoPrivacyInfo.bundle",
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/AntDesign.ttf",
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/Entypo.ttf",
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/EvilIcons.ttf",
Expand Down
5 changes: 3 additions & 2 deletions apps/ledger-live-mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"@ledgerhq/ethereum-provider": "workspace:^",
"@ledgerhq/hw-transport": "workspace:^",
"@ledgerhq/hw-transport-http": "workspace:^",
"@ledgerhq/hw-trustchain": "workspace:^",
"@ledgerhq/icons-ui": "workspace:^",
"@ledgerhq/live-common": "workspace:^",
"@ledgerhq/live-config": "workspace:^",
Expand All @@ -102,7 +103,6 @@
"@ledgerhq/types-cryptoassets": "workspace:^",
"@ledgerhq/types-devices": "workspace:^",
"@ledgerhq/types-live": "workspace:^",
"@ledgerhq/hw-trustchain": "workspace:^",
"@likashefqet/react-native-image-zoom": "^1.3.0",
"@react-native-async-storage/async-storage": "^1.19.2",
"@react-native-clipboard/clipboard": "^1.11.2",
Expand Down Expand Up @@ -140,13 +140,13 @@
"expo": "^50.0.3",
"expo-barcode-scanner": "~12.9.2",
"expo-camera": "14.1.3",
"expo-crypto": "^12.8.1",
"expo-file-system": "~16.0.5",
"expo-image-loader": "~4.6.0",
"expo-image-manipulator": "~11.8.0",
"expo-keep-awake": "~12.8.2",
"expo-modules-autolinking": "^1.10.2",
"expo-modules-core": "^1.11.8",
"expo-crypto": "^12.8.1",
"fuse.js": "^6.4.6",
"hoist-non-react-statics": "3.3.2",
"i18next": "20.6.1",
Expand All @@ -169,6 +169,7 @@
"react-native-biometrics": "^3.0.1",
"react-native-ble-plx": "3.1.2",
"react-native-config": "1.5.1",
"react-native-device-info": "^11.1.0",
"react-native-easy-markdown": "^2.0.0",
"react-native-extra-dimensions-android": "^1.2.5",
"react-native-fast-crypto": "^2.2.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { getDeviceNameSync } from "react-native-device-info";
import { getEnv } from "@ledgerhq/live-env";
import { Platform } from "react-native";

const platformMap: Record<string, string | undefined> = {
ios: "iOS",
ios: "iPhone iOS",
android: "Android",
};

let deviceName: string;

export function useInstanceName(): string {
const hash = getEnv("USER_ID").slice(0, 5);
return `${platformMap[Platform.OS] ?? Platform.OS} ${Platform.Version} ${hash ? " " + hash : ""}`;
const os = platformMap[Platform.OS] ?? Platform.OS;
if (!deviceName) deviceName = getDeviceNameSync() ?? `${os} ${Platform.Version}`;
return `${deviceName} ${hash ? " " + hash : ""}`;
}
12 changes: 12 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6f781da

Please sign in to comment.