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
parent bbd20482be
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();
};
});

View File

@ -7,7 +7,7 @@
</ion-nav-back-button>
</ion-nav-bar>
<ion-content class="tx-details-content">
<ion-content class="tx-details-content" ng-show="btx">
<div class="list">
<div class="item head">
<div class="sending-label" ng-if="btx.confirmations > 0">
@ -25,11 +25,13 @@
</div>
<div class="amount-label">
<div class="amount">{{displayAmount}} <span class="unit">{{displayUnit}}</span></div>
<div class="alternative" ng-click="getFiatRate(); showRate = !showRate">
<div class="alternative" ng-click="showRate = !showRate">
<span ng-show="!showRate">{{btx.alternativeAmountStr}}</span>
<span ng-show="showRate">
<span ng-show="!loadingRate">{{rateStr}} ({{rateDate | amDateFormat:'MM/DD/YYYY HH:mm a'}})</span>
<span ng-show="loadingRate">...</span>
<span ng-show="!rate">...</span>
<span ng-show="rate">
{{rate| currency:'':2}} {{alternativeIsoCode}} ({{rateDate | amDateFormat:'MM/DD/YYYY HH:mm a'}})
</span>
</span>
</div>
</div>
@ -56,10 +58,16 @@
<div>{{wallet.name}}</div>
</div>
</div>
<div class="item single-line" ng-if="btx.action != 'received'">
<div class="item single-line" ng-if="btx.action != 'received' && isShared">
<span class="label" translate>Created by</span>
<span class="item-note">
{{btx.creatorName}} <time>{{ (btx.ts || btx.createdOn ) * 1000 | amDateFormat:'MM/DD/YYYY hh:mm a'}}</time>
{{btx.creatorName}}
</span>
</div>
<div class="item single-line" ng-if="btx.ts || btx.createdOn || btx.time">
<span class="label" translate>Date</span>
<span class="item-note">
<time>{{ (btx.ts || btx.createdOn || btx.time) * 1000 | amDateFormat:'MM/DD/YYYY hh:mm a'}}</time>
</span>
</div>
<a class="item item-icon-right" ng-class="{'single-line': !btx.note.body && !btx.message}" ng-click="showCommentPopup()">
@ -75,7 +83,7 @@
{{btx.feeStr}}
</span>
</div>
<div class="item single-line">
<div class="item single-line" ng-click="updateTx()">
<span class="label" translate>Confirmations</span>
<span class="item-note">
<span ng-show="!btx.confirmations || btx.confirmations == 0" translate>