diff --git a/src/components/ManagerPage/AppsList.js b/src/components/ManagerPage/AppsList.js index a703a051..e924b6ef 100644 --- a/src/components/ManagerPage/AppsList.js +++ b/src/components/ManagerPage/AppsList.js @@ -20,8 +20,10 @@ import Progress from 'components/base/Progress' import Spinner from 'components/base/Spinner' import Button from 'components/base/Button' import Space from 'components/base/Space' +import TranslatedError from '../TranslatedError' import ExclamationCircle from 'icons/ExclamationCircle' +import ExclamationCircleThin from 'icons/ExclamationCircleThin' import Update from 'icons/Update' import Trash from 'icons/Trash' import CheckCircle from 'icons/CheckCircle' @@ -54,7 +56,7 @@ type Props = { type State = { status: Status, - error: string | null, + error: ?Error, appsList: LedgerScriptParams[] | Array<*>, app: string, mode: Mode, @@ -88,7 +90,7 @@ class AppsList extends PureComponent { this.setState({ appsList, status: 'idle' }) } } catch (err) { - this.setState({ status: 'error', error: err.message }) + this.setState({ status: 'error', error: err }) } } @@ -103,7 +105,7 @@ class AppsList extends PureComponent { await installApp.send(data).toPromise() this.setState({ status: 'success', app: '' }) } catch (err) { - this.setState({ status: 'error', error: err.message, app: '', mode: 'home' }) + this.setState({ status: 'error', error: err, app: '', mode: 'home' }) } } @@ -118,7 +120,7 @@ class AppsList extends PureComponent { await uninstallApp.send(data).toPromise() this.setState({ status: 'success', app: '' }) } catch (err) { - this.setState({ status: 'error', error: err.message, app: '', mode: 'home' }) + this.setState({ status: 'error', error: err, app: '', mode: 'home' }) } } @@ -127,7 +129,7 @@ class AppsList extends PureComponent { renderModal = () => { const { t } = this.props const { app, status, error, mode } = this.state - + console.log('what is error?? : ', error) return ( { {status === 'busy' || status === 'idle' ? ( - {mode === 'installing' ? : } + {mode === 'installing' ? ( + + + + ) : ( + + + + )} @@ -149,40 +159,52 @@ class AppsList extends PureComponent { ) : status === 'error' ? ( - + - + - - {error} + + - ) : status === 'success' ? ( - + - + - - - + {t( `app:manager.apps.${ mode === 'installing' ? 'installSuccess' : 'uninstallSuccess' }`, { app }, )} - + - - diff --git a/src/helpers/apps/installApp.js b/src/helpers/apps/installApp.js index 2183d639..96f1af75 100644 --- a/src/helpers/apps/installApp.js +++ b/src/helpers/apps/installApp.js @@ -7,6 +7,19 @@ import { createDeviceSocket } from 'helpers/socket' import type { LedgerScriptParams } from 'helpers/common' +import createCustomErrorClass from '../createCustomErrorClass' + +const CannotInstall = createCustomErrorClass('CannotInstall') + +function remapError(promise) { + return promise.catch((e: Error) => { + if (e.message.endsWith('6982')) { + throw new CannotInstall() + } + throw e + }) +} + /** * Install an app on the device */ @@ -21,5 +34,5 @@ export default async function installApp( firmwareKey: app.firmware_key, } const url = `${BASE_SOCKET_URL_SECURE}/install?${qs.stringify(params)}` - return createDeviceSocket(transport, url).toPromise() + return remapError(createDeviceSocket(transport, url).toPromise()) } diff --git a/src/helpers/apps/uninstallApp.js b/src/helpers/apps/uninstallApp.js index 570e361c..6ead5304 100644 --- a/src/helpers/apps/uninstallApp.js +++ b/src/helpers/apps/uninstallApp.js @@ -6,6 +6,18 @@ import { BASE_SOCKET_URL_SECURE } from 'config/constants' import { createDeviceSocket } from 'helpers/socket' import type { LedgerScriptParams } from 'helpers/common' +import createCustomErrorClass from '../createCustomErrorClass' + +const CannotUninstall = createCustomErrorClass('CannotUninstall') + +function remapError(promise) { + return promise.catch((e: Error) => { + if (e.message.endsWith('6a83')) { + throw new CannotUninstall() + } + throw e + }) +} /** * Install an app on the device @@ -22,5 +34,5 @@ export default async function uninstallApp( firmwareKey: app.delete_key, } const url = `${BASE_SOCKET_URL_SECURE}/install?${qs.stringify(params)}` - return createDeviceSocket(transport, url).toPromise() + return remapError(createDeviceSocket(transport, url).toPromise()) } diff --git a/src/icons/Trash.js b/src/icons/Trash.js index a6630967..992d7349 100644 --- a/src/icons/Trash.js +++ b/src/icons/Trash.js @@ -5,6 +5,7 @@ import React from 'react' const path = ( diff --git a/static/i18n/en/errors.yml b/static/i18n/en/errors.yml index 108a9402..80ebeeb0 100644 --- a/static/i18n/en/errors.yml +++ b/static/i18n/en/errors.yml @@ -16,7 +16,9 @@ NoAddressesFound: 'No accounts found' UserRefusedOnDevice: Transaction have been aborted WebsocketConnectionError: An error occurred with the socket connection WebsocketConnectionFailed: Failed to establish a socket connection -DeviceSocketFail: Device socket failure +DeviceSocketFail: 'Device socket failure ({{message}})' DeviceSocketNoBulkStatus: Device socket failure (bulk) DeviceSocketNoHandler: Device socket failure (handler {{query}}) LatestMCUInstalledError: The latest MCU is already installed on the Device +CannotUninstall: Cannot uninstall app +CannotInstall: Cannot install app