Merge pull request #3095 from cmgustavo/bug/modal-txp-05

Fixes txp modals for single outputs
This commit is contained in:
Matias Alejo Garcia 2015-08-21 10:53:05 -03:00
commit 0791c3fc32
8 changed files with 128 additions and 119 deletions

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.controllers').controller('indexController', function($rootScope, $scope, $log, $filter, $timeout, lodash, go, profileService, configService, isCordova, rateService, storageService, addressService, gettextCatalog, gettext, amMoment, nodeWebkit, addonManager, feeService, isChromeApp, bwsError) {
angular.module('copayApp.controllers').controller('indexController', function($rootScope, $scope, $log, $filter, $timeout, lodash, go, profileService, configService, isCordova, rateService, storageService, addressService, gettextCatalog, gettext, amMoment, nodeWebkit, addonManager, feeService, isChromeApp, bwsError, utilService) {
var self = this;
self.isCordova = isCordova;
self.onGoingProcess = {};
@ -469,49 +469,11 @@ angular.module('copayApp.controllers').controller('indexController', function($r
});
};
self.summarizeOutputs = function(tx, formatAmount) {
tx.showSingle = true;
if (tx.outputs) {
tx.showSingle = false;
tx.outputs.details = lodash.clone(tx.outputs);
var total = lodash.reduce(tx.outputs.details, function(total, o) {
formatAmount(o);
return total + o.amount;
}, 0);
if (tx.action != 'received') {
tx.amount = total;
}
tx.outputs.summary = {
amount: tx.amount,
message: tx.message,
isSummary: true,
showDetails: false,
recipientCount: tx.outputs.details.length
};
formatAmount(tx.outputs.summary);
if (tx.outputs.length === 1 && !tx.outputs[0].message) {
tx.showSingle = true;
tx.toAddress = tx.outputs[0].toAddress; // txproposal
tx.address = tx.outputs[0].address; // txhistory
}
}
};
self.setPendingTxps = function(txps) {
var config = configService.getSync().wallet.settings;
self.pendingTxProposalsCountForUs = 0;
lodash.each(txps, function(tx) {
function formatAmount(tx) {
tx.amountStr = profileService.formatAmount(tx.amount) + ' ' + config.unitName;
tx.alternativeAmount = rateService.toFiat(tx.amount, config.alternativeIsoCode) ? rateService.toFiat(tx.amount, config.alternativeIsoCode).toFixed(2) : 'N/A';
tx.alternativeAmountStr = tx.alternativeAmount + " " + config.alternativeIsoCode;
};
self.summarizeOutputs(tx, formatAmount);
formatAmount(tx);
tx.feeStr = profileService.formatAmount(tx.fee) + ' ' + config.unitName;
tx.alternativeIsoCode = config.alternativeIsoCode;
tx = utilService.processTx(tx);
var action = lodash.find(tx.actions, {
copayerId: self.copayerId
@ -546,21 +508,12 @@ angular.module('copayApp.controllers').controller('indexController', function($r
var c = 0;
self.txHistoryPaging = txs[self.limitHistory] ? true : false;
lodash.each(txs, function(tx) {
tx = utilService.processTx(tx);
// no future transactions...
if (tx.time > now)
tx.time = now;
tx.rateTs = Math.floor((tx.ts || now) / 1000);
if (tx.fees)
tx.feeStr = profileService.formatAmount(tx.fees) + ' ' + config.unitName;
function formatAmount(tx) {
tx.amountStr = profileService.formatAmount(tx.amount); //$filter('noFractionNumber')(
};
self.summarizeOutputs(tx, formatAmount);
formatAmount(tx);
if (c < self.limitHistory) {
self.txHistory.push(tx);
c++;

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.controllers').controller('walletHomeController', function($scope, $rootScope, $timeout, $filter, $modal, $log, notification, txStatus, isCordova, profileService, lodash, configService, rateService, storageService, bitcore, isChromeApp, gettext, gettextCatalog, nodeWebkit, addressService, feeService, bwsError) {
angular.module('copayApp.controllers').controller('walletHomeController', function($scope, $rootScope, $timeout, $filter, $modal, $log, notification, txStatus, isCordova, profileService, lodash, configService, rateService, storageService, bitcore, isChromeApp, gettext, gettextCatalog, nodeWebkit, addressService, feeService, bwsError, utilService) {
var self = this;
$rootScope.hideMenuBar = false;
@ -171,9 +171,6 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
var ModalInstanceCtrl = function($scope, $modalInstance) {
$scope.error = null;
$scope.tx = tx;
$scope.amountStr = tx.amountStr;
$scope.feeStr = tx.feeStr;
$scope.alternativeAmountStr = tx.alternativeAmountStr;
$scope.copayers = copayers
$scope.copayerId = fc.credentials.copayerId;
$scope.canSign = fc.canSign();
@ -204,7 +201,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
var action = lodash.find(tx.actions, {
copayerId: fc.credentials.copayerId
});
$scope.tx = tx;
$scope.tx = utilService.processTx(tx);
if (!action && tx.status == 'pending')
$scope.tx.pendingForUs = true;
$scope.updateCopayerList();
@ -348,10 +345,6 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
self.copyAddress(addr);
};
$scope.toggleOutputDetails = function(summary) {
summary.showDetails = !summary.showDetails;
};
$scope.cancel = function() {
$modalInstance.dismiss('cancel');
};
@ -1014,7 +1007,6 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
$scope.color = fc.backgroundColor;
$scope.copayerId = fc.credentials.copayerId;
$scope.isShared = fc.credentials.n > 1;
$scope.feeStr = btx.feeStr;
$scope.getAmount = function(amount) {
return self.getAmount(amount);
@ -1038,9 +1030,6 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
$modalInstance.dismiss('cancel');
};
$scope.toggleOutputDetails = function(summary) {
summary.showDetails = !summary.showDetails;
};
};
var modalInstance = $modal.open({

View file

@ -0,0 +1,46 @@
'use strict';
angular.module('copayApp.services').factory('utilService', function(profileService, rateService, configService, lodash) {
var root = {};
var formatAmountStr = function(amount) {
if (!amount) return;
var config = configService.getSync().wallet.settings;
return profileService.formatAmount(amount) + ' ' + config.unitName;
};
var formatAlternativeStr = function(amount) {
if (!amount) return;
var config = configService.getSync().wallet.settings;
return (rateService.toFiat(amount, config.alternativeIsoCode) ? rateService.toFiat(amount, config.alternativeIsoCode).toFixed(2) : 'N/A') + ' ' + config.alternativeIsoCode;
};
var formatFeeStr = function(fee) {
if (!fee) return;
var config = configService.getSync().wallet.settings;
return profileService.formatAmount(fee) + ' ' + config.unitName;
};
root.processTx = function(tx) {
if (!tx) return;
var outputs = tx.outputs ? tx.outputs.length : 0;
if (outputs > 1 && tx.action != 'received') {
tx.hasMultiplesOutputs = true;
tx.recipientCount = outputs;
tx.amount = lodash.reduce(tx.outputs, function(total, o) {
o.amountStr = formatAmountStr(o.amount);
o.alternativeAmountStr = formatAlternativeStr(o.amount);
return total + o.amount;
}, 0);
}
tx.amountStr = formatAmountStr(tx.amount);
tx.alternativeAmountStr = formatAlternativeStr(tx.amount);
tx.feeStr = formatFeeStr(tx.fee || tx.fees);
return tx;
};
return root;
});