Skip to content

Commit 8b099cf

Browse files
authored
feat: implement Reactotron (MetaMask#17780)
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** React Native DevTools network tab is unstable on Android and it only works on iOS. As an alternative, Reactotron is implemented to view API calls on Android (also works on iOS) ## **Changelog** <!-- If this PR is not End-User-Facing and should not show up in the CHANGELOG, you can choose to either: 1. Write `CHANGELOG entry: null` 2. Label with `no-changelog` If this PR is End-User-Facing, please write a short User-Facing description in the past tense like: `CHANGELOG entry: Added a new tab for users to see their NFTs` `CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker` (This helps the Release Engineer do their job more quickly and accurately) --> CHANGELOG entry: null ## **Related issues** Fixes: MetaMask/mobile-planning#2245 ## **Manual testing steps** 1. Install desktop Reactotron `brew install --cask reactotron` 2. Open Reactotron and refresh simulator (maybe need to rebuild) 3. Should see API calls in Timeline tab in Reactotron 4. If no connection is made on Android, run `adb reverse tcp:9090 tcp:9090` ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** ![React Native DevTool](https://github.com/user-attachments/assets/bb40c273-c12c-4a4e-9fb3-6921ce8ecca0) ### **After** ![Reactotron](https://github.com/user-attachments/assets/0685744a-e5c5-48b6-9bd4-3f0e8a93a587) <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [x] I’ve followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [x] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [x] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.
1 parent 71b70c1 commit 8b099cf

6 files changed

Lines changed: 60 additions & 1 deletion

File tree

ReactotronConfig.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import Reactotron, { networking } from 'reactotron-react-native';
2+
3+
Reactotron.configure().use(networking()).connect();

docs/readme/api-logging.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ LOG_API_CALLS=true yarn start:android
2121

2222
1. Open a new terminal window
2323
2. Run the following command:
24+
2425
```bash
2526
yarn start:api-logging-server
2627
```
2728

2829
The monitor will start and display:
30+
2931
- The port it's running on
3032
- Detailed logs for all API calls including:
3133
- Request method and URL
@@ -53,11 +55,13 @@ The API call logging functionality is implemented using the following components
5355
4. The API monitor script uses `mockttp` to intercept and log all API calls
5456

5557
When using the API monitor, you'll see detailed logs in the console showing:
58+
5659
- All API requests with their methods, URLs, headers, and bodies
5760
- All API responses with their status codes, headers, and bodies
5861
- Pretty-formatted JSON for better readability
5962

6063
This is particularly useful for:
64+
6165
- Debugging API-related issues
6266
- Understanding the network traffic of the app
63-
- Verifying that API calls are being made correctly
67+
- Verifying that API calls are being made correctly

docs/readme/debugging.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,29 @@ For reference on how to use `Redux DevTools`, refer to [Redux DevTools](https://
3131
- Make sure the value of `webviewDebuggingEnabled` prop on the Webview component is `true`
3232
- Open Safari on your desktop
3333
- Go to the menu Develop -> [Your device] -> [Website]
34+
35+
## Debugging Network Requests using Reactotron
36+
37+
Reactotron is already configured in the app and can be used to monitor API calls
38+
39+
### Install the Reactotron Desktop App
40+
41+
```bash
42+
brew install --cask reactotron
43+
```
44+
45+
### Start monitoring
46+
47+
- Open Reactotron
48+
- Refresh simulator
49+
- API logs should appear under Timeline tab in Reactotron.
50+
51+
### Troubleshooting (Android)
52+
53+
If Reactotron isn’t picking up connections on Android, run:
54+
55+
```bash
56+
adb reverse tcp:9090 tcp:9090
57+
```
58+
59+
Then refresh the app again.

index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ import {
1818
} from './app/core/ErrorHandler';
1919

2020
import { enableFreeze } from 'react-native-screens';
21+
22+
if (__DEV__) {
23+
require('./ReactotronConfig');
24+
}
25+
2126
enableFreeze(true);
2227

2328
// Setup Sentry

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@
445445
"react-native-webview-invoke": "^0.6.2",
446446
"react-native-worklets-core": "^1.6.0",
447447
"react-redux": "^8.1.3",
448+
"reactotron-react-native": "^5.1.14",
448449
"readable-stream": "2.3.7",
449450
"redux": "^4.2.1",
450451
"redux-mock-store": "1.5.4",

yarn.lock

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28137,6 +28137,26 @@ react@18.3.1, react@^18.2.0, react@^18.3.1:
2813728137
dependencies:
2813828138
loose-envify "^1.1.0"
2813928139

28140+
reactotron-core-client@2.9.7:
28141+
version "2.9.7"
28142+
resolved "https://registry.yarnpkg.com/reactotron-core-client/-/reactotron-core-client-2.9.7.tgz#c1fd2842b095dbd2c7522cfc6bd59e34768038eb"
28143+
integrity sha512-QWd0ekjU71CQL70J87NT5f7cmIJAMVZND+YgOaaUgmgFjhiXzHrpeIWs19+IFQPVLsJr97gdi58X8Y62Hchs9w==
28144+
dependencies:
28145+
reactotron-core-contract "0.2.5"
28146+
28147+
reactotron-core-contract@0.2.5:
28148+
version "0.2.5"
28149+
resolved "https://registry.yarnpkg.com/reactotron-core-contract/-/reactotron-core-contract-0.2.5.tgz#927160c026895798bfe931bd2462fdd5d4e435f9"
28150+
integrity sha512-pxuXFG1jffAWQSdT0FBws+/Xvl8++6T6WrAi4g7AxIZU5FPeut2wq//0yDhDWx6lF82eAo5JTZK7zECQy45QxA==
28151+
28152+
reactotron-react-native@^5.1.14:
28153+
version "5.1.14"
28154+
resolved "https://registry.yarnpkg.com/reactotron-react-native/-/reactotron-react-native-5.1.14.tgz#65d3e8ed0e1e94c9fdb84e374dd2aa455a403067"
28155+
integrity sha512-D4TVQ4qei4jYNyJQBs1/DDxnMrJLiYxHjrZbOziAGPr9WA0kBMZ1X7INdIR9CaJtqpw9770fgVzOyYXtayXZVg==
28156+
dependencies:
28157+
mitt "^3.0.1"
28158+
reactotron-core-client "2.9.7"
28159+
2814028160
read-cache@^1.0.0:
2814128161
version "1.0.0"
2814228162
resolved "https://registry.yarnpkg.com/read-cache/-/read-cache-1.0.0.tgz#e664ef31161166c9751cdbe8dbcf86b5fb58f774"

0 commit comments

Comments
 (0)