Skip to content

Commit

Permalink
Remove usage of deprecated navigator.product (#5785)
Browse files Browse the repository at this point in the history
* remove conditional axios agent

* set https agent if in electron

* revert snapshot

* conditional navigator

* jsdom environement

* use https keep alive if not llm

* clearer condition

* add comments

* explain why keep alive in comment

* snap linebreak

* revert near snpashot changesg

* revert celo snapshot changes

* changeset

* revert arg.timeout existence check

* set test ledger_client_version

* setenv in test

* setEnv beforeAll

* optional getEnv

* no need for beforeAll in hasMinimumFund test
  • Loading branch information
lvndry authored Jan 5, 2024
1 parent 41dffe9 commit dd5d930
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/big-beds-lie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ledgerhq/live-network": patch
---

Inject https agent in all platform other than mobile
1 change: 1 addition & 0 deletions apps/ledger-live-mobile/jest-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ console.error = (...args) => {
}
originalError.call(console, ...args);
};

console.warn = (...args) => {
const warning = args.join();
if (EXCLUDED_WARNINGS.some(excluded => warning.includes(excluded))) {
Expand Down
3 changes: 3 additions & 0 deletions libs/ledger-live-common/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ const testPathIgnorePatterns = [
"cli/",
"test-helpers/",
];

let testRegex = "(/__tests__/.*|(\\.|/)(test|spec))\\.[jt]sx?$";
if (process.env.IGNORE_INTEGRATION_TESTS) {
testPathIgnorePatterns.push(".*\\.integration\\.test\\.[tj]s");
}

if (process.env.ONLY_INTEGRATION_TESTS) {
testRegex = "(/__tests__/.*|(\\.|/)integration\\.(test|spec))\\.[jt]sx?$";
}

const reporters = ["default"];
if (process.env.CI) {
reporters.push("github-actions");
Expand Down
13 changes: 9 additions & 4 deletions libs/live-network/src/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,16 @@ export const errorInterceptor = (error: InterceptedError): InterceptedError => {
axios.interceptors.request.use(requestInterceptor);
axios.interceptors.response.use(responseInterceptor, errorInterceptor);

// not react native
if (!(typeof navigator !== "undefined" && navigator.product === "ReactNative")) {
/**
* We only allow HTTPS agent on platforms other than LLM because
* https library is not compatible with react native
*/
const NETWORK_USE_HTTPS_KEEP_ALIVE = !getEnv("LEDGER_CLIENT_VERSION")?.startsWith("llm-");

This comment has been minimized.

Copy link
@n4l5u0r

n4l5u0r Jan 17, 2024

Hi @lvndry we have an issue with the setEnv of this LEDGER_CLIENT_VERSION value as it tends to reset it back to its default leter on when the lib is loaded in a later component. Even if the react native platform check is executed in the beginning. The reset tends to happen later in the build / code execution process and raise https import lib issue.

Env: simple expo project + metro

cc: @fcipollone-ledger, @cfranceschi-ledger

if (NETWORK_USE_HTTPS_KEEP_ALIVE) {
// the keepAlive is necessary when we make a lot of request in in parallel, especially for bitcoin sync. Otherwise, it may raise "connect ETIMEDOUT" error
// this should only be needed in Windows as UNIX systems reuse TCP packets by default
// refer to https://stackoverflow.com/questions/63064393/getting-axios-error-connect-etimedout-when-making-high-volume-of-calls
// eslint-disable-next-line global-require,@typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-var-requires
const https = require("https");
axios.defaults.httpsAgent = new https.Agent({ keepAlive: true });
}
Expand Down Expand Up @@ -154,7 +159,7 @@ const extractErrorMessage = (raw: string): string | undefined => {

const implementation = <T = any>(arg: AxiosRequestConfig): AxiosPromise<T> => {
invariant(typeof arg === "object", "network takes an object as parameter");
let promise;
let promise: AxiosPromise;

if (arg.method === "GET") {
if (!("timeout" in arg)) {
Expand Down

1 comment on commit dd5d930

@vercel
Copy link

@vercel vercel bot commented on dd5d930 Jan 5, 2024

Choose a reason for hiding this comment

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

Please sign in to comment.