From c062232976027f846e96f45e2b8a7f22992ed43c Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Wed, 8 Mar 2017 15:55:30 -0300 Subject: [PATCH] better error handling of getTx --- src/js/controllers/tx-details.js | 4 ++-- src/js/services/walletService.js | 25 ++++++++++--------------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/js/controllers/tx-details.js b/src/js/controllers/tx-details.js index fc1deba81..619bc3781 100644 --- a/src/js/controllers/tx-details.js +++ b/src/js/controllers/tx-details.js @@ -93,9 +93,9 @@ angular.module('copayApp.controllers').controller('txDetailsController', functio walletService.getTx($scope.wallet, txId, function(err, tx) { ongoingProcess.set('loadingTxInfo', false); if (err) { - $log.warn('Could not get tx'); + $log.warn('Error getting transaction' + err); $ionicHistory.goBack(); - return popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Transaction not found')); + return popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Transaction not available at this time')); } $scope.btx = txFormatService.processTx(tx); diff --git a/src/js/services/walletService.js b/src/js/services/walletService.js index 746631a8d..4f5a36e26 100644 --- a/src/js/services/walletService.js +++ b/src/js/services/walletService.js @@ -523,32 +523,27 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim }; root.getTx = function(wallet, txid, cb) { - var tx; - if (wallet.completeHistory && wallet.completeHistory.isValid) { - tx = lodash.find(wallet.completeHistory, { - txid: txid + function finish(list){ + var tx = lodash.find(list, { + txid: txid }); - finish(); + if (!tx) return cb('Could not get transaction'); + return cb(null, tx); + }; + + if (wallet.completeHistory && wallet.completeHistory.isValid) { + finish(wallet.completeHistory); } else { root.getTxHistory(wallet, { limitTx: txid }, function(err, txHistory) { if (err) return cb(err); - tx = lodash.find(txHistory, { - txid: txid - }); - - finish(); + finish(txHistory); }); } - - function finish() { - if (tx) return cb(null, tx); - else return cb(); - }; };