use scope only - preferences (advanced)

This commit is contained in:
Javier 2016-06-13 16:13:35 -03:00
commit 9163127dca
22 changed files with 238 additions and 305 deletions

View file

@ -4,26 +4,13 @@ angular.module('copayApp.controllers').controller('preferencesHistory',
function($scope, $log, $timeout, storageService, go, profileService, lodash) {
var fc = profileService.focusedClient;
var c = fc.credentials;
this.csvReady = false;
$scope.csvReady = false;
$scope.csvHistory = function(isUpdating, cb) {
if (isUpdating) return;
this.csvHistory = function(cb) {
var allTxs = [];
function formatDate(date) {
var dateObj = new Date(date);
if (!dateObj) {
$log.debug('Error formating a date');
return 'DateError'
}
if (!dateObj.toJSON()) {
return '';
}
return dateObj.toJSON();
}
var step = 6;
var unique = {};
function getHistory(cb) {
storageService.getTxHistory(c.walletId, function(err, txs) {
if (err) return cb(err);
@ -38,16 +25,7 @@ angular.module('copayApp.controllers').controller('preferencesHistory',
allTxs.push(txsFromLocal);
return cb(null, lodash.flatten(allTxs));
});
}
var fc = profileService.focusedClient;
var c = fc.credentials;
if (!fc.isComplete())
return;
var self = this;
var allTxs = [];
};
$log.debug('Generating CSV from History');
getHistory(function(err, txs) {
@ -59,12 +37,12 @@ angular.module('copayApp.controllers').controller('preferencesHistory',
$log.debug('Wallet Transaction History Length:', txs.length);
self.satToUnit = 1 / self.unitToSatoshi;
$scope.satToUnit = 1 / $scope.unitToSatoshi;
var data = txs;
var satToBtc = 1 / 100000000;
self.csvContent = [];
self.csvFilename = 'Copay-' + (self.alias || self.walletName) + '.csv';
self.csvHeader = ['Date', 'Destination', 'Description', 'Amount', 'Currency', 'Txid', 'Creator', 'Copayers', 'Comment'];
$scope.csvContent = [];
$scope.csvFilename = 'Copay-' + ($scope.alias || $scope.walletName) + '.csv';
$scope.csvHeader = ['Date', 'Destination', 'Description', 'Amount', 'Currency', 'Txid', 'Creator', 'Copayers', 'Comment'];
var _amount, _note, _copayers, _creator, _comment;
data.forEach(function(it, index) {
@ -89,7 +67,7 @@ angular.module('copayApp.controllers').controller('preferencesHistory',
if (it.action == 'moved')
_note += ' Moved:' + (it.amount * satToBtc).toFixed(8)
self.csvContent.push({
$scope.csvContent.push({
'Date': formatDate(it.time * 1000),
'Destination': it.addressTo || '',
'Description': _note,
@ -103,7 +81,7 @@ angular.module('copayApp.controllers').controller('preferencesHistory',
if (it.fees && (it.action == 'moved' || it.action == 'sent')) {
var _fee = (it.fees * satToBtc).toFixed(8)
self.csvContent.push({
$scope.csvContent.push({
'Date': formatDate(it.time * 1000),
'Destination': 'Bitcoin Network Fees',
'Description': '',
@ -116,16 +94,31 @@ angular.module('copayApp.controllers').controller('preferencesHistory',
}
});
self.csvReady = true;
$scope.csvReady = true;
$timeout(function() {
$scope.$apply();
}, 100);
if (cb)
return cb();
return;
});
function formatDate(date) {
var dateObj = new Date(date);
if (!dateObj) {
$log.debug('Error formating a date');
return 'DateError'
}
if (!dateObj.toJSON()) {
return '';
}
return dateObj.toJSON();
};
};
this.clearTransactionHistory = function() {
$scope.clearTransactionHistory = function() {
storageService.removeTxHistory(c.walletId, function(err) {
if (err) {
$log.error(err);
@ -137,5 +130,5 @@ angular.module('copayApp.controllers').controller('preferencesHistory',
go.walletHome();
}, 100);
});
}
};
});