@ledgerhq/live-common 34.35.0-nightly.3 → 34.35.0-nightly.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/apps/support.d.ts +1 -0
- package/lib/apps/support.d.ts.map +1 -1
- package/lib/apps/support.js +10 -1
- package/lib/apps/support.js.map +1 -1
- package/lib/e2e/enum/Account.js +5 -5
- package/lib/e2e/enum/Account.js.map +1 -1
- package/lib/e2e/index.d.ts +2 -0
- package/lib/e2e/index.d.ts.map +1 -1
- package/lib/featureFlags/defaultFeatures.d.ts.map +1 -1
- package/lib/featureFlags/defaultFeatures.js +1 -0
- package/lib/featureFlags/defaultFeatures.js.map +1 -1
- package/lib/featureFlags/useFeature.d.ts +1 -1
- package/lib/featureFlags/useFeature.d.ts.map +1 -1
- package/lib/hw/actions/manager.d.ts +1 -1
- package/lib/hw/actions/manager.d.ts.map +1 -1
- package/lib/hw/connectApp.d.ts.map +1 -1
- package/lib/hw/connectApp.js +56 -5
- package/lib/hw/connectApp.js.map +1 -1
- package/lib/hw/connectAppEventMapper.d.ts +29 -0
- package/lib/hw/connectAppEventMapper.d.ts.map +1 -0
- package/lib/hw/connectAppEventMapper.js +300 -0
- package/lib/hw/connectAppEventMapper.js.map +1 -0
- package/lib/hw/connectManager.d.ts +3 -2
- package/lib/hw/connectManager.d.ts.map +1 -1
- package/lib/hw/connectManager.js +34 -3
- package/lib/hw/connectManager.js.map +1 -1
- package/lib/hw/connectManagerEventMapper.d.ts +16 -0
- package/lib/hw/connectManagerEventMapper.d.ts.map +1 -0
- package/lib/hw/connectManagerEventMapper.js +78 -0
- package/lib/hw/connectManagerEventMapper.js.map +1 -0
- package/lib/notifications/AnnouncementProvider/index.d.ts.map +1 -1
- package/lib/notifications/AnnouncementProvider/index.js +12 -10
- package/lib/notifications/AnnouncementProvider/index.js.map +1 -1
- package/lib/notifications/AnnouncementProvider/machine.d.ts +1 -4
- package/lib/notifications/AnnouncementProvider/machine.d.ts.map +1 -1
- package/lib/notifications/AnnouncementProvider/machine.js +9 -8
- package/lib/notifications/AnnouncementProvider/machine.js.map +1 -1
- package/lib/notifications/ServiceStatusProvider/index.d.ts.map +1 -1
- package/lib/notifications/ServiceStatusProvider/index.js +5 -4
- package/lib/notifications/ServiceStatusProvider/index.js.map +1 -1
- package/lib/notifications/ServiceStatusProvider/machine.d.ts +1 -4
- package/lib/notifications/ServiceStatusProvider/machine.d.ts.map +1 -1
- package/lib/notifications/ServiceStatusProvider/machine.js +4 -4
- package/lib/notifications/ServiceStatusProvider/machine.js.map +1 -1
- package/lib/wallet-api/ModularDrawer/types.d.ts +63 -0
- package/lib/wallet-api/ModularDrawer/types.d.ts.map +1 -0
- package/lib/wallet-api/ModularDrawer/types.js +25 -0
- package/lib/wallet-api/ModularDrawer/types.js.map +1 -0
- package/lib/wallet-api/ModularDrawer/utils.d.ts +5 -0
- package/lib/wallet-api/ModularDrawer/utils.d.ts.map +1 -0
- package/lib/wallet-api/ModularDrawer/utils.js +30 -0
- package/lib/wallet-api/ModularDrawer/utils.js.map +1 -0
- package/lib/wallet-api/react.d.ts +2 -0
- package/lib/wallet-api/react.d.ts.map +1 -1
- package/lib/wallet-api/react.js +2 -1
- package/lib/wallet-api/react.js.map +1 -1
- package/lib-es/apps/support.d.ts +1 -0
- package/lib-es/apps/support.d.ts.map +1 -1
- package/lib-es/apps/support.js +8 -0
- package/lib-es/apps/support.js.map +1 -1
- package/lib-es/e2e/enum/Account.js +5 -5
- package/lib-es/e2e/enum/Account.js.map +1 -1
- package/lib-es/e2e/index.d.ts +2 -0
- package/lib-es/e2e/index.d.ts.map +1 -1
- package/lib-es/featureFlags/defaultFeatures.d.ts.map +1 -1
- package/lib-es/featureFlags/defaultFeatures.js +1 -0
- package/lib-es/featureFlags/defaultFeatures.js.map +1 -1
- package/lib-es/featureFlags/useFeature.d.ts +1 -1
- package/lib-es/featureFlags/useFeature.d.ts.map +1 -1
- package/lib-es/hw/actions/manager.d.ts +1 -1
- package/lib-es/hw/actions/manager.d.ts.map +1 -1
- package/lib-es/hw/connectApp.d.ts.map +1 -1
- package/lib-es/hw/connectApp.js +57 -6
- package/lib-es/hw/connectApp.js.map +1 -1
- package/lib-es/hw/connectAppEventMapper.d.ts +29 -0
- package/lib-es/hw/connectAppEventMapper.d.ts.map +1 -0
- package/lib-es/hw/connectAppEventMapper.js +296 -0
- package/lib-es/hw/connectAppEventMapper.js.map +1 -0
- package/lib-es/hw/connectManager.d.ts +3 -2
- package/lib-es/hw/connectManager.d.ts.map +1 -1
- package/lib-es/hw/connectManager.js +34 -4
- package/lib-es/hw/connectManager.js.map +1 -1
- package/lib-es/hw/connectManagerEventMapper.d.ts +16 -0
- package/lib-es/hw/connectManagerEventMapper.d.ts.map +1 -0
- package/lib-es/hw/connectManagerEventMapper.js +74 -0
- package/lib-es/hw/connectManagerEventMapper.js.map +1 -0
- package/lib-es/notifications/AnnouncementProvider/index.d.ts.map +1 -1
- package/lib-es/notifications/AnnouncementProvider/index.js +12 -10
- package/lib-es/notifications/AnnouncementProvider/index.js.map +1 -1
- package/lib-es/notifications/AnnouncementProvider/machine.d.ts +1 -4
- package/lib-es/notifications/AnnouncementProvider/machine.d.ts.map +1 -1
- package/lib-es/notifications/AnnouncementProvider/machine.js +9 -8
- package/lib-es/notifications/AnnouncementProvider/machine.js.map +1 -1
- package/lib-es/notifications/ServiceStatusProvider/index.d.ts.map +1 -1
- package/lib-es/notifications/ServiceStatusProvider/index.js +5 -4
- package/lib-es/notifications/ServiceStatusProvider/index.js.map +1 -1
- package/lib-es/notifications/ServiceStatusProvider/machine.d.ts +1 -4
- package/lib-es/notifications/ServiceStatusProvider/machine.d.ts.map +1 -1
- package/lib-es/notifications/ServiceStatusProvider/machine.js +4 -4
- package/lib-es/notifications/ServiceStatusProvider/machine.js.map +1 -1
- package/lib-es/wallet-api/ModularDrawer/types.d.ts +63 -0
- package/lib-es/wallet-api/ModularDrawer/types.d.ts.map +1 -0
- package/lib-es/wallet-api/ModularDrawer/types.js +22 -0
- package/lib-es/wallet-api/ModularDrawer/types.js.map +1 -0
- package/lib-es/wallet-api/ModularDrawer/utils.d.ts +5 -0
- package/lib-es/wallet-api/ModularDrawer/utils.d.ts.map +1 -0
- package/lib-es/wallet-api/ModularDrawer/utils.js +25 -0
- package/lib-es/wallet-api/ModularDrawer/utils.js.map +1 -0
- package/lib-es/wallet-api/react.d.ts +2 -0
- package/lib-es/wallet-api/react.d.ts.map +1 -1
- package/lib-es/wallet-api/react.js +2 -1
- package/lib-es/wallet-api/react.js.map +1 -1
- package/package.json +50 -49
- package/src/apps/support.ts +11 -0
- package/src/e2e/enum/Account.ts +5 -5
- package/src/featureFlags/defaultFeatures.ts +1 -0
- package/src/hw/actions/manager.ts +1 -1
- package/src/hw/connectApp.ts +245 -178
- package/src/hw/connectAppEventMapper.ts +364 -0
- package/src/hw/connectManager.ts +116 -74
- package/src/hw/connectManagerEventMapper.ts +109 -0
- package/src/notifications/AnnouncementProvider/index.tsx +21 -17
- package/src/notifications/AnnouncementProvider/machine.ts +9 -8
- package/src/notifications/ServiceStatusProvider/index.tsx +11 -8
- package/src/notifications/ServiceStatusProvider/machine.ts +4 -4
- package/src/wallet-api/ModularDrawer/types.ts +45 -0
- package/src/wallet-api/ModularDrawer/utils.ts +37 -0
- package/src/wallet-api/react.ts +37 -31
- package/lib/index.d.ts +0 -2
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -3
- package/lib/index.js.map +0 -1
- package/lib-es/index.d.ts +0 -1
- package/lib-es/index.d.ts.map +0 -1
- package/lib-es/index.js +0 -2
- package/lib-es/index.js.map +0 -1
- package/src/index.ts +0 -0
package/src/hw/connectApp.ts
CHANGED
@@ -26,10 +26,18 @@ import getDeviceInfo from "./getDeviceInfo";
|
|
26
26
|
import getAddress from "./getAddress";
|
27
27
|
import openApp from "./openApp";
|
28
28
|
import quitApp from "./quitApp";
|
29
|
-
import { mustUpgrade } from "../apps";
|
29
|
+
import { mustUpgrade, getMinVersion } from "../apps";
|
30
30
|
import isUpdateAvailable from "./isUpdateAvailable";
|
31
31
|
import { LockedDeviceEvent } from "./actions/types";
|
32
32
|
import { getLatestFirmwareForDeviceUseCase } from "../device/use-cases/getLatestFirmwareForDeviceUseCase";
|
33
|
+
import {
|
34
|
+
type ApplicationDependency,
|
35
|
+
type ApplicationConstraint,
|
36
|
+
type ApplicationVersionConstraint,
|
37
|
+
type DeviceManagementKit,
|
38
|
+
} from "@ledgerhq/device-management-kit";
|
39
|
+
import { ConnectAppDeviceAction } from "@ledgerhq/live-dmk-shared";
|
40
|
+
import { ConnectAppEventMapper } from "./connectAppEventMapper";
|
33
41
|
|
34
42
|
export type RequiresDerivation = {
|
35
43
|
currencyId: string;
|
@@ -274,7 +282,7 @@ const derivationLogic = (
|
|
274
282
|
* @param allowPartialDependencies If some dependencies need to be installed, and if set to true,
|
275
283
|
* skip any app install if the app is not found from the provider.
|
276
284
|
*/
|
277
|
-
const cmd = (
|
285
|
+
const cmd = (transport: Transport, { request }: Input): Observable<ConnectAppEvent> => {
|
278
286
|
const {
|
279
287
|
appName,
|
280
288
|
requiresDerivation,
|
@@ -283,202 +291,222 @@ const cmd = ({ deviceId, request }: Input): Observable<ConnectAppEvent> => {
|
|
283
291
|
outdatedApp,
|
284
292
|
allowPartialDependencies = false,
|
285
293
|
} = request;
|
286
|
-
return
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
concatMap((appAndVersion): Observable<ConnectAppEvent> => {
|
301
|
-
timeoutSub.unsubscribe();
|
294
|
+
return new Observable(o => {
|
295
|
+
const timeoutSub = of({
|
296
|
+
type: "unresponsiveDevice",
|
297
|
+
})
|
298
|
+
.pipe(delay(1000))
|
299
|
+
.subscribe(e => o.next(e as ConnectAppEvent));
|
300
|
+
const innerSub = ({
|
301
|
+
appName,
|
302
|
+
dependencies,
|
303
|
+
requireLatestFirmware,
|
304
|
+
}: ConnectAppRequest): Observable<ConnectAppEvent> =>
|
305
|
+
defer(() => from(getAppAndVersion(transport))).pipe(
|
306
|
+
concatMap((appAndVersion): Observable<ConnectAppEvent> => {
|
307
|
+
timeoutSub.unsubscribe();
|
302
308
|
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
309
|
+
if (isDashboardName(appAndVersion.name)) {
|
310
|
+
// check if we meet minimum fw
|
311
|
+
if (requireLatestFirmware || outdatedApp) {
|
312
|
+
return from(getDeviceInfo(transport)).pipe(
|
313
|
+
mergeMap((deviceInfo: DeviceInfo) =>
|
314
|
+
from(getLatestFirmwareForDeviceUseCase(deviceInfo)).pipe(
|
315
|
+
mergeMap((latest: FirmwareUpdateContext | undefined | null) => {
|
316
|
+
const isLatest =
|
317
|
+
!latest || semver.eq(deviceInfo.version, latest.final.version);
|
312
318
|
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
),
|
319
|
+
if (
|
320
|
+
(!requireLatestFirmware || (requireLatestFirmware && isLatest)) &&
|
321
|
+
outdatedApp
|
322
|
+
) {
|
323
|
+
return from(isUpdateAvailable(deviceInfo, outdatedApp)).pipe(
|
324
|
+
mergeMap(isAvailable =>
|
325
|
+
isAvailable
|
326
|
+
? throwError(
|
327
|
+
() =>
|
328
|
+
new UpdateYourApp(undefined, {
|
329
|
+
managerAppName: outdatedApp.name,
|
330
|
+
}),
|
331
|
+
)
|
332
|
+
: throwError(
|
333
|
+
() =>
|
334
|
+
new LatestFirmwareVersionRequired(
|
335
|
+
"LatestFirmwareVersionRequired",
|
336
|
+
{
|
337
|
+
latest: latest?.final.version,
|
338
|
+
current: deviceInfo.version,
|
339
|
+
},
|
335
340
|
),
|
336
|
-
|
337
|
-
|
338
|
-
|
341
|
+
),
|
342
|
+
),
|
343
|
+
);
|
344
|
+
}
|
339
345
|
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
allowPartialDependencies,
|
375
|
-
// dependencies // Resolved!
|
376
|
-
});
|
377
|
-
},
|
346
|
+
if (isLatest) {
|
347
|
+
o.next({ type: "latest-firmware-resolved" });
|
348
|
+
return innerSub({
|
349
|
+
appName,
|
350
|
+
dependencies,
|
351
|
+
allowPartialDependencies,
|
352
|
+
// requireLatestFirmware // Resolved!.
|
353
|
+
});
|
354
|
+
} else {
|
355
|
+
return throwError(
|
356
|
+
() =>
|
357
|
+
new LatestFirmwareVersionRequired("LatestFirmwareVersionRequired", {
|
358
|
+
latest: latest.final.version,
|
359
|
+
current: deviceInfo.version,
|
360
|
+
}),
|
361
|
+
);
|
362
|
+
}
|
363
|
+
}),
|
364
|
+
),
|
365
|
+
),
|
366
|
+
);
|
367
|
+
}
|
368
|
+
// check if we meet dependencies
|
369
|
+
if (dependencies?.length) {
|
370
|
+
const completesInDashboard = isDashboardName(appName);
|
371
|
+
return inlineAppInstall({
|
372
|
+
transport,
|
373
|
+
appNames: [...(completesInDashboard ? [] : [appName]), ...dependencies],
|
374
|
+
onSuccessObs: () => {
|
375
|
+
o.next({
|
376
|
+
type: "dependencies-resolved",
|
377
|
+
});
|
378
|
+
return innerSub({
|
379
|
+
appName,
|
378
380
|
allowPartialDependencies,
|
381
|
+
// dependencies // Resolved!
|
379
382
|
});
|
380
|
-
}
|
383
|
+
},
|
384
|
+
allowPartialDependencies,
|
385
|
+
});
|
386
|
+
}
|
381
387
|
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
388
|
+
// maybe we want to be in the dashboard
|
389
|
+
if (appName === appAndVersion.name) {
|
390
|
+
const e: ConnectAppEvent = {
|
391
|
+
type: "opened",
|
392
|
+
app: appAndVersion,
|
393
|
+
};
|
394
|
+
return of(e);
|
395
|
+
}
|
390
396
|
|
391
|
-
|
392
|
-
|
393
|
-
|
397
|
+
// we're in dashboard
|
398
|
+
return openAppFromDashboard(transport, appName);
|
399
|
+
}
|
394
400
|
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
401
|
+
const appNeedsUpgrade = mustUpgrade(appAndVersion.name, appAndVersion.version);
|
402
|
+
if (appNeedsUpgrade) {
|
403
|
+
// quit app, check provider's app update for device's minimum requirements.
|
404
|
+
o.next({
|
405
|
+
type: "has-outdated-app",
|
406
|
+
outdatedApp: appAndVersion,
|
407
|
+
});
|
408
|
+
}
|
403
409
|
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
410
|
+
// need dashboard to check firmware, install dependencies, or verify app update
|
411
|
+
if (
|
412
|
+
dependencies?.length ||
|
413
|
+
requireLatestFirmware ||
|
414
|
+
appAndVersion.name !== appName ||
|
415
|
+
appNeedsUpgrade
|
416
|
+
) {
|
417
|
+
return attemptToQuitApp(transport, appAndVersion as AppAndVersion);
|
418
|
+
}
|
419
|
+
|
420
|
+
if (requiresDerivation) {
|
421
|
+
return derivationLogic(transport, {
|
422
|
+
requiresDerivation,
|
423
|
+
appAndVersion: appAndVersion as AppAndVersion,
|
424
|
+
appName,
|
425
|
+
});
|
426
|
+
} else {
|
427
|
+
const e: ConnectAppEvent = {
|
428
|
+
type: "opened",
|
429
|
+
app: appAndVersion,
|
430
|
+
};
|
431
|
+
return of(e);
|
432
|
+
}
|
433
|
+
}),
|
434
|
+
catchError((e: unknown) => {
|
435
|
+
if (
|
436
|
+
(typeof e === "object" &&
|
437
|
+
e !== null &&
|
438
|
+
"_tag" in e &&
|
439
|
+
e._tag === "DeviceDisconnectedWhileSendingError") ||
|
440
|
+
e instanceof DisconnectedDeviceDuringOperation ||
|
441
|
+
e instanceof DisconnectedDevice
|
442
|
+
) {
|
443
|
+
return of(<ConnectAppEvent>{
|
444
|
+
type: "disconnected",
|
445
|
+
});
|
446
|
+
}
|
447
|
+
|
448
|
+
if (e && e instanceof TransportStatusError) {
|
449
|
+
switch (e.statusCode) {
|
450
|
+
case StatusCodes.CLA_NOT_SUPPORTED: // in 1.3.1 dashboard
|
451
|
+
case StatusCodes.INS_NOT_SUPPORTED: // in 1.3.1 and bitcoin app
|
452
|
+
// fallback on "old way" because device does not support getAppAndVersion
|
453
|
+
if (!requiresDerivation) {
|
454
|
+
// if there is no derivation, there is nothing we can do to check an app (e.g. requiring non coin app)
|
455
|
+
return throwError(() => new FirmwareOrAppUpdateRequired());
|
456
|
+
}
|
413
457
|
|
414
|
-
if (requiresDerivation) {
|
415
458
|
return derivationLogic(transport, {
|
416
459
|
requiresDerivation,
|
417
|
-
appAndVersion: appAndVersion as AppAndVersion,
|
418
460
|
appName,
|
419
461
|
});
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
}
|
427
|
-
}),
|
428
|
-
catchError((e: unknown) => {
|
429
|
-
if (
|
430
|
-
(typeof e === "object" &&
|
431
|
-
e !== null &&
|
432
|
-
"_tag" in e &&
|
433
|
-
e._tag === "DeviceDisconnectedWhileSendingError") ||
|
434
|
-
e instanceof DisconnectedDeviceDuringOperation ||
|
435
|
-
e instanceof DisconnectedDevice
|
436
|
-
) {
|
437
|
-
return of(<ConnectAppEvent>{
|
438
|
-
type: "disconnected",
|
439
|
-
});
|
440
|
-
}
|
462
|
+
}
|
463
|
+
} else if (e instanceof LockedDeviceError) {
|
464
|
+
return of({
|
465
|
+
type: "lockedDevice",
|
466
|
+
} as ConnectAppEvent);
|
467
|
+
}
|
441
468
|
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
case StatusCodes.INS_NOT_SUPPORTED: // in 1.3.1 and bitcoin app
|
446
|
-
// fallback on "old way" because device does not support getAppAndVersion
|
447
|
-
if (!requiresDerivation) {
|
448
|
-
// if there is no derivation, there is nothing we can do to check an app (e.g. requiring non coin app)
|
449
|
-
return throwError(() => new FirmwareOrAppUpdateRequired());
|
450
|
-
}
|
469
|
+
return throwError(() => e);
|
470
|
+
}),
|
471
|
+
);
|
451
472
|
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
return of({
|
459
|
-
type: "lockedDevice",
|
460
|
-
} as ConnectAppEvent);
|
461
|
-
}
|
473
|
+
const sub = innerSub({
|
474
|
+
appName,
|
475
|
+
dependencies,
|
476
|
+
requireLatestFirmware,
|
477
|
+
allowPartialDependencies,
|
478
|
+
}).subscribe(o);
|
462
479
|
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
dependencies,
|
470
|
-
requireLatestFirmware,
|
471
|
-
allowPartialDependencies,
|
472
|
-
}).subscribe(o);
|
480
|
+
return () => {
|
481
|
+
timeoutSub.unsubscribe();
|
482
|
+
sub.unsubscribe();
|
483
|
+
};
|
484
|
+
});
|
485
|
+
};
|
473
486
|
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
487
|
+
const isDmkTransport = (
|
488
|
+
transport: Transport,
|
489
|
+
): transport is Transport & { dmk: DeviceManagementKit; sessionId: string } => {
|
490
|
+
return (
|
491
|
+
"dmk" in transport &&
|
492
|
+
transport.dmk !== undefined &&
|
493
|
+
"sessionId" in transport &&
|
494
|
+
transport.sessionId !== undefined
|
479
495
|
);
|
480
496
|
};
|
481
497
|
|
498
|
+
const appNameToDependency = (appName: string): ApplicationDependency => {
|
499
|
+
let constraints: ApplicationConstraint[] | undefined = undefined;
|
500
|
+
const minVersion = getMinVersion(appName);
|
501
|
+
if (minVersion !== undefined) {
|
502
|
+
constraints = [{ minVersion: minVersion as ApplicationVersionConstraint }];
|
503
|
+
}
|
504
|
+
return {
|
505
|
+
name: appName,
|
506
|
+
constraints,
|
507
|
+
};
|
508
|
+
};
|
509
|
+
|
482
510
|
export default function connectAppFactory(
|
483
511
|
{
|
484
512
|
isLdmkConnectAppEnabled,
|
@@ -487,7 +515,46 @@ export default function connectAppFactory(
|
|
487
515
|
} = { isLdmkConnectAppEnabled: false },
|
488
516
|
) {
|
489
517
|
if (!isLdmkConnectAppEnabled) {
|
490
|
-
return
|
518
|
+
return ({ deviceId, request }: Input): Observable<ConnectAppEvent> =>
|
519
|
+
withDevice(deviceId)(transport => cmd(transport, { deviceId, request }));
|
491
520
|
}
|
492
|
-
|
521
|
+
return ({ deviceId, request }: Input): Observable<ConnectAppEvent> => {
|
522
|
+
const {
|
523
|
+
appName,
|
524
|
+
requiresDerivation,
|
525
|
+
dependencies,
|
526
|
+
requireLatestFirmware,
|
527
|
+
allowPartialDependencies = false,
|
528
|
+
} = request;
|
529
|
+
return withDevice(deviceId)(transport => {
|
530
|
+
if (!isDmkTransport(transport)) {
|
531
|
+
return cmd(transport, { deviceId, request });
|
532
|
+
}
|
533
|
+
const { dmk, sessionId } = transport;
|
534
|
+
const deviceAction = new ConnectAppDeviceAction({
|
535
|
+
input: {
|
536
|
+
application: appNameToDependency(appName),
|
537
|
+
dependencies: dependencies ? dependencies.map(name => appNameToDependency(name)) : [],
|
538
|
+
requireLatestFirmware,
|
539
|
+
allowMissingApplication: allowPartialDependencies,
|
540
|
+
unlockTimeout: 0, // Expect to fail immediately when device is locked
|
541
|
+
requiredDerivation: requiresDerivation
|
542
|
+
? async () => {
|
543
|
+
const { currencyId, ...derivationRest } = requiresDerivation;
|
544
|
+
const derivation = await getAddress(transport, {
|
545
|
+
currency: getCryptoCurrencyById(currencyId),
|
546
|
+
...derivationRest,
|
547
|
+
});
|
548
|
+
return derivation.address;
|
549
|
+
}
|
550
|
+
: undefined,
|
551
|
+
},
|
552
|
+
});
|
553
|
+
const observable = dmk.executeDeviceAction({
|
554
|
+
sessionId,
|
555
|
+
deviceAction,
|
556
|
+
});
|
557
|
+
return new ConnectAppEventMapper(dmk, sessionId, appName, observable).map();
|
558
|
+
});
|
559
|
+
};
|
493
560
|
}
|