From dd5d9308e0e3ef8ca78f879c15bc07313ef3c8c4 Mon Sep 17 00:00:00 2001 From: Landry Monga Date: Fri, 5 Jan 2024 18:29:52 +0100 Subject: [PATCH] Remove usage of deprecated navigator.product (#5785) * 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 --- .changeset/big-beds-lie.md | 5 +++++ apps/ledger-live-mobile/jest-setup.js | 1 + libs/ledger-live-common/jest.config.ts | 3 +++ libs/live-network/src/network.ts | 13 +++++++++---- 4 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 .changeset/big-beds-lie.md diff --git a/.changeset/big-beds-lie.md b/.changeset/big-beds-lie.md new file mode 100644 index 000000000000..bbea97804224 --- /dev/null +++ b/.changeset/big-beds-lie.md @@ -0,0 +1,5 @@ +--- +"@ledgerhq/live-network": patch +--- + +Inject https agent in all platform other than mobile diff --git a/apps/ledger-live-mobile/jest-setup.js b/apps/ledger-live-mobile/jest-setup.js index 5edeb8dad424..766087d3476a 100644 --- a/apps/ledger-live-mobile/jest-setup.js +++ b/apps/ledger-live-mobile/jest-setup.js @@ -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))) { diff --git a/libs/ledger-live-common/jest.config.ts b/libs/ledger-live-common/jest.config.ts index 24848e07ede5..e2c286f74c0d 100644 --- a/libs/ledger-live-common/jest.config.ts +++ b/libs/ledger-live-common/jest.config.ts @@ -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"); diff --git a/libs/live-network/src/network.ts b/libs/live-network/src/network.ts index de91e00b8196..6e674270eb77 100644 --- a/libs/live-network/src/network.ts +++ b/libs/live-network/src/network.ts @@ -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-"); +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 }); } @@ -154,7 +159,7 @@ const extractErrorMessage = (raw: string): string | undefined => { const implementation = (arg: AxiosRequestConfig): AxiosPromise => { invariant(typeof arg === "object", "network takes an object as parameter"); - let promise; + let promise: AxiosPromise; if (arg.method === "GET") { if (!("timeout" in arg)) {