Ref tx-details. Transition smoother. Show date on receive tx. Pre-load exchange rate. Click on confirmation line to refresh tx

This commit is contained in:
Gustavo Maximiliano Cortez 2017-03-07 15:23:02 -03:00
commit a27addfdc3
No known key found for this signature in database
GPG key ID: 15EDAD8D9F2EB1AF
2 changed files with 53 additions and 46 deletions

View file

@ -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,36 @@ 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);
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 +147,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();
};
});