From 7ea75cd964b7c7e5e63f3ced9b3ef39dc9aeae17 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Wed, 9 Mar 2016 16:35:34 -0300 Subject: [PATCH] fix trezor --- src/js/services/trezor.js | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/js/services/trezor.js b/src/js/services/trezor.js index 7c1827814..199709886 100644 --- a/src/js/services/trezor.js +++ b/src/js/services/trezor.js @@ -9,10 +9,10 @@ angular.module('copayApp.services') root.getEntropySource = function(isMultisig, account, callback) { root.getXPubKey(hwWallet.getEntropyPath('trezor', isMultisig, account), function(data) { - if (!data.success) + if (!data.success) return callback(hwWallet._err(data)); - - return callback(null, hwWallet.pubKeyToEntropySource(data.xpubkey)); + + return callback(null, hwWallet.pubKeyToEntropySource(data.xpubkey)); }); }; @@ -75,8 +75,28 @@ angular.module('copayApp.services') outputs = []; var tmpOutputs = []; - if (txp.type != 'simple') + + if (txp.type && txp.type != 'simple') { return callback('Only TXPs type SIMPLE are supported in TREZOR'); + } else if (txp.outputs) { + if (txp.outputs.length > 1) + return callback('Only single output TXPs are supported in TREZOR'); + } else { + return callback('Unknown TXP at TREZOR'); + } + + if (txp.outputs) { + + if (!txp.toAddress) + txp.toAddress = txp.outputs[0].toAddress; + + if (!txp.amount) + txp.amount = txp.outputs[0].amount; + } + + if (!txp.toAddress || !txp.amount) + return callback('No address or amount at TREZOR signing'); + var toScriptType = 'PAYTOADDRESS'; if (txp.toAddress.charAt(0) == '2' || txp.toAddress.charAt(0) == '3')