Skip to content

Commit

Permalink
chore(mobile): ⬆️ upgrade usb lib, jest, sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
Nodonisko committed Nov 15, 2024
1 parent dac2ad1 commit 70f3917
Show file tree
Hide file tree
Showing 17 changed files with 232 additions and 265 deletions.
3 changes: 1 addition & 2 deletions jest.config.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,11 @@ module.exports = {
'\\.(js|jsx|ts|tsx)$': ['babel-jest', babelConfig],
},
transformIgnorePatterns: [
'node_modules/(?!((jest-)?react-native|@react-native(-community)?)|expo(nent)?|@expo(nent)?/.*|@expo-google-fonts/.*|react-navigation|@react-navigation/.*|@unimodules/.*|unimodules|sentry-expo|native-base|react-native-svg)',
'node_modules/(?!((jest-)?react-native|@react-native(-community)?)|expo(nent)?|@expo(nent)?/.*|@expo-google-fonts/.*|react-navigation|@react-navigation/.*|@sentry/react-native|native-base|react-native-svg)',
],
setupFiles: [
'<rootDir>/../../node_modules/@shopify/react-native-skia/jestSetup.js',
'<rootDir>/../../node_modules/react-native-gesture-handler/jestSetup.js',
'<rootDir>/../../suite-native/test-utils/src/setupReactReanimatedMock.js',
'<rootDir>/../../suite-native/test-utils/src/atomsMock.js',
'<rootDir>/../../suite-native/test-utils/src/expoMock.js',
'<rootDir>/../../suite-native/test-utils/src/walletSdkMock.js',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
"globals": "^15.11.0",
"jest": "29.7.0",
"jest-environment-jsdom": "29.7.0",
"jest-expo": "^50.0.2",
"jest-expo": "^52.0.1",
"metro-react-native-babel-preset": "0.77.0",
"node-fetch": "^2.6.4",
"nx": "^18.0.3",
Expand Down
21 changes: 20 additions & 1 deletion packages/react-native-usb/src/ReactNativeUsbModule.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
import { requireNativeModule } from 'expo-modules-core';
import { NativeModule } from 'expo';

import { NativeDevice } from './ReactNativeUsb.types';

type DeviceEvents = {
onDeviceConnect: (device: NativeDevice | null) => void;
onDeviceDisconnect: (device: NativeDevice | null) => void;
};

declare class ReactNativeUsbModuleDeclaration extends NativeModule<DeviceEvents> {
open: (deviceName: string) => Promise<void>;
close: (deviceName: string) => Promise<void>;
claimInterface: (deviceName: string, interfaceNumber: number) => Promise<void>;
releaseInterface: (deviceName: string, interfaceNumber: number) => Promise<void>;
selectConfiguration: (deviceName: string, configurationValue: number) => Promise<void>;
transferIn: (deviceName: string, endpointNumber: number, length: number) => Promise<number[]>;
transferOut: (deviceName: string, endpointNumber: number, data: string) => Promise<void>;
}

// It loads the native module object from the JSI or falls back to
// the bridge module (from NativeModulesProxy) if the remote debugger is on.
export const ReactNativeUsbModule = requireNativeModule('ReactNativeUsb');
export const ReactNativeUsbModule =
requireNativeModule<ReactNativeUsbModuleDeclaration>('ReactNativeUsb');
58 changes: 23 additions & 35 deletions packages/react-native-usb/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
/* eslint-disable no-console */
import { NativeModulesProxy, EventEmitter, Subscription } from 'expo-modules-core';

import { ReactNativeUsbModule } from './ReactNativeUsbModule';
import { NativeDevice, OnConnectEvent, WebUSBDevice } from './ReactNativeUsb.types';

const DEBUG_LOGS = false;

const debugLog = (...args: any[]) => {
if (DEBUG_LOGS) {
// eslint-disable-next-line no-console
console.log(...args);
}
};

const emitter = new EventEmitter(ReactNativeUsbModule ?? NativeModulesProxy.ReactNativeUsb);

const open = (deviceName: string) => ReactNativeUsbModule.open(deviceName);

const close = (deviceName: string) => ReactNativeUsbModule.close(deviceName);
Expand Down Expand Up @@ -105,53 +101,45 @@ const createWebUSBDevice = (device: NativeDevice): WebUSBDevice => ({
// and not send onConnect event if device is already connected.
const connectedDevices = new Map<string, WebUSBDevice>();

export function onDeviceConnected(listener: (event: OnConnectEvent) => void): Subscription {
return emitter.addListener<NativeDevice>('onDeviceConnect', event => {
if (!event) {
console.error('JS: USB onDeviceConnect: event is null');
// just for debugging purposes now
alert('JS: USB onDeviceConnect: event is null');
export function onDeviceConnected(listener: (event: OnConnectEvent) => void) {
return ReactNativeUsbModule.addListener('onDeviceConnect', (device: NativeDevice | null) => {
if (!device) {
debugLog('JS: USB onDeviceConnect: device is null');
console.error('JS: USB onDeviceConnect: device is null');
alert('JS: USB onDeviceConnect: device is null');

return;
}

if (connectedDevices.has(event.deviceName)) {
if (connectedDevices.has(device.deviceName)) {
console.warn('JS: USB onDeviceConnect: device already connected');
debugLog('JS: USB onDeviceConnect: device already connected');

return;
}

const eventPayload = {
device: createWebUSBDevice(event as NativeDevice),
};

debugLog('JS: USB onDeviceConnect', eventPayload);

connectedDevices.set(event.deviceName, eventPayload.device);
const webUSBDevice = createWebUSBDevice(device);
connectedDevices.set(device.deviceName, webUSBDevice);

return listener(eventPayload as any);
const event = { device: webUSBDevice, ...new Event('onconnect') } as OnConnectEvent;
listener(event);
});
}

export function onDeviceDisconnect(listener: (event: OnConnectEvent) => void): Subscription {
return emitter.addListener<NativeDevice>('onDeviceDisconnect', event => {
if (!event) {
console.error('JS: USB onDeviceConnect: event is null');
// just for debugging purposes now
alert('JS: USB onDeviceConnect: event is null');
export function onDeviceDisconnect(listener: (event: OnConnectEvent) => void) {
return ReactNativeUsbModule.addListener('onDeviceDisconnect', (device: NativeDevice | null) => {
if (!device) {
debugLog('JS: USB onDeviceDisconnect: device is null');
console.error('JS: USB onDeviceDisconnect: device is null');
alert('JS: USB onDeviceDisconnect: device is null');

return;
}

const eventPayload = {
device: createWebUSBDevice(event as NativeDevice),
};

debugLog('JS: USB onDeviceDisconnect', eventPayload);

connectedDevices.delete(event.deviceName);

return listener(eventPayload as any);
const webUSBDevice = createWebUSBDevice(device);
connectedDevices.delete(device.deviceName);
const event = { device: webUSBDevice, ...new Event('ondisconnect') } as OnConnectEvent;
listener(event);
});
}

Expand Down
2 changes: 1 addition & 1 deletion suite-native/app/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export default ({ config }: ConfigContext): ExpoConfig => {
slug: appSlugs[buildType],
owner: appOwners[buildType],
version: suiteNativeVersion,
runtimeVersion: '10',
runtimeVersion: '11',
...(buildType === 'production'
? {}
: {
Expand Down
4 changes: 2 additions & 2 deletions suite-native/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@react-navigation/native": "6.1.18",
"@react-navigation/native-stack": "6.11.0",
"@reduxjs/toolkit": "1.9.5",
"@sentry/integrations": "^7.114.0",
"@sentry/core": "8.34.0",
"@sentry/react-native": "6.1.0",
"@shopify/flash-list": "^1.7.2",
"@shopify/react-native-skia": "^1.5.3",
Expand Down Expand Up @@ -108,7 +108,7 @@
"react": "18.2.0",
"react-intl": "^6.6.8",
"react-native": "0.76.1",
"react-native-gesture-handler": "^2.20.2",
"react-native-gesture-handler": "^2.21.0",
"react-native-keyboard-aware-scroll-view": "0.9.5",
"react-native-mmkv": "2.12.2",
"react-native-reanimated": "3.16.1",
Expand Down
2 changes: 1 addition & 1 deletion suite-native/app/src/SentryProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useEffect, ReactNode } from 'react';
import { useSelector } from 'react-redux';

import * as Sentry from '@sentry/react-native';
import { captureConsoleIntegration } from '@sentry/integrations';
import { captureConsoleIntegration } from '@sentry/core';

import { selectIsAnalyticsEnabled } from '@suite-common/analytics';
import { getEnv, isDebugEnv, isDevelopEnv } from '@suite-native/config';
Expand Down
7 changes: 2 additions & 5 deletions suite-native/app/src/snow/Snow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ If you found yourself here, congratulations! You have found an easter egg.
Merry Christmas and Happy New Year!
*/
import React, { useCallback, useEffect } from 'react';
import { AppState, Dimensions, StyleSheet, TextStyle, View } from 'react-native';
import { AppState, Dimensions, StyleSheet, View } from 'react-native';

import { Snowflake } from './Snowflake';

Expand Down Expand Up @@ -40,9 +40,7 @@ const isChristmas = () => {
return month === 11 && day > 22 && day < 26;
};

export const Snow: React.FC<{
snowflakesStyle?: TextStyle;
}> = ({ snowflakesStyle }) => {
export const Snow: React.FC = () => {
const [letItSnow, setLetItSnow] = React.useState(false);

const tryToMakeItSnow = useCallback(() => {
Expand Down Expand Up @@ -84,7 +82,6 @@ export const Snow: React.FC<{
offset={offset}
fallDelay={fallDelay}
shakeDelay={shakeDelay}
style={snowflakesStyle}
/>
);
})}
Expand Down
11 changes: 3 additions & 8 deletions suite-native/app/src/snow/Snowflake.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* eslint-disable @typescript-eslint/no-use-before-define */

import React, { useCallback, useEffect } from 'react';
import { StyleSheet, Dimensions, TextStyle, DimensionValue } from 'react-native';
import { StyleSheet, Dimensions, DimensionValue } from 'react-native';
import Animated, {
Easing,
interpolate,
Expand Down Expand Up @@ -41,7 +41,6 @@ export const Snowflake: React.FC<{
shakeDuration?: number;
fallDelay: number;
shakeDelay: number;
style?: TextStyle;
}> = props => {
const size = props.size || 12;
const amplitude = props.amplitude || 60;
Expand Down Expand Up @@ -105,15 +104,11 @@ export const Snowflake: React.FC<{

if (props.glyph === 'btc') {
return (
<Animated.View style={[styles.text, animatedStyle, props.style]}>
<Animated.View style={[styles.text, animatedStyle]}>
<CryptoIcon symbol="btc" size={13} />
</Animated.View>
);
}

return (
<Animated.Text style={[styles.text, animatedStyle, props.style]}>
{props.glyph || '❅'}
</Animated.Text>
);
return <Animated.Text style={[styles.text, animatedStyle]}>{props.glyph || '❅'}</Animated.Text>;
};
2 changes: 1 addition & 1 deletion suite-native/atoms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"lottie-react-native": "^7.1.0",
"react": "18.2.0",
"react-native": "0.76.1",
"react-native-gesture-handler": "^2.20.2",
"react-native-gesture-handler": "^2.21.0",
"react-native-reanimated": "3.16.1",
"react-native-safe-area-context": "^4.14.0"
}
Expand Down
2 changes: 1 addition & 1 deletion suite-native/notifications/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@trezor/styles": "workspace:*",
"react": "18.2.0",
"react-native": "0.76.1",
"react-native-gesture-handler": "^2.20.2",
"react-native-gesture-handler": "^2.21.0",
"react-native-reanimated": "3.16.1",
"react-redux": "8.0.7"
}
Expand Down
2 changes: 1 addition & 1 deletion suite-native/react-native-graph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@types/react": "18.2.79",
"react": "18.2.0",
"react-native": "0.76.1",
"react-native-gesture-handler": "^2.20.2",
"react-native-gesture-handler": "^2.21.0",
"react-native-reanimated": "3.16.1"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion suite-native/receive/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@trezor/theme": "workspace:*",
"react": "18.2.0",
"react-native": "0.76.1",
"react-native-gesture-handler": "^2.20.2",
"react-native-gesture-handler": "^2.21.0",
"react-native-reanimated": "3.16.1",
"react-redux": "8.0.7"
}
Expand Down
4 changes: 1 addition & 3 deletions suite-native/test-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@
"type-check": "yarn g:tsc --build"
},
"dependencies": {
"@testing-library/react-native": "^11.0.0",
"@testing-library/react-native": "^12.8.1",
"@trezor/styles": "workspace:*",
"@trezor/theme": "workspace:*",
"react": "18.2.0",
"react-native-gesture-handler": "^2.20.2",
"react-native-reanimated": "3.16.1",
"react-native-safe-area-context": "^4.14.0"
}
}
16 changes: 0 additions & 16 deletions suite-native/test-utils/src/setupReactReanimatedMock.js

This file was deleted.

2 changes: 1 addition & 1 deletion suite-native/transactions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"@trezor/utils": "workspace:*",
"react": "18.2.0",
"react-native": "0.76.1",
"react-native-gesture-handler": "^2.20.2",
"react-native-gesture-handler": "^2.21.0",
"react-native-reanimated": "3.16.1",
"react-redux": "8.0.7"
}
Expand Down
Loading

0 comments on commit 70f3917

Please sign in to comment.