From ed9a8dfe0626edf9a11fe16676a684197def88b8 Mon Sep 17 00:00:00 2001 From: Hedi EDELBLOUTE Date: Mon, 6 Nov 2023 15:50:55 +0100 Subject: [PATCH] change onspeculoscreated hook --- libs/ledger-live-common/src/bot/engine.ts | 9 ++++----- .../src/bot/portfolio/process-sync.ts | 7 ++----- libs/ledger-live-common/src/load/speculos.ts | 14 +++++++++++++- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/libs/ledger-live-common/src/bot/engine.ts b/libs/ledger-live-common/src/bot/engine.ts index b0208848b6c4..1d64797158df 100644 --- a/libs/ledger-live-common/src/bot/engine.ts +++ b/libs/ledger-live-common/src/bot/engine.ts @@ -26,7 +26,7 @@ import { releaseSpeculosDevice, findAppCandidate, } from "../load/speculos"; -import type { AppCandidate } from "@ledgerhq/coin-framework/bot/types"; +import type { AppCandidate, SpeculosTransport } from "@ledgerhq/coin-framework/bot/types"; import { formatReportForConsole, formatTime, formatAppCandidate, formatError } from "./formatters"; import type { AppSpec, @@ -93,7 +93,7 @@ export async function runWithAppSpec( } const mutationReports: MutationReport[] = []; - const { appQuery, currency, dependency } = spec; + const { appQuery, currency, dependency, onSpeculosDeviceCreated } = spec; const appCandidate = findAppCandidate(appCandidates, appQuery); if (!appCandidate) { console.warn("no app found for " + spec.name); @@ -113,8 +113,10 @@ export async function runWithAppSpec( seed, dependency, coinapps, + onSpeculosDeviceCreated, }; let device; + const hintWarnings: string[] = []; const appReport: SpecReport = { spec, @@ -137,9 +139,6 @@ export async function runWithAppSpec( try { device = await createSpeculosDevice(deviceParams); appReport.appPath = device.appPath; - if (spec.onSpeculosDeviceCreated) { - await spec.onSpeculosDeviceCreated(device); - } const bridge = getCurrencyBridge(currency); const syncConfig = { paginationConfig: {}, diff --git a/libs/ledger-live-common/src/bot/portfolio/process-sync.ts b/libs/ledger-live-common/src/bot/portfolio/process-sync.ts index 82c57ad4bc22..4216074f9e06 100644 --- a/libs/ledger-live-common/src/bot/portfolio/process-sync.ts +++ b/libs/ledger-live-common/src/bot/portfolio/process-sync.ts @@ -52,7 +52,7 @@ async function main(): Promise { const appCandidates = await listAppCandidates(COINAPPS); - const { appQuery, currency, dependency } = spec; + const { appQuery, currency, dependency, onSpeculosDeviceCreated } = spec; const appCandidate = findAppCandidate(appCandidates, appQuery); if (!appCandidate) { console.warn("no app found for " + spec.name); @@ -68,14 +68,11 @@ async function main(): Promise { seed: SEED, dependency, coinapps: COINAPPS, + onSpeculosDeviceCreated, }; const device = await createSpeculosDevice(deviceParams); - if (spec.onSpeculosDeviceCreated) { - await spec.onSpeculosDeviceCreated(device); - } - try { const audit = new Audit(); diff --git a/libs/ledger-live-common/src/load/speculos.ts b/libs/ledger-live-common/src/load/speculos.ts index 22d920dfeefd..287d525734c3 100644 --- a/libs/ledger-live-common/src/load/speculos.ts +++ b/libs/ledger-live-common/src/load/speculos.ts @@ -100,6 +100,11 @@ export async function createSpeculosDevice( seed: string; // Folder where we have app binaries coinapps: string; + onSpeculosDeviceCreated?: (device: { + transport: SpeculosTransport; + id: string; + appPath: string; + }) => Promise; }, maxRetry = 3, ): Promise<{ @@ -271,11 +276,18 @@ export async function createSpeculosDevice( destroy, }; } - return { + + const device = { id: speculosID, transport, appPath, }; + + if (arg.onSpeculosDeviceCreated != null) { + await arg.onSpeculosDeviceCreated(device); + } + + return device; } function hackBadSemver(str) {