Skip to content

Commit

Permalink
Improved error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Toporin committed Aug 18, 2021
1 parent 9d35ca2 commit 6f427fb
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 35 deletions.
2 changes: 2 additions & 0 deletions src/translations/en_US.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import secalotError from './errors-secalot/en_US';
import keepkeyError from './errors-keepkey/en_US';
import bitboxError from './errors-bitbox/en_US';
import bitbox02Error from './errors-bitbox02/en_US';
import satochipError from './errors-satochip/en_US';
import buyHardwareWallet from './other/buy-hardware-wallet/en_US';
import convertUnits from './other/convert-units/en_US';
import verifyMessage from './other/verify-message/en_US';
Expand Down Expand Up @@ -66,6 +67,7 @@ const en_US = {
keepkeyError: keepkeyError,
bitboxError: bitboxError,
bitbox02Error: bitbox02Error,
satochipError: satochipError,
buyHardwareWallet: buyHardwareWallet,
dappsMaker: dappsMaker,
convertUnits: convertUnits,
Expand Down
15 changes: 15 additions & 0 deletions src/translations/errors-satochip/en_US.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"popup-closed": "Popup Closed",
"device-disconnect": "Device disconnected",
"device-disconnect-action": "device disconnected during action",
"user-cancelled-action": "Action cancelled by user",
"no-permission": "Permissions not granted",
"call-in-progress": "Device call in progress",
"cancelled": "Event cancelled by user",
"iframe-timeout": "Make sure you enable pop-ups in the browser, and that your ad blocker is not blocking the pop-up",
"popup-failed-to-open": "Popup failed to open. Make sure you enable pop-ups in the browser, and that your ad blocker is not blocking the pop-up",
"connect-error": "Satochip: error while connecting to Satochip-Bridge. Make sure that Satochip-Bridge is up and running",
"noresponse-2FA": "Satochip: no response received from 2FA device",
"rejected-2FA": "Satochip: signing request rejected by user",
"no-card-found": "Satochip error: no card found! Please insert a Satochip"
}
15 changes: 15 additions & 0 deletions src/translations/errors-satochip/es_ES.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"popup-closed": "Popup Closed",
"device-disconnect": "Device disconnected",
"device-disconnect-action": "device disconnected during action",
"user-cancelled-action": "Action cancelled by user",
"no-permission": "Permissions not granted",
"call-in-progress": "Device call in progress",
"cancelled": "Event cancelled by user",
"iframe-timeout": "Make sure you enable pop-ups in the browser, and that your ad blocker is not blocking the pop-up",
"popup-failed-to-open": "Popup failed to open. Make sure you enable pop-ups in the browser, and that your ad blocker is not blocking the pop-up",
"connect-error": "Satochip: error while connecting to Satochip-Bridge. Make sure that Satochip-Bridge is up and running",
"noresponse-2FA": "Satochip: no response received from 2FA device",
"rejected-2FA": "Satochip: signing request rejected by user",
"no-card-found": "Satochip error: no card found! Please insert a Satochip"
}
15 changes: 15 additions & 0 deletions src/translations/errors-satochip/ja_JP.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"popup-closed": "Popup Closed",
"device-disconnect": "Device disconnected",
"device-disconnect-action": "device disconnected during action",
"user-cancelled-action": "Action cancelled by user",
"no-permission": "Permissions not granted",
"call-in-progress": "Device call in progress",
"cancelled": "Event cancelled by user",
"iframe-timeout": "Make sure you enable pop-ups in the browser, and that your ad blocker is not blocking the pop-up",
"popup-failed-to-open": "Popup failed to open. Make sure you enable pop-ups in the browser, and that your ad blocker is not blocking the pop-up",
"connect-error": "Satochip: error while connecting to Satochip-Bridge. Make sure that Satochip-Bridge is up and running",
"noresponse-2FA": "Satochip: no response received from 2FA device",
"rejected-2FA": "Satochip: signing request rejected by user",
"no-card-found": "Satochip error: no card found! Please insert a Satochip"
}
15 changes: 15 additions & 0 deletions src/translations/errors-satochip/ko_KR.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"popup-closed": "Popup Closed",
"device-disconnect": "Device disconnected",
"device-disconnect-action": "device disconnected during action",
"user-cancelled-action": "Action cancelled by user",
"no-permission": "Permissions not granted",
"call-in-progress": "Device call in progress",
"cancelled": "Event cancelled by user",
"iframe-timeout": "Make sure you enable pop-ups in the browser, and that your ad blocker is not blocking the pop-up",
"popup-failed-to-open": "Popup failed to open. Make sure you enable pop-ups in the browser, and that your ad blocker is not blocking the pop-up",
"connect-error": "Satochip: error while connecting to Satochip-Bridge. Make sure that Satochip-Bridge is up and running",
"noresponse-2FA": "Satochip: no response received from 2FA device",
"rejected-2FA": "Satochip: signing request rejected by user",
"no-card-found": "Satochip error: no card found! Please insert a Satochip"
}
15 changes: 15 additions & 0 deletions src/translations/errors-satochip/ru_RU.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"popup-closed": "Popup Closed",
"device-disconnect": "Device disconnected",
"device-disconnect-action": "device disconnected during action",
"user-cancelled-action": "Action cancelled by user",
"no-permission": "Permissions not granted",
"call-in-progress": "Device call in progress",
"cancelled": "Event cancelled by user",
"iframe-timeout": "Make sure you enable pop-ups in the browser, and that your ad blocker is not blocking the pop-up",
"popup-failed-to-open": "Popup failed to open. Make sure you enable pop-ups in the browser, and that your ad blocker is not blocking the pop-up",
"connect-error": "Satochip: error while connecting to Satochip-Bridge. Make sure that Satochip-Bridge is up and running",
"noresponse-2FA": "Satochip: no response received from 2FA device",
"rejected-2FA": "Satochip: signing request rejected by user",
"no-card-found": "Satochip error: no card found! Please insert a Satochip"
}
15 changes: 15 additions & 0 deletions src/translations/errors-satochip/zh_CN.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"popup-closed": "Popup Closed",
"device-disconnect": "Device disconnected",
"device-disconnect-action": "device disconnected during action",
"user-cancelled-action": "Action cancelled by user",
"no-permission": "Permissions not granted",
"call-in-progress": "Device call in progress",
"cancelled": "Event cancelled by user",
"iframe-timeout": "Make sure you enable pop-ups in the browser, and that your ad blocker is not blocking the pop-up",
"popup-failed-to-open": "Popup failed to open. Make sure you enable pop-ups in the browser, and that your ad blocker is not blocking the pop-up",
"connect-error": "Satochip: error while connecting to Satochip-Bridge. Make sure that Satochip-Bridge is up and running",
"noresponse-2FA": "Satochip: no response received from 2FA device",
"rejected-2FA": "Satochip: signing request rejected by user",
"no-card-found": "Satochip error: no card found! Please insert a Satochip"
}
37 changes: 19 additions & 18 deletions src/wallets/hardware/satochip/errorHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,19 @@ import { Toast } from '@/helpers';
import Vue from 'vue';

const ERRORS = {
'Popup closed': 'trezorError.popup-closed',
'Device disconnected': 'trezorError.device-disconnect',
'device disconnected during action': 'trezorError.device-disconnect-action',
'Action cancelled by user': 'trezorError.user-cancelled-action',
'Permissions not granted': 'trezorError.no-permission',
'Device call in progress': 'trezorError.call-in-progress',
'Transport is missing': 'trezorError.transport-missing',
'EthAppPleaseEnableContractData: Please enable Contract data on the Ethereum app Settings':
'trezorError.turn-on-contract-data',
'Initialize failed: Response of unexpected type: Address. Should be Features':
'trezor.initializing-failed',
Cancelled: 'trezorError.cancelled',
'Iframe timeout': 'trezor.iframe-timeout',
'Browser not supported': 'trezor.unsupported-browser',
'popup failed to open': 'trezor.popup-failed-to-open',
'Safety check failed': 'trezor.safety-check-failed',
'TrezorConnect not yet initialized': 'trezor.trezor-connect-not-initialized'
'Popup closed': 'satochipError.popup-closed',
'Device disconnected': 'satochipError.device-disconnect',
'device disconnected during action': 'satochipError.device-disconnect-action',
'Action cancelled by user': 'satochipError.user-cancelled-action',
'Permissions not granted': 'satochipError.no-permission',
'Device call in progress': 'satochipError.call-in-progress',
Cancelled: 'satochipError.cancelled',
'Iframe timeout': 'satochipError.iframe-timeout',
'popup failed to open': 'satochipError.popup-failed-to-open',
'Satochip: error while connecting to Satochip-Bridge': 'satochipError.connect-error',
'No response received from 2FA': 'satochipError.noresponse-2FA',
'Signing request rejected by user': 'satochipError.rejected-2FA',
'No card found': 'satochipError.no-card-found'
};

const WARNING = {};
Expand All @@ -27,7 +23,12 @@ export default err => {
const errorValues = Object.keys(ERRORS);
const warningValues = Object.keys(WARNING);
const foundError = errorValues.find(item => {
return err.message.includes(item) || item.includes(err);
return (
item.includes(err.message) ||
item.includes(err) ||
(err.message && err.message.includes(item)) ||
(typeof err === 'string' && err.includes(item))
);
});

const foundWarning = warningValues.find(item => {
Expand Down
49 changes: 32 additions & 17 deletions src/wallets/hardware/satochip/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class SatochipWallet {
this.resolveMap= new Map();
this.requestID=0;
this.ws= 0;
this.reconnectInterval = (1 * 1000 * 60) / 4;
this.reconnectInterval = (1 * 1000 * 60) / 4; //time in ms

} // end constructor()

Expand Down Expand Up @@ -55,7 +55,7 @@ class SatochipWallet {
};
const request = JSON.stringify(msg);

return new Promise((resolve) => {
return new Promise((resolve, reject) => {
// send request to device and keep a ref of the resolve function in a map
new Promise((resolve2) => {
console.log('Satochip: resolveMap.size - before:' + this.resolveMap.size);
Expand All @@ -66,10 +66,14 @@ class SatochipWallet {
//console.log('Satochip: resolveMap.size - after:' + this.resolveMap.size);
}).then((res) => {
console.log('In satochip-connect-tab: getChainCode: res: ', res);
resolve({
publicKey: res.pubkey,
chainCode: res.chaincode
});
if (res.exitstatus == 0){//no issue
resolve({
publicKey: res.pubkey,
chainCode: res.chaincode
});
}else{// there was an issue
reject(res.reason)
}
});
})
});
Expand Down Expand Up @@ -124,6 +128,8 @@ class SatochipWallet {
mywallet.ws.onerror = function error() {
console.log('disconnected with error!');
mywallet.isConnected = false;
//throw new Error('Satochip: error while connecting to Satochip-Bridge')
errorHandler('Satochip: error while connecting to Satochip-Bridge')
};
} else {
resolve(mywallet.ws);
Expand Down Expand Up @@ -151,7 +157,7 @@ class SatochipWallet {
const request = JSON.stringify(msg);
const chainId= tx_info.chainId;

return new Promise((resolve) => {
return new Promise((resolve, reject) => {
// send request to device and keep a ref of the resolve function in a map
new Promise((resolve2) => {
this.resolveMap.set(msg.requestID, resolve2);
Expand All @@ -160,9 +166,12 @@ class SatochipWallet {
}).then((res) => {
// extracts usefull data from device response and resolve original promise
console.log('In satochip-connect-tab: signRawTransaction: res: ', res);
const payload={ v: (res.v+chainId*2+35), r:res.r, s:res.s}
resolve(payload);

if (res.exitstatus == 0){//no issue
const payload={ v: (res.v+chainId*2+35), r:res.r, s:res.s}
resolve(payload);
}else{// there was an issue
reject(res.reason)
}
});
});
});
Expand All @@ -172,7 +181,8 @@ class SatochipWallet {
console.log('Satochip: signMessage() START');
// message is a hex-string prefixed with 0x
if (!msg) {
throw Error('No message to sign');
//throw new Error('No message to sign');
errorHandler('No message to sign');
}

return this.connect().then((ws) => {
Expand All @@ -194,11 +204,16 @@ class SatochipWallet {
}).then((res) => {
// extracts usefull data from device response and resolve original promise
console.log('Satochip: signMessage: result: ' + res);
const r = res.r;
const s = res.s;
const v = ('0' + res.v.toString(16)).slice(-2); //padd with '0'
const combined = '0x'+r + s + v;
resolve(combined);
if (res.exitstatus == 0){//no issue
const r = res.r;
const s = res.s;
const v = ('0' + res.v.toString(16)).slice(-2); //padd with '0'
const combined = '0x'+r + s + v;
resolve(combined);
}else{// there was an issue
//throw new Error(res.reason); //reject(res.reason)
errorHandler(res.reason)
}
});
});
});
Expand Down Expand Up @@ -294,4 +309,4 @@ const createWallet = async basePath => {
};

createWallet.errorHandler = errorHandler;
export default createWallet;
export default createWallet;

0 comments on commit 6f427fb

Please sign in to comment.