From 9918f95289f8b4678672271bcd2a515c45b7cd3e Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Mon, 5 Oct 2015 15:57:59 -0300 Subject: [PATCH 1/2] Handle TREZOR error --- src/js/services/trezor.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/js/services/trezor.js b/src/js/services/trezor.js index d9d7e15de..f1caf963f 100644 --- a/src/js/services/trezor.js +++ b/src/js/services/trezor.js @@ -39,8 +39,9 @@ angular.module('copayApp.services') var opts = {}; root.getEntropySource(account, function(data) { if (!data.success) { - $log.warn(data.message); - return callback(data.message); + var err = data.message || data.error || 'TREZOR Error'; + $log.warn(err); + return callback(err); } opts.entropySource = data.entropySource; $log.debug('Waiting TREZOR to settle...'); From ba9d6b044bd181a9fc886ba073f13fb8e6a76787 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Mon, 5 Oct 2015 16:36:33 -0300 Subject: [PATCH 2/2] better error handling 2 --- src/js/services/profileService.js | 8 ++------ src/js/services/trezor.js | 32 +++++++++++++++++-------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index 907483da2..e6d5d681a 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -569,15 +569,11 @@ console.log('[profileService.js.239:walletClient:]',walletClient); //TODO var fc = root.focusedClient; $log.info('Requesting Trezor to sign the transaction'); -console.log('[profileService.js.570] xPub:', fc.credentials.xPubKey); //TODO var xPubKeys = lodash.pluck(fc.credentials.publicKeyRing,'xPubKey'); -console.log('[profileService.js.571:xPubKeys:]',xPubKeys); //TODO + trezor.signTx(xPubKeys, txp, 0, function(err, result) { + if (err) return cb(err); - trezor.signTx(xPubKeys, txp, 0, function(result) { $log.debug('Trezor response',result); - if (!result.success) - return cb(result.error || result); - txp.signatures = result.signatures; return fc.signTxProposal(txp, cb); }); diff --git a/src/js/services/trezor.js b/src/js/services/trezor.js index f1caf963f..c06b61f55 100644 --- a/src/js/services/trezor.js +++ b/src/js/services/trezor.js @@ -9,19 +9,25 @@ angular.module('copayApp.services') root.ENTROPY_INDEX_PATH = "0xb11e/"; root.callbacks = {}; + + root._err = function(data) { + var msg = 'TREZOR Error: ' + (data.error || data.message || 'unknown'); + $log.warn(msg); + return msg; + }; + root.getEntropySource = function(account, callback) { var path = root.ENTROPY_INDEX_PATH + account + "'"; var xpub = root.getXPubKey(path, function(data) { if (!data.success) { - $log.warn(data.message); - return callback(data); + return callback(root._err(data)); } var b = bwcService.getBitcore(); var x = b.HDPublicKey(data.xpubkey); data.entropySource = x.publicKey.toString(); - return callback(data); + return callback(null, data); }); }; @@ -37,20 +43,15 @@ angular.module('copayApp.services') root.getInfoForNewWallet = function(account, callback) { var opts = {}; - root.getEntropySource(account, function(data) { - if (!data.success) { - var err = data.message || data.error || 'TREZOR Error'; - $log.warn(err); - return callback(err); - } + root.getEntropySource(account, function(err, data) { + if (err) return callback(err); opts.entropySource = data.entropySource; $log.debug('Waiting TREZOR to settle...'); $timeout(function() { root.getXPubKeyForAddresses(account, function(data) { - if (!data.success) { - $log.warn(data.message); - return callback(data); - } + if (!data.success) + return callback(root._err(data)); + opts.extendedPublicKey = data.xpubkey; opts.externalSource = 'trezor'; opts.externalIndex = account; @@ -226,7 +227,10 @@ angular.module('copayApp.services') $log.debug('Signing with TREZOR', inputs, outputs); TrezorConnect.signTx(inputs, outputs, function(result) { - callback(result); + if (!data.success) + return callback(root._err(data)); + + callback(null, result); }); };