2014-03-26 05:18:42 -07:00
|
|
|
'use strict';
|
2014-06-12 13:42:26 -07:00
|
|
|
var bitcore = require('bitcore');
|
2014-03-26 05:18:42 -07:00
|
|
|
|
2014-06-03 13:42:36 -07:00
|
|
|
angular.module('copayApp.controllers').controller('TransactionsController',
|
2014-09-23 22:13:56 -07:00
|
|
|
function($scope, $rootScope, $timeout, controllerUtils, notification, rateService) {
|
2014-10-10 13:58:19 -07:00
|
|
|
controllerUtils.redirIfNotComplete();
|
|
|
|
|
2014-04-23 08:59:21 -07:00
|
|
|
|
2014-09-04 07:12:08 -07:00
|
|
|
var w = $rootScope.wallet;
|
|
|
|
|
2014-03-26 05:18:42 -07:00
|
|
|
$scope.title = 'Transactions';
|
2014-04-24 18:43:19 -07:00
|
|
|
$scope.loading = false;
|
2014-05-16 21:19:52 -07:00
|
|
|
$scope.lastShowed = false;
|
2014-04-25 13:53:19 -07:00
|
|
|
|
2014-05-20 11:14:52 -07:00
|
|
|
$scope.txpCurrentPage = 1;
|
|
|
|
$scope.txpItemsPerPage = 4;
|
2014-06-03 12:54:09 -07:00
|
|
|
$scope.blockchain_txs = [];
|
2014-09-23 22:13:56 -07:00
|
|
|
$scope.alternativeCurrency = [];
|
2014-05-20 11:14:52 -07:00
|
|
|
|
2014-09-04 07:12:08 -07:00
|
|
|
var satToUnit = 1 / w.settings.unitToSatoshi;
|
2014-06-16 08:44:18 -07:00
|
|
|
|
|
|
|
$scope.update = function() {
|
2014-08-25 06:44:20 -07:00
|
|
|
$scope.loading = true;
|
2014-06-16 08:44:18 -07:00
|
|
|
var from = ($scope.txpCurrentPage - 1) * $scope.txpItemsPerPage;
|
2014-05-20 14:34:55 -07:00
|
|
|
var opts = {
|
2014-08-06 09:59:33 -07:00
|
|
|
pending: false,
|
|
|
|
skip: [from, from + $scope.txpItemsPerPage]
|
2014-05-20 14:34:55 -07:00
|
|
|
};
|
|
|
|
controllerUtils.updateTxs(opts);
|
2014-08-06 09:59:33 -07:00
|
|
|
setTimeout(function() {
|
|
|
|
$rootScope.$digest();
|
|
|
|
}, 0);
|
2014-05-16 14:33:06 -07:00
|
|
|
};
|
|
|
|
|
2014-08-06 09:59:33 -07:00
|
|
|
$scope.show = function() {
|
2014-06-16 08:44:18 -07:00
|
|
|
$scope.loading = true;
|
|
|
|
setTimeout(function() {
|
2014-05-16 21:19:52 -07:00
|
|
|
$scope.update();
|
|
|
|
}, 10);
|
|
|
|
};
|
|
|
|
|
2014-06-16 08:44:18 -07:00
|
|
|
$scope.toogleLast = function() {
|
2014-05-16 21:19:52 -07:00
|
|
|
$scope.lastShowed = !$scope.lastShowed;
|
|
|
|
if ($scope.lastShowed) {
|
2014-06-03 12:54:09 -07:00
|
|
|
$scope.getTransactions();
|
2014-05-16 21:19:52 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-06-03 12:54:09 -07:00
|
|
|
$scope.getTransactions = function() {
|
2014-10-22 09:10:41 -07:00
|
|
|
var self = this;
|
2014-06-03 12:54:09 -07:00
|
|
|
var w = $rootScope.wallet;
|
2014-10-22 09:10:41 -07:00
|
|
|
if (!w) return;
|
|
|
|
|
2014-10-22 12:57:29 -07:00
|
|
|
$scope.blockchain_txs = w.cached_txs || [];
|
2014-06-03 12:54:09 -07:00
|
|
|
$scope.loading = true;
|
2014-10-22 09:10:41 -07:00
|
|
|
w.getTransactionHistory(function(err, res) {
|
|
|
|
if (err) throw err;
|
|
|
|
|
|
|
|
if (!res) {
|
|
|
|
$scope.loading = false;
|
|
|
|
$scope.lastShowed = false;
|
|
|
|
return;
|
2014-04-24 19:13:55 -07:00
|
|
|
}
|
2014-10-22 09:10:41 -07:00
|
|
|
|
2014-10-22 12:57:29 -07:00
|
|
|
$scope.blockchain_txs = w.cached_txs = res;
|
2014-10-22 09:10:41 -07:00
|
|
|
$scope.loading = false;
|
|
|
|
});
|
2014-04-22 21:55:00 -07:00
|
|
|
};
|
|
|
|
|
2014-10-22 09:10:41 -07:00
|
|
|
|
2014-07-31 16:34:21 -07:00
|
|
|
$scope.hasAction = function(actions, action) {
|
|
|
|
return actions.hasOwnProperty('create');
|
|
|
|
}
|
|
|
|
|
2014-05-08 14:14:49 -07:00
|
|
|
$scope.getShortNetworkName = function() {
|
2014-09-11 11:25:32 -07:00
|
|
|
return w.getNetworkName().substring(0, 4);
|
2014-05-08 14:14:49 -07:00
|
|
|
};
|
|
|
|
|
2014-06-24 11:46:07 -07:00
|
|
|
// Autoload transactions on 1-of-1
|
|
|
|
if ($rootScope.wallet && $rootScope.wallet.totalCopayers == 1) {
|
|
|
|
$scope.lastShowed = true;
|
|
|
|
$scope.getTransactions();
|
|
|
|
}
|
|
|
|
|
2014-10-22 09:10:41 -07:00
|
|
|
$scope.amountAlternative = function(amount, txIndex, cb) {
|
2014-09-23 22:13:56 -07:00
|
|
|
var w = $rootScope.wallet;
|
|
|
|
rateService.whenAvailable(function() {
|
|
|
|
var valueSat = amount * w.settings.unitToSatoshi;
|
|
|
|
$scope.alternativeCurrency[txIndex] = rateService.toFiat(valueSat, w.settings.alternativeIsoCode);
|
2014-09-25 12:50:15 -07:00
|
|
|
return cb ? cb() : null;
|
2014-09-23 22:13:56 -07:00
|
|
|
});
|
|
|
|
};
|
2014-03-26 05:18:42 -07:00
|
|
|
});
|