From 5a7df0bd02ed5ce9fe0468afb90a282d9244f67d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Cort=C3=A9s=20Ross?= Date: Mon, 7 Feb 2022 20:19:39 +0100 Subject: [PATCH] LIVE-921 Throw specific error when app not in provider (#1689) --- src/apps/logic.ts | 9 ++++++--- src/errors.ts | 3 +++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/apps/logic.ts b/src/apps/logic.ts index 62e4f722b2..95773e835c 100644 --- a/src/apps/logic.ts +++ b/src/apps/logic.ts @@ -1,7 +1,6 @@ import { $Shape } from "utility-types"; import { Subject } from "rxjs"; import flatMap from "lodash/flatMap"; -import invariant from "invariant"; import semver from "semver"; import { getDeviceModel } from "@ledgerhq/devices"; import type { App } from "../types/manager"; @@ -17,7 +16,7 @@ import { findCryptoCurrencyById, isCurrencySupported, } from "../currencies"; -import { LatestFirmwareVersionRequired } from "../errors"; +import { LatestFirmwareVersionRequired, NoSuchAppOnProvider } from "../errors"; export const initState = ( { @@ -292,6 +291,7 @@ export const reducer = (state: State, action: Action): State => { // No app found but fw update is available if ( !depApp && + state.firmware?.updateAvailable?.final?.version && semver.lt( state.deviceInfo.version, state.firmware?.updateAvailable?.final?.version @@ -306,7 +306,10 @@ export const reducer = (state: State, action: Action): State => { ); } - invariant(depApp, "no such app '%s'", name); + if (!depApp) { + throw new NoSuchAppOnProvider("", { appName: name }); + } + const deps = depApp.dependencies; const dependentsOfDep = flatMap(deps, (dep) => findDependents(state.appByName, dep) diff --git a/src/errors.ts b/src/errors.ts index 7656ecdfbe..d7d6f81708 100644 --- a/src/errors.ts +++ b/src/errors.ts @@ -141,6 +141,9 @@ export const SatStackDescriptorNotImported = createCustomErrorClass( export const SwapNoAvailableProviders = createCustomErrorClass( "SwapNoAvailableProviders" ); +export const NoSuchAppOnProvider = createCustomErrorClass( + "NoSuchAppOnProvider" +); export const SwapExchangeRateAmountTooLow = createCustomErrorClass( "SwapExchangeRateAmountTooLow" );