From c8ac662e6f88349187f802741e14c3d5fb67cddb Mon Sep 17 00:00:00 2001 From: Samy Rabah Date: Tue, 3 Sep 2024 17:21:04 +0200 Subject: [PATCH 1/3] Chore/regen pnpmlock + fix axios type in cosmos unit test (#7735) * regen pnpmlock * fix mock type in cosmos unit test and regen pnpm lock --- .changeset/small-penguins-allow.md | 5 + .../coin-cosmos/src/api/Cosmos.unit.test.ts | 122 ++++++++-------- pnpm-lock.yaml | 131 ++++++++++-------- 3 files changed, 146 insertions(+), 112 deletions(-) create mode 100644 .changeset/small-penguins-allow.md diff --git a/.changeset/small-penguins-allow.md b/.changeset/small-penguins-allow.md new file mode 100644 index 000000000000..9b8142c8d50b --- /dev/null +++ b/.changeset/small-penguins-allow.md @@ -0,0 +1,5 @@ +--- +"@ledgerhq/coin-cosmos": patch +--- + +fix mock type in cosmos unit test and regen pnpm lock diff --git a/libs/coin-modules/coin-cosmos/src/api/Cosmos.unit.test.ts b/libs/coin-modules/coin-cosmos/src/api/Cosmos.unit.test.ts index 1a4c15c0ff05..4ca523d7f865 100644 --- a/libs/coin-modules/coin-cosmos/src/api/Cosmos.unit.test.ts +++ b/libs/coin-modules/coin-cosmos/src/api/Cosmos.unit.test.ts @@ -1,12 +1,22 @@ import network from "@ledgerhq/live-network/network"; import { Operation } from "@ledgerhq/types-live"; -import { AxiosResponse } from "axios"; import BigNumber from "bignumber.js"; import cryptoFactory from "../chain/chain"; import { CosmosAPI } from "./Cosmos"; jest.mock("@ledgerhq/live-network/network"); const mockedNetwork = jest.mocked(network); +const mockAxiosResponse = (data: any) => { + return mockedNetwork.mockResolvedValue({ + data, + status: 200, + headers: {} as any, + statusText: "", + config: { + headers: {} as any, + }, + }); +}; describe("CosmosApi", () => { let cosmosApi: CosmosAPI; @@ -21,20 +31,28 @@ describe("CosmosApi", () => { describe("getAccount", () => { it("should return base_account if available", async () => { - mockedNetwork.mockResolvedValue({ - data: { - account: { - account_number: 1, - sequence: 0, - pub_key: { key: "k", "@type": "type" }, - base_account: { - account_number: 2, - sequence: 42, - pub_key: { key: "k2", "@type": "type2" }, + mockedNetwork.mockResolvedValue( + Promise.resolve({ + data: { + account: { + account_number: 1, + sequence: 0, + pub_key: { key: "k", "@type": "type" }, + base_account: { + account_number: 2, + sequence: 42, + pub_key: { key: "k2", "@type": "type2" }, + }, }, }, - }, - } as AxiosResponse); + status: 200, + headers: {} as any, + statusText: "", + config: { + headers: {} as any, + }, + }), + ); const account = await cosmosApi.getAccount("addr"); expect(account.accountNumber).toEqual(2); @@ -44,16 +62,14 @@ describe("CosmosApi", () => { }); it("should return the correct account based on type", async () => { - mockedNetwork.mockResolvedValue({ - data: { - account: { - "@type": "/cosmos.auth.v1beta1.BaseAccount", - account_number: 1, - sequence: 0, - pub_key: { key: "k", "@type": "type" }, - }, + mockAxiosResponse({ + account: { + "@type": "/cosmos.auth.v1beta1.BaseAccount", + account_number: 1, + sequence: 0, + pub_key: { key: "k", "@type": "type" }, }, - } as AxiosResponse); + }); const account = await cosmosApi.getAccount("addr"); expect(account).toEqual({ @@ -63,24 +79,22 @@ describe("CosmosApi", () => { pubKeyType: "type", }); - mockedNetwork.mockResolvedValue({ - data: { - account: { - "@type": "/ethermint.types.v1.EthAccount", - account_number: 1, - sequence: 0, - pub_key: { key: "k", "@type": "type" }, + mockAxiosResponse({ + account: { + "@type": "/ethermint.types.v1.EthAccount", + account_number: 1, + sequence: 0, + pub_key: { key: "k", "@type": "type" }, - base_account: { - address: "address", - pub_key: { key: "k2", "@type": "type2" }, - account_number: 2, - sequence: 3, - }, - code_hash: "codeHash", + base_account: { + address: "address", + pub_key: { key: "k2", "@type": "type2" }, + account_number: 2, + sequence: 3, }, + code_hash: "codeHash", }, - } as AxiosResponse); + }); const ethermintAccount = await cosmosApi.getAccount("addr"); expect(ethermintAccount).toEqual({ @@ -144,9 +158,7 @@ describe("CosmosApi", () => { total: "1", }, }; - mockedNetwork.mockResolvedValue({ - data: getApiResponseSinceSdk041, - } as AxiosResponse); + mockAxiosResponse(getApiResponseSinceSdk041); const cosmosRedelegations = await cosmosApi.getRedelegations("cosmosDelegatorAddress"); expect(cosmosRedelegations[0].amount).toEqual(new BigNumber(100)); expect(cosmosRedelegations[0].completionDate).toEqual(new Date("2023-06-04T15:12:58.567Z")); @@ -180,9 +192,8 @@ describe("CosmosApi", () => { ], pagination: { next_key: null, total: "1" }, }; - mockedNetwork.mockResolvedValue({ - data: getApiResponseSinceSdk046, - } as AxiosResponse); + + mockAxiosResponse(getApiResponseSinceSdk046); const cosmosRedelegations = await cosmosApi.getRedelegations("cosmosDelegatorAddress"); expect(cosmosRedelegations[0].amount).toEqual(new BigNumber(100)); @@ -194,9 +205,7 @@ describe("CosmosApi", () => { }); it("should return no redelegations if there are none", async () => { - mockedNetwork.mockResolvedValue({ - data: { redelegation_responses: [], pagination: { next_key: null, total: "0" } }, - } as AxiosResponse); + mockAxiosResponse({ redelegation_responses: [], pagination: { next_key: null, total: "0" } }); const cosmosRedelegations = await cosmosApi.getRedelegations("cosmosDelegatorAddress"); expect(cosmosRedelegations.length).toEqual(0); @@ -205,21 +214,20 @@ describe("CosmosApi", () => { describe("simulate", () => { it("should return gas used when the network call returns gas used", async () => { - mockedNetwork.mockResolvedValue({ - data: { - gas_info: { - gas_used: 42000, - }, + mockAxiosResponse({ + gas_info: { + gas_used: 42000, }, - } as AxiosResponse); + }); const gas = await cosmosApi.simulate([]); expect(gas).toEqual(new BigNumber(42000)); }); it("should throw an error when the network call does not return gas used", async () => { - mockedNetwork.mockResolvedValue({ - data: { gas_info: {} }, - } as AxiosResponse); + mockAxiosResponse({ + gas_info: {}, + }); + await expect(cosmosApi.simulate([])).rejects.toThrowError(); }); @@ -590,9 +598,7 @@ describe("CosmosApi", () => { describe("broadcastTransaction", () => { it("should throw a SequenceNumberError exception in case of sequence number error", async () => { - mockedNetwork.mockResolvedValue({ - data: { tx_response: { code: 32 } }, - } as AxiosResponse); + mockAxiosResponse({ tx_response: { code: 32 } }); await expect( cosmosApi.broadcast({ signedOperation: { operation: {} as Operation, signature: "signedOperation" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b6df4361d036..0644a0d8d6fc 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -15694,6 +15694,9 @@ packages: axios@0.24.0: resolution: {integrity: sha512-Q6cWsys88HoPgAaFAVUb0WpPk0O8iTeisR9IMqy9G8AbO4NlpVknrnQS03zzF9PGAWgO3cgletO3VjV/P7VztA==} + axios@0.26.1: + resolution: {integrity: sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA==} + axios@1.7.3: resolution: {integrity: sha512-Ar7ND9pU99eJ9GpoGQKhKf58GpUOgnzuaB7ueNQ5BMi0p+LZ5oaEnfF999fAArcTIBwXTCHAmGcHOZJaWPq9Nw==} @@ -16122,6 +16125,10 @@ packages: brace-expansion@2.0.1: resolution: {integrity: sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==} + braces@3.0.2: + resolution: {integrity: sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==} + engines: {node: '>=8'} + braces@3.0.3: resolution: {integrity: sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==} engines: {node: '>=8'} @@ -19590,6 +19597,10 @@ packages: resolution: {integrity: sha512-pjmC+bkIF8XI7fWaH8KxHcZL3DPybs1roSKP4rKDvy20tAWwIObE4+JIseG2byfGKhud5ZnM4YSGKBz7Sh0ndQ==} engines: {node: '>= 0.4.0'} + fill-range@7.0.1: + resolution: {integrity: sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==} + engines: {node: '>=8'} + fill-range@7.1.1: resolution: {integrity: sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==} engines: {node: '>=8'} @@ -31576,7 +31587,7 @@ snapshots: '@babel/template@7.24.0': dependencies: - '@babel/code-frame': 7.24.6 + '@babel/code-frame': 7.24.2 '@babel/parser': 7.24.1 '@babel/types': 7.24.0 @@ -34180,7 +34191,7 @@ snapshots: find-up: 5.0.0 find-yarn-workspace-root: 2.0.0 js-yaml: 3.14.1 - micromatch: 4.0.7 + micromatch: 4.0.5 npm-package-arg: 7.0.0 split: 1.0.1 sudo-prompt: 9.1.1 @@ -34194,7 +34205,7 @@ snapshots: find-up: 5.0.0 find-yarn-workspace-root: 2.0.0 js-yaml: 3.14.1 - micromatch: 4.0.7 + micromatch: 4.0.5 npm-package-arg: 7.0.0 ora: 3.4.0 split: 1.0.1 @@ -34966,7 +34977,7 @@ snapshots: jest-util: 27.5.1 jest-validate: 27.5.1 jest-watcher: 27.5.1 - micromatch: 4.0.7 + micromatch: 4.0.5 rimraf: 3.0.2 slash: 3.0.0 strip-ansi: 6.0.1 @@ -35040,7 +35051,7 @@ snapshots: jest-util: 29.7.0 jest-validate: 29.7.0 jest-watcher: 29.7.0 - micromatch: 4.0.7 + micromatch: 4.0.5 pretty-format: 29.7.0 slash: 3.0.0 strip-ansi: 6.0.1 @@ -35076,7 +35087,7 @@ snapshots: jest-util: 29.7.0 jest-validate: 29.7.0 jest-watcher: 29.7.0 - micromatch: 4.0.7 + micromatch: 4.0.5 pretty-format: 29.7.0 slash: 3.0.0 strip-ansi: 6.0.1 @@ -35112,7 +35123,7 @@ snapshots: jest-util: 29.7.0 jest-validate: 29.7.0 jest-watcher: 29.7.0 - micromatch: 4.0.7 + micromatch: 4.0.5 pretty-format: 29.7.0 slash: 3.0.0 strip-ansi: 6.0.1 @@ -35148,7 +35159,7 @@ snapshots: jest-util: 29.7.0 jest-validate: 29.7.0 jest-watcher: 29.7.0 - micromatch: 4.0.7 + micromatch: 4.0.5 pretty-format: 29.7.0 slash: 3.0.0 strip-ansi: 6.0.1 @@ -35184,7 +35195,7 @@ snapshots: jest-util: 29.7.0 jest-validate: 29.7.0 jest-watcher: 29.7.0 - micromatch: 4.0.7 + micromatch: 4.0.5 pretty-format: 29.7.0 slash: 3.0.0 strip-ansi: 6.0.1 @@ -35220,7 +35231,7 @@ snapshots: jest-util: 29.7.0 jest-validate: 29.7.0 jest-watcher: 29.7.0 - micromatch: 4.0.7 + micromatch: 4.0.5 pretty-format: 29.7.0 slash: 3.0.0 strip-ansi: 6.0.1 @@ -35256,7 +35267,7 @@ snapshots: jest-util: 29.7.0 jest-validate: 29.7.0 jest-watcher: 29.7.0 - micromatch: 4.0.7 + micromatch: 4.0.5 pretty-format: 29.7.0 slash: 3.0.0 strip-ansi: 6.0.1 @@ -35292,7 +35303,7 @@ snapshots: jest-util: 29.7.0 jest-validate: 29.7.0 jest-watcher: 29.7.0 - micromatch: 4.0.7 + micromatch: 4.0.5 pretty-format: 29.7.0 slash: 3.0.0 strip-ansi: 6.0.1 @@ -35582,7 +35593,7 @@ snapshots: jest-haste-map: 27.5.1 jest-regex-util: 27.5.1 jest-util: 27.5.1 - micromatch: 4.0.7 + micromatch: 4.0.5 pirates: 4.0.6 slash: 3.0.0 source-map: 0.6.1 @@ -35604,7 +35615,7 @@ snapshots: jest-haste-map: 28.1.3 jest-regex-util: 28.0.2 jest-util: 28.1.3 - micromatch: 4.0.7 + micromatch: 4.0.5 pirates: 4.0.6 slash: 3.0.0 write-file-atomic: 4.0.2 @@ -35625,7 +35636,7 @@ snapshots: jest-haste-map: 29.7.0 jest-regex-util: 29.6.3 jest-util: 29.7.0 - micromatch: 4.0.7 + micromatch: 4.0.5 pirates: 4.0.6 slash: 3.0.0 write-file-atomic: 4.0.2 @@ -35646,7 +35657,7 @@ snapshots: jest-haste-map: 29.7.0(metro@0.80.8) jest-regex-util: 29.6.3 jest-util: 29.7.0 - micromatch: 4.0.7 + micromatch: 4.0.5 pirates: 4.0.6 slash: 3.0.0 write-file-atomic: 4.0.2 @@ -41261,7 +41272,7 @@ snapshots: endent: 2.1.0 find-cache-dir: 3.3.2 flat-cache: 3.2.0 - micromatch: 4.0.7 + micromatch: 4.0.5 react-docgen-typescript: 2.2.2(typescript@5.4.3) tslib: 2.6.2 typescript: 5.4.3 @@ -41275,7 +41286,7 @@ snapshots: endent: 2.1.0 find-cache-dir: 3.3.2 flat-cache: 3.2.0 - micromatch: 4.0.7 + micromatch: 4.0.5 react-docgen-typescript: 2.2.2(typescript@5.4.3) tslib: 2.6.2 typescript: 5.4.3 @@ -44328,6 +44339,10 @@ snapshots: dependencies: follow-redirects: 1.15.6 + axios@0.26.1: + dependencies: + follow-redirects: 1.15.6 + axios@1.7.3: dependencies: follow-redirects: 1.15.6 @@ -45071,6 +45086,10 @@ snapshots: dependencies: balanced-match: 1.0.2 + braces@3.0.2: + dependencies: + fill-range: 7.0.1 + braces@3.0.3: dependencies: fill-range: 7.1.1 @@ -45599,7 +45618,7 @@ snapshots: chokidar@3.6.0: dependencies: anymatch: 3.1.3 - braces: 3.0.3 + braces: 3.0.2 glob-parent: 5.1.2 is-binary-path: 2.1.0 is-glob: 4.0.3 @@ -47749,7 +47768,7 @@ snapshots: function.prototype.name: 1.1.6 get-intrinsic: 1.2.4 get-symbol-description: 1.0.2 - globalthis: 1.0.3 + globalthis: 1.0.4 gopd: 1.0.1 has-property-descriptors: 1.0.2 has-proto: 1.0.3 @@ -47810,7 +47829,7 @@ snapshots: es-set-tostringtag: 2.0.3 function-bind: 1.1.2 get-intrinsic: 1.2.4 - globalthis: 1.0.4 + globalthis: 1.0.3 has-property-descriptors: 1.0.2 has-proto: 1.0.3 has-symbols: 1.0.3 @@ -48481,7 +48500,7 @@ snapshots: '@types/eslint': 8.56.6 eslint: 8.57.0 jest-worker: 28.1.3 - micromatch: 4.0.7 + micromatch: 4.0.5 normalize-path: 3.0.0 schema-utils: 4.2.0 webpack: 5.94.0 @@ -49398,7 +49417,7 @@ snapshots: '@nodelib/fs.walk': 1.2.8 glob-parent: 5.1.2 merge2: 1.4.1 - micromatch: 4.0.7 + micromatch: 4.0.5 fast-json-parse@1.0.3: {} @@ -49527,6 +49546,10 @@ snapshots: filesize@8.0.7: {} + fill-range@7.0.1: + dependencies: + to-regex-range: 5.0.1 + fill-range@7.1.1: dependencies: to-regex-range: 5.0.1 @@ -49616,7 +49639,7 @@ snapshots: find-yarn-workspace-root@2.0.0: dependencies: - micromatch: 4.0.7 + micromatch: 4.0.5 firebase@9.23.0: dependencies: @@ -50787,7 +50810,7 @@ snapshots: http-proxy: 1.18.1 is-glob: 4.0.3 is-plain-obj: 3.0.0 - micromatch: 4.0.7 + micromatch: 4.0.5 optionalDependencies: '@types/express': 4.17.21 @@ -51988,7 +52011,7 @@ snapshots: jest-runner: 28.1.3 jest-util: 28.1.3 jest-validate: 28.1.3 - micromatch: 4.0.7 + micromatch: 4.0.5 parse-json: 5.2.0 pretty-format: 28.1.3 slash: 3.0.0 @@ -52018,7 +52041,7 @@ snapshots: jest-runner: 28.1.3 jest-util: 28.1.3 jest-validate: 28.1.3 - micromatch: 4.0.7 + micromatch: 4.0.5 parse-json: 5.2.0 pretty-format: 28.1.3 slash: 3.0.0 @@ -52048,7 +52071,7 @@ snapshots: jest-runner: 29.7.0 jest-util: 29.7.0 jest-validate: 29.7.0 - micromatch: 4.0.7 + micromatch: 4.0.5 parse-json: 5.2.0 pretty-format: 29.7.0 slash: 3.0.0 @@ -52077,7 +52100,7 @@ snapshots: jest-runner: 29.7.0 jest-util: 29.7.0 jest-validate: 29.7.0 - micromatch: 4.0.7 + micromatch: 4.0.5 parse-json: 5.2.0 pretty-format: 29.7.0 slash: 3.0.0 @@ -52109,7 +52132,7 @@ snapshots: jest-runner: 29.7.0 jest-util: 29.7.0 jest-validate: 29.7.0 - micromatch: 4.0.7 + micromatch: 4.0.5 parse-json: 5.2.0 pretty-format: 29.7.0 slash: 3.0.0 @@ -52140,7 +52163,7 @@ snapshots: jest-runner: 29.7.0 jest-util: 29.7.0 jest-validate: 29.7.0 - micromatch: 4.0.7 + micromatch: 4.0.5 parse-json: 5.2.0 pretty-format: 29.7.0 slash: 3.0.0 @@ -52172,7 +52195,7 @@ snapshots: jest-runner: 29.7.0 jest-util: 29.7.0 jest-validate: 29.7.0 - micromatch: 4.0.7 + micromatch: 4.0.5 parse-json: 5.2.0 pretty-format: 29.7.0 slash: 3.0.0 @@ -52204,7 +52227,7 @@ snapshots: jest-runner: 29.7.0 jest-util: 29.7.0 jest-validate: 29.7.0 - micromatch: 4.0.7 + micromatch: 4.0.5 parse-json: 5.2.0 pretty-format: 29.7.0 slash: 3.0.0 @@ -52236,7 +52259,7 @@ snapshots: jest-runner: 29.7.0 jest-util: 29.7.0 jest-validate: 29.7.0 - micromatch: 4.0.7 + micromatch: 4.0.5 parse-json: 5.2.0 pretty-format: 29.7.0 slash: 3.0.0 @@ -52268,7 +52291,7 @@ snapshots: jest-runner: 29.7.0 jest-util: 29.7.0 jest-validate: 29.7.0 - micromatch: 4.0.7 + micromatch: 4.0.5 parse-json: 5.2.0 pretty-format: 29.7.0 slash: 3.0.0 @@ -52300,7 +52323,7 @@ snapshots: jest-runner: 29.7.0 jest-util: 29.7.0 jest-validate: 29.7.0 - micromatch: 4.0.7 + micromatch: 4.0.5 parse-json: 5.2.0 pretty-format: 29.7.0 slash: 3.0.0 @@ -52332,7 +52355,7 @@ snapshots: jest-runner: 29.7.0 jest-util: 29.7.0 jest-validate: 29.7.0 - micromatch: 4.0.7 + micromatch: 4.0.5 parse-json: 5.2.0 pretty-format: 29.7.0 slash: 3.0.0 @@ -52364,7 +52387,7 @@ snapshots: jest-runner: 29.7.0 jest-util: 29.7.0 jest-validate: 29.7.0 - micromatch: 4.0.7 + micromatch: 4.0.5 parse-json: 5.2.0 pretty-format: 29.7.0 slash: 3.0.0 @@ -52395,7 +52418,7 @@ snapshots: jest-runner: 29.7.0 jest-util: 29.7.0 jest-validate: 29.7.0 - micromatch: 4.0.7 + micromatch: 4.0.5 parse-json: 5.2.0 pretty-format: 29.7.0 slash: 3.0.0 @@ -52589,7 +52612,7 @@ snapshots: jest-serializer: 27.5.1 jest-util: 27.5.1 jest-worker: 27.5.1 - micromatch: 4.0.7 + micromatch: 4.0.5 walker: 1.0.8 optionalDependencies: fsevents: 2.3.3 @@ -52607,7 +52630,7 @@ snapshots: jest-regex-util: 28.0.2 jest-util: 28.1.3 jest-worker: 28.1.3 - micromatch: 4.0.7 + micromatch: 4.0.5 walker: 1.0.8 optionalDependencies: fsevents: 2.3.3 @@ -52625,7 +52648,7 @@ snapshots: jest-regex-util: 29.6.3 jest-util: 29.7.0 jest-worker: 29.7.0 - micromatch: 4.0.7 + micromatch: 4.0.5 walker: 1.0.8 optionalDependencies: fsevents: 2.3.3 @@ -52643,7 +52666,7 @@ snapshots: jest-regex-util: 29.6.3 jest-util: 29.7.0 jest-worker: 29.7.0(metro@0.80.8) - micromatch: 4.0.7 + micromatch: 4.0.5 walker: 1.0.8 optionalDependencies: fsevents: 2.3.3 @@ -52716,7 +52739,7 @@ snapshots: '@types/stack-utils': 2.0.3 chalk: 4.1.2 graceful-fs: 4.2.11 - micromatch: 4.0.7 + micromatch: 4.0.5 pretty-format: 27.5.1 slash: 3.0.0 stack-utils: 2.0.6 @@ -52728,19 +52751,19 @@ snapshots: '@types/stack-utils': 2.0.3 chalk: 4.1.2 graceful-fs: 4.2.11 - micromatch: 4.0.7 + micromatch: 4.0.5 pretty-format: 28.1.3 slash: 3.0.0 stack-utils: 2.0.6 jest-message-util@29.7.0: dependencies: - '@babel/code-frame': 7.24.6 + '@babel/code-frame': 7.24.2 '@jest/types': 29.6.3 '@types/stack-utils': 2.0.3 chalk: 4.1.2 graceful-fs: 4.2.11 - micromatch: 4.0.7 + micromatch: 4.0.5 pretty-format: 29.7.0 slash: 3.0.0 stack-utils: 2.0.6 @@ -53525,7 +53548,7 @@ snapshots: chalk: 4.1.2 flow-parser: 0.232.0 graceful-fs: 4.2.11 - micromatch: 4.0.7 + micromatch: 4.0.5 neo-async: 2.6.2 node-dir: 0.1.17 recast: 0.21.5 @@ -53550,7 +53573,7 @@ snapshots: chalk: 4.1.2 flow-parser: 0.232.0 graceful-fs: 4.2.11 - micromatch: 4.0.7 + micromatch: 4.0.5 neo-async: 2.6.2 node-dir: 0.1.17 recast: 0.21.5 @@ -53575,7 +53598,7 @@ snapshots: chalk: 4.1.2 flow-parser: 0.232.0 graceful-fs: 4.2.11 - micromatch: 4.0.7 + micromatch: 4.0.5 neo-async: 2.6.2 node-dir: 0.1.17 recast: 0.23.6 @@ -55087,7 +55110,7 @@ snapshots: graceful-fs: 4.2.11 invariant: 2.2.4 jest-worker: 29.7.0(metro@0.80.8) - micromatch: 4.0.7 + micromatch: 4.0.5 node-abort-controller: 3.1.1 nullthrows: 1.1.1 walker: 1.0.8 @@ -55716,7 +55739,7 @@ snapshots: micromatch@4.0.5: dependencies: - braces: 3.0.3 + braces: 3.0.2 picomatch: 2.3.1 micromatch@4.0.7: @@ -61386,7 +61409,7 @@ snapshots: is-glob: 4.0.3 jiti: 1.21.0 lilconfig: 2.1.0 - micromatch: 4.0.7 + micromatch: 4.0.5 normalize-path: 3.0.0 object-hash: 3.0.0 picocolors: 1.0.0 @@ -62130,7 +62153,7 @@ snapshots: dependencies: chalk: 4.1.2 enhanced-resolve: 5.16.0 - micromatch: 4.0.7 + micromatch: 4.0.5 semver: 7.6.3 source-map: 0.7.4 typescript: 5.1.3 From f5c88915cd5642e0bdce8ffb3ea1abe32e249f9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Grellard?= Date: Tue, 3 Sep 2024 17:22:58 +0200 Subject: [PATCH 2/3] Feat/llm ledger sync redirection on sync again (#7729) feat(llm): Ledger sync redirect to qr code method on sync again --- .changeset/strange-shrimps-clean.md | 5 +++++ apps/ledger-live-mobile/src/actions/types.ts | 8 ++++++- .../src/actions/walletSync.ts | 10 ++++++++- .../AddAccount/components/StepFlow.tsx | 12 +++++------ .../Accounts/screens/AddAccount/index.tsx | 6 ++---- .../AddAccount/useAddAccountViewModel.ts | 19 +++++++++-------- ...synchronizeWithQrCode.integration.test.tsx | 2 -- .../components/Activation/ActivationFlow.tsx | 8 +++---- .../WalletSync/hooks/useCurrentStep.ts | 21 +++++++++++++++++++ .../WalletSync/hooks/useQRCodeHost.ts | 6 +++--- .../WalletSync/hooks/useSyncWithQrCode.ts | 10 ++++----- .../screens/Activation/ActivationDrawer.tsx | 4 ---- .../screens/Activation/ActivationSuccess.tsx | 13 +++++++++++- .../Activation/useActivationDrawerModel.ts | 13 ++++++------ apps/ledger-live-mobile/src/reducers/types.ts | 2 ++ .../src/reducers/walletSync.ts | 9 ++++++++ .../Settings/General/WalletSyncRow.tsx | 5 ++++- 17 files changed, 103 insertions(+), 50 deletions(-) create mode 100644 .changeset/strange-shrimps-clean.md create mode 100644 apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/useCurrentStep.ts diff --git a/.changeset/strange-shrimps-clean.md b/.changeset/strange-shrimps-clean.md new file mode 100644 index 000000000000..673b5f34c85e --- /dev/null +++ b/.changeset/strange-shrimps-clean.md @@ -0,0 +1,5 @@ +--- +"live-mobile": minor +--- + +LLM - Ledger Sync redirects to Qr code when syncing again after a successful sync diff --git a/apps/ledger-live-mobile/src/actions/types.ts b/apps/ledger-live-mobile/src/actions/types.ts index bc1686033660..a4e20fdd3dd9 100644 --- a/apps/ledger-live-mobile/src/actions/types.ts +++ b/apps/ledger-live-mobile/src/actions/types.ts @@ -36,6 +36,7 @@ import type { import type { Unpacked } from "../types/helpers"; import { HandlersPayloads } from "@ledgerhq/live-wallet/store"; import { ImportAccountsReduceInput } from "@ledgerhq/live-wallet/liveqr/importAccounts"; +import { Steps } from "LLM/features/WalletSync/types/Activation"; // === ACCOUNTS ACTIONS === @@ -530,11 +531,16 @@ export type MarketPayload = export enum WalletSyncActionTypes { WALLET_SYNC_SET_MANAGE_KEY_DRAWER = "WALLET_SYNC_SET_MANAGE_KEY_DRAWER", LEDGER_SYNC_SET_ACTIVATE_DRAWER = "LEDGER_SYNC_SET_ACTIVATE_DRAWER", + LEDGER_SYNC_SET_ACTIVATE_STEP = "LEDGER_SYNC_SET_ACTIVATE_STEP", } export type WalletSyncSetManageKeyDrawerPayload = boolean; export type WalletSyncSetActivateDrawer = boolean; -export type WalletSyncPayload = WalletSyncSetManageKeyDrawerPayload | WalletSyncSetActivateDrawer; +export type WalletSyncSetActivateStep = Steps; +export type WalletSyncPayload = + | WalletSyncSetManageKeyDrawerPayload + | WalletSyncSetActivateDrawer + | WalletSyncSetActivateStep; // === PAYLOADS === diff --git a/apps/ledger-live-mobile/src/actions/walletSync.ts b/apps/ledger-live-mobile/src/actions/walletSync.ts index 49563fdbcc15..70943a527383 100644 --- a/apps/ledger-live-mobile/src/actions/walletSync.ts +++ b/apps/ledger-live-mobile/src/actions/walletSync.ts @@ -1,6 +1,10 @@ import { createAction } from "redux-actions"; import { WalletSyncActionTypes } from "./types"; -import type { WalletSyncSetActivateDrawer, WalletSyncSetManageKeyDrawerPayload } from "./types"; +import type { + WalletSyncSetActivateDrawer, + WalletSyncSetActivateStep, + WalletSyncSetManageKeyDrawerPayload, +} from "./types"; export const setWallectSyncManageKeyDrawer = createAction( WalletSyncActionTypes.WALLET_SYNC_SET_MANAGE_KEY_DRAWER, @@ -9,3 +13,7 @@ export const setWallectSyncManageKeyDrawer = createAction( WalletSyncActionTypes.LEDGER_SYNC_SET_ACTIVATE_DRAWER, ); + +export const setLedgerSyncActivateStep = createAction( + WalletSyncActionTypes.LEDGER_SYNC_SET_ACTIVATE_STEP, +); diff --git a/apps/ledger-live-mobile/src/newArch/features/Accounts/screens/AddAccount/components/StepFlow.tsx b/apps/ledger-live-mobile/src/newArch/features/Accounts/screens/AddAccount/components/StepFlow.tsx index d0e6b600d21d..3b6aa7cc300b 100644 --- a/apps/ledger-live-mobile/src/newArch/features/Accounts/screens/AddAccount/components/StepFlow.tsx +++ b/apps/ledger-live-mobile/src/newArch/features/Accounts/screens/AddAccount/components/StepFlow.tsx @@ -11,14 +11,13 @@ import PinCodeDisplay from "LLM/features/WalletSync/screens/Synchronize/PinCodeD import PinCodeInput from "LLM/features/WalletSync/screens/Synchronize/PinCodeInput"; import { useInitMemberCredentials } from "LLM/features/WalletSync/hooks/useInitMemberCredentials"; import { useSyncWithQrCode } from "LLM/features/WalletSync/hooks/useSyncWithQrCode"; -import { SpecificError } from "~/newArch/features/WalletSync/components/Error/SpecificError"; -import { ErrorReason } from "~/newArch/features/WalletSync/hooks/useSpecificError"; +import { SpecificError } from "LLM/features/WalletSync/components/Error/SpecificError"; +import { ErrorReason } from "LLM/features/WalletSync/hooks/useSpecificError"; +import { useCurrentStep } from "LLM/features/WalletSync/hooks/useCurrentStep"; type Props = { - currentStep: Steps; currency?: CryptoCurrency | TokenCurrency | null; doesNotHaveAccount?: boolean; - setCurrentStep: (step: Steps) => void; setCurrentOption: (option: Options) => void; currentOption: Options; navigateToChooseSyncMethod: () => void; @@ -36,23 +35,22 @@ type Props = { const StepFlow = ({ doesNotHaveAccount, currency, - currentStep, setCurrentOption, currentOption, navigateToChooseSyncMethod, navigateToQrCodeMethod, onQrCodeScanned, qrProcess, - setCurrentStep, onCreateKey, }: Props) => { + const { currentStep, setCurrentStep } = useCurrentStep(); const { memberCredentials } = useInitMemberCredentials(); const { handleStart, handleSendDigits, inputCallback, nbDigits } = useSyncWithQrCode(); const handleQrCodeScanned = (data: string) => { onQrCodeScanned(); - if (memberCredentials) handleStart(data, memberCredentials, setCurrentStep); + if (memberCredentials) handleStart(data, memberCredentials); }; const handlePinCodeSubmit = (input: string) => { diff --git a/apps/ledger-live-mobile/src/newArch/features/Accounts/screens/AddAccount/index.tsx b/apps/ledger-live-mobile/src/newArch/features/Accounts/screens/AddAccount/index.tsx index 6e282ba63400..eec0ef8475a4 100644 --- a/apps/ledger-live-mobile/src/newArch/features/Accounts/screens/AddAccount/index.tsx +++ b/apps/ledger-live-mobile/src/newArch/features/Accounts/screens/AddAccount/index.tsx @@ -6,6 +6,7 @@ import DrawerHeader from "LLM/features/WalletSync/components/Synchronize/DrawerH import { Flex } from "@ledgerhq/native-ui"; import StepFlow from "./components/StepFlow"; import { Steps } from "LLM/features/WalletSync/types/Activation"; +import { useCurrentStep } from "LLM/features/WalletSync/hooks/useCurrentStep"; type ViewProps = ReturnType & AddAccountProps; @@ -21,10 +22,8 @@ function View({ doesNotHaveAccount, currency, onCloseAddAccountDrawer, - currentStep, onGoBack, currentOption, - setCurrentStep, setCurrentOption, navigateToChooseSyncMethod, navigateToQrCodeMethod, @@ -32,6 +31,7 @@ function View({ onQrCodeScanned, onCreateKey, }: ViewProps) { + const { currentStep } = useCurrentStep(); const CustomDrawerHeader = () => ; return ( @@ -46,8 +46,6 @@ function View({ { - const [currentStep, setCurrentStep] = useState(startingStep); + const { currentStep, setCurrentStep } = useCurrentStep(); const [currentOption, setCurrentOption] = useState(Options.SCAN); const navigateToChooseSyncMethod = () => setCurrentStep(Steps.ChooseSyncMethod); const navigateToQrCodeMethod = () => setCurrentStep(Steps.QrCodeMethod); const navigation = useNavigation(); - const onGoBack = () => setCurrentStep(prevStep => getPreviousStep(prevStep)); + const onGoBack = () => setCurrentStep(getPreviousStep(currentStep)); + + useEffect(() => { + setCurrentStep(startingStep); + }, [setCurrentStep]); const reset = () => { setCurrentStep(startingStep); @@ -49,15 +54,13 @@ const useAddAccountViewModel = ({ isOpened, onClose }: AddAccountDrawerProps) => }); }, []); - const onCloseAddAccountDrawer = useCallback(() => { + const onCloseAddAccountDrawer = () => { trackButtonClick("Close 'x'"); onClose(); reset(); - }, [trackButtonClick, onClose]); + }; const { url, error, isLoading, pinCode } = useQRCodeHost({ - setCurrentStep, - currentStep, currentOption, }); @@ -74,10 +77,8 @@ const useAddAccountViewModel = ({ isOpened, onClose }: AddAccountDrawerProps) => onCloseAddAccountDrawer, navigateToQrCodeMethod, navigateToChooseSyncMethod, - currentStep, setCurrentOption, currentOption, - setCurrentStep, onQrCodeScanned, onGoBack, qrProcess: { diff --git a/apps/ledger-live-mobile/src/newArch/features/WalletSync/__integrations__/synchronizeWithQrCode.integration.test.tsx b/apps/ledger-live-mobile/src/newArch/features/WalletSync/__integrations__/synchronizeWithQrCode.integration.test.tsx index 499c64c42212..c2eb0e0fe71d 100644 --- a/apps/ledger-live-mobile/src/newArch/features/WalletSync/__integrations__/synchronizeWithQrCode.integration.test.tsx +++ b/apps/ledger-live-mobile/src/newArch/features/WalletSync/__integrations__/synchronizeWithQrCode.integration.test.tsx @@ -6,8 +6,6 @@ import getWalletSyncEnvironmentParams from "@ledgerhq/live-common/walletSync/get jest.mock("../hooks/useQRCodeHost", () => ({ useQRCodeHost: () => ({ - setCurrentStep: jest.fn(), - currentStep: jest.fn(), currentOption: jest.fn(), url: "ledger.com", }), diff --git a/apps/ledger-live-mobile/src/newArch/features/WalletSync/components/Activation/ActivationFlow.tsx b/apps/ledger-live-mobile/src/newArch/features/WalletSync/components/Activation/ActivationFlow.tsx index f45c01ec6e11..e20286db7b2b 100644 --- a/apps/ledger-live-mobile/src/newArch/features/WalletSync/components/Activation/ActivationFlow.tsx +++ b/apps/ledger-live-mobile/src/newArch/features/WalletSync/components/Activation/ActivationFlow.tsx @@ -12,9 +12,9 @@ import { useInitMemberCredentials } from "../../hooks/useInitMemberCredentials"; import { useSyncWithQrCode } from "../../hooks/useSyncWithQrCode"; import { SpecificError } from "../Error/SpecificError"; import { ErrorReason } from "../../hooks/useSpecificError"; +import { useCurrentStep } from "../../hooks/useCurrentStep"; type Props = { - currentStep: Steps; navigateToChooseSyncMethod: () => void; navigateToQrCodeMethod: () => void; qrProcess: { @@ -26,28 +26,26 @@ type Props = { onQrCodeScanned: () => void; currentOption: Options; setOption: (option: Options) => void; - setCurrentStep: (step: Steps) => void; onCreateKey: () => void; }; const ActivationFlow = ({ - currentStep, navigateToChooseSyncMethod, navigateToQrCodeMethod, qrProcess, currentOption, setOption, onQrCodeScanned, - setCurrentStep, onCreateKey, }: Props) => { + const { currentStep, setCurrentStep } = useCurrentStep(); const { memberCredentials } = useInitMemberCredentials(); const { handleStart, handleSendDigits, inputCallback, nbDigits } = useSyncWithQrCode(); const handleQrCodeScanned = (data: string) => { onQrCodeScanned(); - if (memberCredentials) handleStart(data, memberCredentials, setCurrentStep); + if (memberCredentials) handleStart(data, memberCredentials); }; const handlePinCodeSubmit = (input: string) => { diff --git a/apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/useCurrentStep.ts b/apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/useCurrentStep.ts new file mode 100644 index 000000000000..f06b9bd28015 --- /dev/null +++ b/apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/useCurrentStep.ts @@ -0,0 +1,21 @@ +import { useDispatch, useSelector } from "react-redux"; +import { activateDrawerStepSelector } from "~/reducers/walletSync"; +import { Steps } from "../types/Activation"; +import { setLedgerSyncActivateStep } from "~/actions/walletSync"; +import { useCallback } from "react"; + +export function useCurrentStep() { + const dispatch = useDispatch(); + const currentStep = useSelector(activateDrawerStepSelector); + const setCurrentStep = useCallback( + (step: Steps) => { + dispatch(setLedgerSyncActivateStep(step)); + }, + [dispatch], + ); + + return { + currentStep, + setCurrentStep, + }; +} diff --git a/apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/useQRCodeHost.ts b/apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/useQRCodeHost.ts index 64475771ac4b..5f0cff1a9f9e 100644 --- a/apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/useQRCodeHost.ts +++ b/apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/useQRCodeHost.ts @@ -21,16 +21,16 @@ import getWalletSyncEnvironmentParams from "@ledgerhq/live-common/walletSync/get import { useMutation, useQueryClient } from "@tanstack/react-query"; import { QueryKey } from "./type.hooks"; import { useInstanceName } from "./useInstanceName"; +import { useCurrentStep } from "./useCurrentStep"; const MIN_TIME_TO_REFRESH = 30_000; interface Props { - setCurrentStep: (step: Steps) => void; - currentStep: Steps; currentOption: Options; } -export function useQRCodeHost({ setCurrentStep, currentStep, currentOption }: Props) { +export function useQRCodeHost({ currentOption }: Props) { + const { currentStep, setCurrentStep } = useCurrentStep(); const queryClient = useQueryClient(); const trustchain = useSelector(trustchainSelector); const memberCredentials = useSelector(memberCredentialsSelector); diff --git a/apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/useSyncWithQrCode.ts b/apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/useSyncWithQrCode.ts index b116cb0e6cda..08ed51acac13 100644 --- a/apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/useSyncWithQrCode.ts +++ b/apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/useSyncWithQrCode.ts @@ -14,8 +14,10 @@ import { Steps } from "../types/Activation"; import { NavigatorName, ScreenName } from "~/const"; import { useInstanceName } from "./useInstanceName"; import { useTrustchainSdk } from "./useTrustchainSdk"; +import { useCurrentStep } from "./useCurrentStep"; export const useSyncWithQrCode = () => { + const { setCurrentStep } = useCurrentStep(); const [nbDigits, setDigits] = useState(null); const [input, setInput] = useState(null); const instanceName = useInstanceName(); @@ -48,11 +50,7 @@ export const useSyncWithQrCode = () => { }, [navigation]); const handleStart = useCallback( - async ( - url: string, - memberCredentials: MemberCredentials, - setCurrentStep: (step: Steps) => void, - ) => { + async (url: string, memberCredentials: MemberCredentials) => { try { const newTrustchain = await createQRCodeCandidateInstance({ memberCredentials, @@ -94,7 +92,7 @@ export const useSyncWithQrCode = () => { throw e; } }, - [instanceName, onRequestQRCodeInput, trustchain, dispatch, onSyncFinished, sdk], + [instanceName, onRequestQRCodeInput, trustchain, onSyncFinished, sdk, dispatch, setCurrentStep], ); const handleSendDigits = useCallback( diff --git a/apps/ledger-live-mobile/src/newArch/features/WalletSync/screens/Activation/ActivationDrawer.tsx b/apps/ledger-live-mobile/src/newArch/features/WalletSync/screens/Activation/ActivationDrawer.tsx index 91f405e4b8a4..4eb884cfe76f 100644 --- a/apps/ledger-live-mobile/src/newArch/features/WalletSync/screens/Activation/ActivationDrawer.tsx +++ b/apps/ledger-live-mobile/src/newArch/features/WalletSync/screens/Activation/ActivationDrawer.tsx @@ -17,7 +17,6 @@ type Props = { function View({ isOpen, - currentStep, hasCustomHeader, canGoBack, navigateToChooseSyncMethod, @@ -30,7 +29,6 @@ function View({ qrProcess, currentOption, setCurrentOption, - setCurrentStep, }: ViewProps) { const CustomDrawerHeader = () => ; @@ -46,14 +44,12 @@ function View({ > diff --git a/apps/ledger-live-mobile/src/newArch/features/WalletSync/screens/Activation/ActivationSuccess.tsx b/apps/ledger-live-mobile/src/newArch/features/WalletSync/screens/Activation/ActivationSuccess.tsx index b96142165867..44d8c3f684f9 100644 --- a/apps/ledger-live-mobile/src/newArch/features/WalletSync/screens/Activation/ActivationSuccess.tsx +++ b/apps/ledger-live-mobile/src/newArch/features/WalletSync/screens/Activation/ActivationSuccess.tsx @@ -17,6 +17,9 @@ import { BaseNavigatorStackParamList } from "~/components/RootNavigator/types/Ba import { setFromLedgerSyncOnboarding } from "~/actions/settings"; import { AnalyticsButton, AnalyticsFlow, AnalyticsPage } from "../../hooks/useLedgerSyncAnalytics"; import { track } from "~/analytics"; +import { setLedgerSyncActivateDrawer } from "~/actions/walletSync"; +import { Steps } from "../../types/Activation"; +import { useCurrentStep } from "../../hooks/useCurrentStep"; type Props = BaseComposite< StackNavigatorProps @@ -30,6 +33,7 @@ export function ActivationSuccess({ navigation, route }: Props) { const desc = created ? "walletSync.success.activationDesc" : "walletSync.success.syncDesc"; const page = created ? AnalyticsPage.BackupCreationSuccess : AnalyticsPage.SyncSuccess; const dispatch = useDispatch(); + const { setCurrentStep } = useCurrentStep(); const navigationOnbarding = useNavigation>>(); @@ -40,7 +44,14 @@ export function ActivationSuccess({ navigation, route }: Props) { page, flow: AnalyticsFlow.LedgerSync, }); - navigation.navigate(ScreenName.WalletSyncActivationProcess); + if (isFromLedgerSyncOnboarding) { + dispatch(setFromLedgerSyncOnboarding(false)); + } + setCurrentStep(Steps.QrCodeMethod); + navigation.navigate(NavigatorName.Settings, { + screen: ScreenName.GeneralSettings, + }); + dispatch(setLedgerSyncActivateDrawer(true)); } function close(): void { diff --git a/apps/ledger-live-mobile/src/newArch/features/WalletSync/screens/Activation/useActivationDrawerModel.ts b/apps/ledger-live-mobile/src/newArch/features/WalletSync/screens/Activation/useActivationDrawerModel.ts index 635a6cdcb374..4ae33187ffd4 100644 --- a/apps/ledger-live-mobile/src/newArch/features/WalletSync/screens/Activation/useActivationDrawerModel.ts +++ b/apps/ledger-live-mobile/src/newArch/features/WalletSync/screens/Activation/useActivationDrawerModel.ts @@ -1,4 +1,4 @@ -import { useCallback, useMemo, useState } from "react"; +import { useCallback, useEffect, useMemo, useState } from "react"; import { Steps } from "../../types/Activation"; import { AnalyticsButton, @@ -11,6 +11,7 @@ import { NavigatorName, ScreenName } from "~/const"; import { useNavigation } from "@react-navigation/native"; import { BaseComposite, StackNavigatorProps } from "~/components/RootNavigator/types/helpers"; import { WalletSyncNavigatorStackParamList } from "~/components/RootNavigator/types/WalletSyncNavigator"; +import { useCurrentStep } from "../../hooks/useCurrentStep"; type Props = { isOpen: boolean; @@ -24,7 +25,11 @@ type NavigationProps = BaseComposite< const useActivationDrawerModel = ({ isOpen, startingStep, handleClose }: Props) => { const { onClickTrack } = useLedgerSyncAnalytics(); - const [currentStep, setCurrentStep] = useState(startingStep); + const { currentStep, setCurrentStep } = useCurrentStep(); + + useEffect(() => { + setCurrentStep(startingStep); + }, [startingStep, setCurrentStep]); const [currentOption, setCurrentOption] = useState(Options.SCAN); const navigation = useNavigation(); const hasCustomHeader = useMemo(() => currentStep === Steps.QrCodeMethod, [currentStep]); @@ -76,14 +81,11 @@ const useActivationDrawerModel = ({ isOpen, startingStep, handleClose }: Props) }; const { url, error, isLoading, pinCode } = useQRCodeHost({ - setCurrentStep, - currentStep, currentOption, }); return { isOpen, - currentStep, hasCustomHeader, canGoBack, navigateToChooseSyncMethod, @@ -95,7 +97,6 @@ const useActivationDrawerModel = ({ isOpen, startingStep, handleClose }: Props) qrProcess: { url, error, isLoading, pinCode }, currentOption, setCurrentOption, - setCurrentStep, onCreateKey, }; }; diff --git a/apps/ledger-live-mobile/src/reducers/types.ts b/apps/ledger-live-mobile/src/reducers/types.ts index e5b9fa1af111..9df02fefbac0 100644 --- a/apps/ledger-live-mobile/src/reducers/types.ts +++ b/apps/ledger-live-mobile/src/reducers/types.ts @@ -29,6 +29,7 @@ import { ImageType } from "../components/CustomImage/types"; import { CLSSupportedDeviceModelId } from "@ledgerhq/live-common/device/use-cases/isCustomLockScreenSupported"; import { WalletState } from "@ledgerhq/live-wallet/store"; import { TrustchainStore } from "@ledgerhq/trustchain/store"; +import { Steps } from "LLM/features/WalletSync/types/Activation"; // === ACCOUNT STATE === @@ -347,6 +348,7 @@ export type MarketState = { export type WalletSyncState = { isManageKeyDrawerOpen: boolean; isActivateDrawerOpen: boolean; + activateDrawerStep: Steps; }; // === ROOT STATE === diff --git a/apps/ledger-live-mobile/src/reducers/walletSync.ts b/apps/ledger-live-mobile/src/reducers/walletSync.ts index 7253382342aa..8092bac10986 100644 --- a/apps/ledger-live-mobile/src/reducers/walletSync.ts +++ b/apps/ledger-live-mobile/src/reducers/walletSync.ts @@ -5,12 +5,15 @@ import { WalletSyncActionTypes, WalletSyncPayload, WalletSyncSetActivateDrawer, + WalletSyncSetActivateStep, WalletSyncSetManageKeyDrawerPayload, } from "../actions/types"; +import { Steps } from "LLM/features/WalletSync/types/Activation"; export const INITIAL_STATE: WalletSyncState = { isManageKeyDrawerOpen: false, isActivateDrawerOpen: false, + activateDrawerStep: Steps.Activation, }; const handlers: ReducerMap = { @@ -22,6 +25,10 @@ const handlers: ReducerMap = { ...state, isActivateDrawerOpen: (action as Action).payload, }), + [WalletSyncActionTypes.LEDGER_SYNC_SET_ACTIVATE_STEP]: (state, action) => ({ + ...state, + activateDrawerStep: (action as Action).payload, + }), }; export const storeSelector = (state: State): WalletSyncState => state.walletSync; @@ -29,5 +36,7 @@ export const manageKeyDrawerSelector = (state: State): boolean => state.walletSync.isManageKeyDrawerOpen; export const activateDrawerSelector = (state: State): boolean => state.walletSync.isActivateDrawerOpen; +export const activateDrawerStepSelector = (state: State): Steps => + state.walletSync.activateDrawerStep; export default handleActions(handlers, INITIAL_STATE); diff --git a/apps/ledger-live-mobile/src/screens/Settings/General/WalletSyncRow.tsx b/apps/ledger-live-mobile/src/screens/Settings/General/WalletSyncRow.tsx index d93c667bd6b1..82af7b53a5d8 100644 --- a/apps/ledger-live-mobile/src/screens/Settings/General/WalletSyncRow.tsx +++ b/apps/ledger-live-mobile/src/screens/Settings/General/WalletSyncRow.tsx @@ -14,6 +14,7 @@ import ActivationDrawer from "LLM/features/WalletSync/screens/Activation/Activat import { Steps } from "LLM/features/WalletSync/types/Activation"; import { activateDrawerSelector } from "~/reducers/walletSync"; import { setLedgerSyncActivateDrawer } from "~/actions/walletSync"; +import { useCurrentStep } from "LLM/features/WalletSync/hooks/useCurrentStep"; const WalletSyncRow = () => { const { t } = useTranslation(); @@ -22,10 +23,12 @@ const WalletSyncRow = () => { const isDrawerVisible = useSelector(activateDrawerSelector); const dispatch = useDispatch(); + const { setCurrentStep } = useCurrentStep(); const closeDrawer = useCallback(() => { dispatch(setLedgerSyncActivateDrawer(false)); - }, [dispatch]); + setCurrentStep(Steps.Activation); + }, [dispatch, setCurrentStep]); const trustchain = useSelector(trustchainSelector); const navigateToWalletSyncActivationScreen = useCallback(() => { From 644332f58790fb89375b9ca8a4b58e5f1613c14f Mon Sep 17 00:00:00 2001 From: Martin CAYUELAS <112866305+mcayuelas-ledger@users.noreply.github.com> Date: Tue, 3 Sep 2024 17:34:10 +0200 Subject: [PATCH 3/3] [FIX]: Animation color on FollowSteps (#7736) --- .changeset/sixty-eagles-watch.md | 5 +++++ .../WalletSync/screens/DeviceActions/FollowStepsOnDevice.tsx | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 .changeset/sixty-eagles-watch.md diff --git a/.changeset/sixty-eagles-watch.md b/.changeset/sixty-eagles-watch.md new file mode 100644 index 000000000000..a6f0d904195c --- /dev/null +++ b/.changeset/sixty-eagles-watch.md @@ -0,0 +1,5 @@ +--- +"ledger-live-desktop": patch +--- + +Fix Animation Color diff --git a/apps/ledger-live-desktop/src/newArch/features/WalletSync/screens/DeviceActions/FollowStepsOnDevice.tsx b/apps/ledger-live-desktop/src/newArch/features/WalletSync/screens/DeviceActions/FollowStepsOnDevice.tsx index ea57db6708b1..79b612228655 100644 --- a/apps/ledger-live-desktop/src/newArch/features/WalletSync/screens/DeviceActions/FollowStepsOnDevice.tsx +++ b/apps/ledger-live-desktop/src/newArch/features/WalletSync/screens/DeviceActions/FollowStepsOnDevice.tsx @@ -17,9 +17,11 @@ const getProductName = (modelId: DeviceModelId) => getDeviceModel(modelId)?.productName.replace("Ledger", "").trimStart() || modelId; export default function FollowStepsOnDevice({ modelId, isDeviceBlocker }: Props) { - const { theme } = useTheme(); + const { colors } = useTheme(); + const theme = colors.palette.type; const { t } = useTranslation(); const wording = getProductName(modelId); + return ( <> {isDeviceBlocker ? : null}