diff --git a/src/js/controllers/tx-details.js b/src/js/controllers/tx-details.js index 9b27d2f0d..c37e92f44 100644 --- a/src/js/controllers/tx-details.js +++ b/src/js/controllers/tx-details.js @@ -2,39 +2,16 @@ angular.module('copayApp.controllers').controller('txDetailsController', function($log, $ionicHistory, $scope, $timeout, walletService, lodash, gettextCatalog, profileService, configService, externalLinkService, popupService, ongoingProcess, txFormatService) { + var txId; + $scope.$on("$ionicView.beforeEnter", function(event, data) { + txId = data.stateParams.txid; $scope.title = gettextCatalog.getString('Transaction'); $scope.wallet = profileService.getWallet(data.stateParams.walletId); $scope.color = $scope.wallet.color; $scope.copayerId = $scope.wallet.credentials.copayerId; $scope.isShared = $scope.wallet.credentials.n > 1; - - ongoingProcess.set('loadingTxInfo', true); - walletService.getTx($scope.wallet, data.stateParams.txid, function(err, tx) { - ongoingProcess.set('loadingTxInfo', false); - if (err) { - $log.warn('Could not get tx'); - $ionicHistory.goBack(); - return popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Transaction not found')); - } - - $scope.btx = txFormatService.processTx(tx); - - if ($scope.btx.action != 'invalid') { - if ($scope.btx.action == 'sent') $scope.title = gettextCatalog.getString('Sent Funds'); - if ($scope.btx.action == 'received') $scope.title = gettextCatalog.getString('Received Funds'); - if ($scope.btx.action == 'moved') $scope.title = gettextCatalog.getString('Moved Funds'); - } - - $scope.displayAmount = getDisplayAmount($scope.btx.amountStr); - $scope.displayUnit = getDisplayUnit($scope.btx.amountStr); - - updateMemo(); - initActionList(); - $timeout(function() { - $scope.$apply(); - }); - }); + $scope.updateTx(); }); function getDisplayAmount(amountStr) { @@ -96,6 +73,39 @@ angular.module('copayApp.controllers').controller('txDetailsController', functio }, 10); } + $scope.updateTx = function() { + ongoingProcess.set('loadingTxInfo', true); + walletService.getTx($scope.wallet, txId, function(err, tx) { + ongoingProcess.set('loadingTxInfo', false); + if (err) { + $log.warn('Could not get tx'); + $ionicHistory.goBack(); + return popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Transaction not found')); + } + + $scope.btx = txFormatService.processTx(tx); + txFormatService.formatAlternativeStr(tx.fees, function(v) { + $scope.feeFiatStr = v; + }); + + if ($scope.btx.action != 'invalid') { + if ($scope.btx.action == 'sent') $scope.title = gettextCatalog.getString('Sent Funds'); + if ($scope.btx.action == 'received') $scope.title = gettextCatalog.getString('Received Funds'); + if ($scope.btx.action == 'moved') $scope.title = gettextCatalog.getString('Moved Funds'); + } + + $scope.displayAmount = getDisplayAmount($scope.btx.amountStr); + $scope.displayUnit = getDisplayUnit($scope.btx.amountStr); + + updateMemo(); + initActionList(); + getFiatRate(); + $timeout(function() { + $scope.$apply(); + }); + }); + }; + $scope.showCommentPopup = function() { var opts = {}; if ($scope.btx.message) { @@ -140,29 +150,21 @@ angular.module('copayApp.controllers').controller('txDetailsController', functio return n.substring(0, 4); }; - $scope.getFiatRate = function() { - if ($scope.rateDate) return; - var alternativeIsoCode = $scope.wallet.status.alternativeIsoCode; - $scope.loadingRate = true; + var getFiatRate = function() { + $scope.alternativeIsoCode = $scope.wallet.status.alternativeIsoCode; $scope.wallet.getFiatRate({ - code: alternativeIsoCode, + code: $scope.alternativeIsoCode, ts: $scope.btx.time * 1000 }, function(err, res) { - $scope.loadingRate = false; if (err) { $log.debug('Could not get historic rate'); return; } if (res && res.rate) { $scope.rateDate = res.fetchedOn; - $scope.rateStr = res.rate + ' ' + alternativeIsoCode; - $scope.$apply(); + $scope.rate = res.rate; } }); }; - $scope.cancel = function() { - $scope.txDetailsModal.hide(); - }; - }); diff --git a/www/views/tx-details.html b/www/views/tx-details.html index 876629110..7b45c77b8 100644 --- a/www/views/tx-details.html +++ b/www/views/tx-details.html @@ -5,9 +5,14 @@ + + + + + - + @@ -25,11 +30,13 @@ {{displayAmount}} {{displayUnit}} - + {{btx.alternativeAmountStr}} - {{rateStr}} ({{rateDate | amDateFormat:'MM/DD/YYYY HH:mm a'}}) - ... + ... + + {{rate| currency:'':2}} {{alternativeIsoCode}} ({{rateDate | amDateFormat:'MM/DD/YYYY HH:mm a'}}) + @@ -56,10 +63,16 @@ {{wallet.name}} - + Created by - {{btx.creatorName}} {{ (btx.ts || btx.createdOn ) * 1000 | amDateFormat:'MM/DD/YYYY hh:mm a'}} + {{btx.creatorName}} + + + + Date + + {{ (btx.ts || btx.createdOn || btx.time) * 1000 | amDateFormat:'MM/DD/YYYY hh:mm a'}} @@ -69,10 +82,11 @@ - + Fee - {{btx.feeStr}} + {{btx.feeStr}} + {{feeFiatStr}}