UNPKG

@ledgerhq/live-common

Version:
24 lines 1.06 kB
import { from, of, switchMap } from "rxjs"; import { RestoreAppDataEventType, } from "./types"; /** * Restores the application data for a specific app on a Ledger device. * * @param appName - The name of the application to restore. * @param deviceModelId - The device model ID. * @param storageProvider - The storage provider object used for retrieving the backup data. * @param restoreAppDataFn - The function used to restore the app data. * @returns An observable that emits RestoreAppDataEvent according to the restore process. * @throws {RestoreAppDataError} */ export function restoreAppDataUseCase(appName, deviceModelId, storageProvider, restoreAppDataFn) { const obs = from(storageProvider.getItem(`${deviceModelId}-${appName}`)).pipe(switchMap((appStorage) => { if (!appStorage) { return of({ type: RestoreAppDataEventType.NoAppDataToRestore, }); } return restoreAppDataFn(appStorage.appData); })); return obs; } //# sourceMappingURL=restoreAppDataUseCase.js.map