Skip to content
Permalink
Browse files

Merge pull request LedgerHQ#162 from LedgerHQ/add-flag-for-firmwareUp…

…date-display

Add a flag to know if firmwareUpdate prepare is displayed on device
  • Loading branch information...
gre committed Mar 1, 2019
2 parents 8b637f0 + 9a303c6 commit d7a54a0881354d3f77fa70e52c9ce42c4445a635
Showing with 31 additions and 18 deletions.
  1. +15 −3 src/api/socket.js
  2. +16 −15 src/hw/firmwareUpdate-prepare.js
@@ -25,7 +25,9 @@ const log = (obj: *) => {
export type SocketEvent =
| {
type: "bulk-progress",
progress: number
progress: number,
index: number,
total: number
}
| {
type: "result",
@@ -142,7 +144,12 @@ export const createDeviceSocket = (
try {
const { data, nonce } = input;

o.next({ type: "bulk-progress", progress: 0 });
o.next({
type: "bulk-progress",
progress: 0,
index: 0,
total: data.length
});

// Execute all apdus and collect last status
let lastStatus = null;
@@ -154,7 +161,12 @@ export const createDeviceSocket = (
lastStatus = r.slice(r.length - 2);
if (lastStatus.toString("hex") !== "9000") break;
if (interrupted) return;
o.next({ type: "bulk-progress", progress: (i + 1) / data.length });
o.next({
type: "bulk-progress",
progress: (i + 1) / data.length,
index: i + 1,
total: data.length
});
}

if (!lastStatus) {
@@ -1,6 +1,6 @@
// @flow
import { Observable, from, of, concat, throwError } from "rxjs";
import { mergeMap, delay, filter, map, throttleTime } from "rxjs/operators";
import { mergeMap, delay, filter, map } from "rxjs/operators";

import getDeviceInfo from "../hw/getDeviceInfo";
import installOsuFirmware from "../hw/installOsuFirmware";
@@ -13,24 +13,25 @@ const waitEnd = of({ type: "wait" }).pipe(delay(1000));
const checkId = (
deviceId: string,
{ osu }: FirmwareUpdateContext
): Observable<{ progress: number }> =>
): Observable<{ progress: number, displayedOnDevice: boolean }> =>
withDevice(deviceId)(transport => from(getDeviceInfo(transport))).pipe(
mergeMap(
deviceInfo =>
// if in bootloader or OSU we'll directly jump to MCU step
deviceInfo.isBootloader || deviceInfo.isOSU
? throwError(new DeviceOnDashboardExpected())
: concat(
withDevice(deviceId)(transport =>
installOsuFirmware(transport, deviceInfo.targetId, osu)
),
waitEnd // the device is likely rebooting now, we give it some time
)
mergeMap(deviceInfo =>
// if in bootloader or OSU we'll directly jump to MCU step
deviceInfo.isBootloader || deviceInfo.isOSU
? throwError(new DeviceOnDashboardExpected())
: concat(
withDevice(deviceId)(transport =>
installOsuFirmware(transport, deviceInfo.targetId, osu)
),
waitEnd // the device is likely rebooting now, we give it some time
)
),

filter(e => e.type === "bulk-progress"),
map(e => ({ progress: e.progress })),
throttleTime(100)
map(e => ({
progress: e.progress,
displayedOnDevice: e.index >= e.total - 1
}))
);

export default checkId;

0 comments on commit d7a54a0

Please sign in to comment.
You can’t perform that action at this time.