Skip to content

Commit

Permalink
Merge pull request #8169 from LedgerHQ/bugfix/LIVE-14585
Browse files Browse the repository at this point in the history
fix(iOS): Solana error after broadcast on WebSockets [LIVE-14585]
  • Loading branch information
Justkant authored Oct 22, 2024
2 parents 5c13c7b + ab08489 commit c4f102d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .changeset/breezy-deers-scream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
"live-mobile": patch
---

fix(iOS): Solana error after broadcast on WebSockets

We are adding a missing user-agent header on the websocket for iOS with RN
https://github.com/facebook/react-native/issues/28450
https://github.com/facebook/react-native/issues/30727
We need to use the interceptor as we don't control the code initiating the websocket
Updating the options passed in by the interceptor works fine
https://github.com/facebook/react-native/blob/3dfe22bd27429a43b4648c597b71f7965f31ca65/packages/react-native/Libraries/WebSocket/WebSocketInterceptor.js#L148-L163
Another solution could be to use pnpm to patch react native WebSocket linked below
https://github.com/facebook/react-native/blob/3dfe22bd27429a43b4648c597b71f7965f31ca65/packages/react-native/Libraries/WebSocket/WebSocket.js
But the interceptor seems lean enough and a simple hack vs patching a lib seems preferable
1 change: 1 addition & 0 deletions apps/ledger-live-mobile/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import "./polyfill";
import "./live-common-setup";
import "./iosWebsocketFix";
import { GestureHandlerRootView } from "react-native-gesture-handler";
import React, { Component, useCallback, useMemo, useEffect } from "react";
import { StyleSheet, LogBox, Appearance, AppState } from "react-native";
Expand Down
25 changes: 25 additions & 0 deletions apps/ledger-live-mobile/src/iosWebsocketFix.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Platform } from "react-native";
// @ts-expect-error WebSocketInterceptor is not exposed by react d.ts
import WebSocketInterceptor from "react-native/Libraries/WebSocket/WebSocketInterceptor.js";

// We are adding a missing user-agent header on the websocket for iOS with RN
// https://github.com/facebook/react-native/issues/28450
// https://github.com/facebook/react-native/issues/30727
// We need to use the interceptor as we don't control the code initiating the websocket
// Updating the options passed in by the interceptor works fine
// https://github.com/facebook/react-native/blob/3dfe22bd27429a43b4648c597b71f7965f31ca65/packages/react-native/Libraries/WebSocket/WebSocketInterceptor.js#L148-L163
// Another solution could be to use pnpm to patch react native WebSocket linked below
// https://github.com/facebook/react-native/blob/3dfe22bd27429a43b4648c597b71f7965f31ca65/packages/react-native/Libraries/WebSocket/WebSocket.js
// But the interceptor seems lean enough and a simple hack vs patching a lib seems preferable

if (Platform.OS === "ios") {
WebSocketInterceptor.enableInterception();
WebSocketInterceptor.setConnectCallback(
(_url: string, _protocols: string[] | null, options?: { headers?: Record<string, string> }) => {
if (options) {
if (!options.headers) options.headers = {};
if (!options.headers["User-Agent"]) options.headers["User-Agent"] = "ReactNative";
}
},
);
}

1 comment on commit c4f102d

@github-actions
Copy link

Choose a reason for hiding this comment

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

[Bot] Evm on Staging ($0.00) ⏲ 20s

What is the bot and how does it work? Everything is documented here!

3 critical spec errors

Spec Ethereum failed!

Error: getaddrinfo ENOTFOUND atlas-stg.ledger-test.com

Spec Ethereum Sepolia failed!

Error: getaddrinfo ENOTFOUND atlas-stg.ledger-test.com

Spec Ethereum Holesky failed!

Error: getaddrinfo ENOTFOUND atlas-stg.ledger-test.com
Details of the 0 mutations

Spec Ethereum (failed)


Spec Ethereum Sepolia (failed)


Spec Ethereum Holesky (failed)


Details of the 9 uncovered mutations

Spec Ethereum (3)

  • move 50%:
  • send max:
  • move some ERC20 like (ERC20, BEP20, etc...):

Spec Ethereum Sepolia (3)

  • move 50%:
  • send max:
  • move some ERC20 like (ERC20, BEP20, etc...):

Spec Ethereum Holesky (3)

  • move 50%:
  • send max:
  • move some ERC20 like (ERC20, BEP20, etc...):
Portfolio ($0.00) – Details of the 3 currencies
Spec (accounts) State Remaining Runs (est) funds?
Ethereum (0) 0 ops , 🤷‍♂️ ``
Ethereum Sepolia (0) 0 ops , 🤷‍♂️ ``
Ethereum Holesky (0) 0 ops , 🤷‍♂️ ``

Performance ⏲ 20s

Time spent for each spec: (total across mutations)

Spec (accounts) preload scan re-sync tx status sign op broadcast test destination test
TOTAL 886ms N/A N/A N/A N/A N/A N/A N/A
Ethereum (0) 672ms N/A N/A N/A N/A N/A N/A N/A
Ethereum Sepolia (0) 115ms N/A N/A N/A N/A N/A N/A N/A
Ethereum Holesky (0) 99ms N/A N/A N/A N/A N/A N/A N/A

What is the bot and how does it work? Everything is documented here!

Please sign in to comment.