/
TrezorLocalizedError.js
64 lines (57 loc) · 2.23 KB
/
TrezorLocalizedError.js
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// @flow
import LocalizableError, { UnexpectedError } from '../i18n/LocalizableError';
import globalMessages from '../i18n/global-messages';
import { defineMessages } from 'react-intl';
import {
Logger,
} from '../utils/logging';
const messages = defineMessages({
signTxError101: {
id: 'wallet.send.trezor.error.101',
defaultMessage: '!!!Signing cancelled on Trezor device. Please retry.',
},
firmwareCatalystSupportError: {
id: 'wallet.send.tezor.error.firmwareCatalystSupport',
defaultMessage: '!!!Registering for Catalyst voting requires Trezor firmware 2.4.1',
},
});
/** Converts error(from API or Trezor API) to LocalizableError */
export function convertToLocalizableError(error: Error): LocalizableError {
let localizableError: ?LocalizableError = null;
if (error instanceof LocalizableError) {
// It means some API Error has been thrown
localizableError = error;
} else if (error && error.message) {
// Trezor device related error happend, convert then to LocalizableError
switch (error.message) {
case 'Iframe timeout':
localizableError = new LocalizableError(globalMessages.trezorError101);
break;
case 'Permissions not granted':
localizableError = new LocalizableError(globalMessages.hwError101);
break;
case 'Cancelled':
case 'Popup closed':
localizableError = new LocalizableError(globalMessages.trezorError103);
break;
case 'Signing cancelled':
localizableError = new LocalizableError(messages.signTxError101);
break;
case 'Feature AuxiliaryData not supported by device firmware':
localizableError = new LocalizableError(messages.firmwareCatalystSupportError);
break;
default:
/** we are not able to figure out why Error is thrown
* make it, Something unexpected happened */
Logger.error(`TrezorLocalizedError::${nameof(convertToLocalizableError)}::error: ${error.message}`);
localizableError = new UnexpectedError();
break;
}
}
if (!localizableError) {
/** we are not able to figure out why Error is thrown
* make it, Something unexpected happened */
localizableError = new UnexpectedError();
}
return localizableError;
}