forked from LedgerHQ/ledger-live-common
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uninstallApp.ts
36 lines (34 loc) · 1.04 KB
/
uninstallApp.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { ignoreElements, catchError } from "rxjs/operators";
import { Observable, throwError } from "rxjs";
import { ManagerAppDepUninstallRequired } from "@ledgerhq/errors";
import Transport from "@ledgerhq/hw-transport";
import type { App, ApplicationVersion } from "../types/manager";
import ManagerAPI from "../api/Manager";
export default function uninstallApp(
transport: Transport,
targetId: string | number,
app: ApplicationVersion | App
): Observable<any> {
return ManagerAPI.install(transport, "uninstall-app", {
targetId,
perso: app.perso,
deleteKey: app.delete_key,
firmware: app.delete,
firmwareKey: app.delete_key,
hash: app.hash,
}).pipe(
ignoreElements(),
catchError((e: Error) => {
if (!e || !e.message) return throwError(e);
const status = e.message.slice(e.message.length - 4);
if (status === "6a83") {
return throwError(
new ManagerAppDepUninstallRequired("", {
appName: app.name,
})
);
}
return throwError(e);
})
);
}