Skip to content

Commit

Permalink
🏗️ adding findLatestAppCandidate function to have the latest app vers…
Browse files Browse the repository at this point in the history
…ion + latest firmware version
  • Loading branch information
VicAlbr committed Jul 25, 2024
1 parent 052bdba commit 0809ef2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions apps/ledger-live-desktop/tests/utils/speculos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
listAppCandidates,
createSpeculosDevice,
releaseSpeculosDevice,
findAppCandidate,
findLatestAppCandidate,
SpeculosTransport,
} from "@ledgerhq/live-common/load/speculos";
import { SpeculosDevice } from "@ledgerhq/speculos-transport";
Expand Down Expand Up @@ -202,7 +202,7 @@ export async function startSpeculos(
}

const { appQuery, dependency, onSpeculosDeviceCreated } = spec;
const appCandidate = findAppCandidate(appCandidates, appQuery);
const appCandidate = findLatestAppCandidate(appCandidates, appQuery);
if (!appCandidate) {
console.warn("no app found for " + testName);
console.warn(appQuery);
Expand Down
14 changes: 14 additions & 0 deletions libs/ledger-live-common/src/load/speculos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,20 @@ export function appCandidatesMatches(appCandidate: AppCandidate, search: AppSear
(search.appVersion && semver.satisfies(appCandidate.appVersion, search.appVersion)))
);
}

export const findLatestAppCandidate = (
appCandidates: AppCandidate[],
search: AppSearch,
): AppCandidate | null => {
let apps = appCandidates.filter(c => appCandidatesMatches(c, search));
if (apps.length === 0) {
return null;
}

apps = apps.sort((a, b) => semver.rcompare(a.appVersion, b.appVersion));
return apps[0];
};

export const findAppCandidate = (
appCandidates: AppCandidate[],
search: AppSearch,
Expand Down

0 comments on commit 0809ef2

Please sign in to comment.