2014-03-26 05:18:42 -07:00
|
|
|
'use strict';
|
|
|
|
|
2014-06-03 12:39:06 -07:00
|
|
|
angular.module('copayApp.transactions').controller('TransactionsController',
|
2014-05-26 06:46:05 -07:00
|
|
|
function($scope, $rootScope, $timeout, controllerUtils) {
|
2014-04-23 08:59:21 -07:00
|
|
|
|
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.onlyPending = true;
|
|
|
|
$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-05-16 14:33:06 -07:00
|
|
|
$scope.update = function () {
|
|
|
|
$scope.loading = false;
|
2014-05-20 14:34:55 -07:00
|
|
|
var from = ($scope.txpCurrentPage-1) * $scope.txpItemsPerPage;
|
|
|
|
var opts = {
|
|
|
|
onlyPending: $scope.onlyPending,
|
|
|
|
skip: !$scope.onlyPending ? [from, from + $scope.txpItemsPerPage] : null
|
|
|
|
};
|
|
|
|
controllerUtils.updateTxs(opts);
|
2014-05-16 14:33:06 -07:00
|
|
|
$rootScope.$digest();
|
|
|
|
};
|
|
|
|
|
2014-05-16 21:19:52 -07:00
|
|
|
$scope.show = function (onlyPending) {
|
|
|
|
$scope.loading=true;
|
|
|
|
$scope.onlyPending = onlyPending;
|
|
|
|
setTimeout(function(){
|
|
|
|
$scope.update();
|
|
|
|
}, 10);
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.toogleLast = function () {
|
2014-05-26 06:46:05 -07:00
|
|
|
$scope.loading = true;
|
2014-05-16 21:19:52 -07:00
|
|
|
$scope.lastShowed = !$scope.lastShowed;
|
|
|
|
if ($scope.lastShowed) {
|
|
|
|
$scope.getTransactions(function(txs){
|
2014-05-26 06:46:05 -07:00
|
|
|
$timeout(function() {
|
|
|
|
$scope.loading = false;
|
|
|
|
$scope.blockchain_txs = txs;
|
|
|
|
$scope.$digest();
|
|
|
|
}, 10);
|
2014-05-16 21:19:52 -07:00
|
|
|
});
|
2014-05-26 06:46:05 -07:00
|
|
|
} else {
|
|
|
|
$timeout(function(){
|
|
|
|
$scope.loading = false;
|
2014-05-16 21:21:15 -07:00
|
|
|
$rootScope.$digest();
|
2014-05-26 06:46:05 -07:00
|
|
|
}, 10);
|
2014-05-16 21:19:52 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-05-16 14:33:06 -07:00
|
|
|
$scope.send = function (ntxid,cb) {
|
2014-04-24 18:43:19 -07:00
|
|
|
$scope.loading = true;
|
2014-05-15 08:51:52 -07:00
|
|
|
$rootScope.txAlertCount = 0;
|
2014-04-20 17:53:54 -07:00
|
|
|
var w = $rootScope.wallet;
|
|
|
|
w.sendTx(ntxid, function(txid) {
|
2014-04-22 19:07:20 -07:00
|
|
|
console.log('[transactions.js.68:txid:] SENTTX CALLBACK',txid); //TODO
|
2014-05-20 08:30:20 -07:00
|
|
|
$rootScope.$flashMessage = txid
|
2014-05-09 08:28:35 -07:00
|
|
|
? {type:'success', message: 'Transaction broadcasted. txid: ' + txid}
|
2014-04-20 17:53:54 -07:00
|
|
|
: {type:'error', message: 'There was an error sending the Transaction'}
|
|
|
|
;
|
2014-05-16 14:33:06 -07:00
|
|
|
if (cb) return cb();
|
|
|
|
else $scope.update();
|
2014-04-20 17:53:54 -07:00
|
|
|
});
|
2014-04-17 14:06:09 -07:00
|
|
|
};
|
|
|
|
|
2014-04-16 13:50:10 -07:00
|
|
|
$scope.sign = function (ntxid) {
|
2014-04-24 18:43:19 -07:00
|
|
|
$scope.loading = true;
|
2014-04-16 13:50:10 -07:00
|
|
|
var w = $rootScope.wallet;
|
2014-05-16 14:33:06 -07:00
|
|
|
w.sign(ntxid, function(ret){
|
|
|
|
if (!ret) {
|
2014-05-20 08:30:20 -07:00
|
|
|
$rootScope.$flashMessage = {
|
2014-05-16 14:33:06 -07:00
|
|
|
type:'error',
|
|
|
|
message: 'There was an error signing the Transaction',
|
|
|
|
};
|
2014-05-16 21:19:52 -07:00
|
|
|
$scope.update();
|
|
|
|
} else {
|
2014-05-16 14:33:06 -07:00
|
|
|
var p = w.txProposals.getTxProposal(ntxid);
|
|
|
|
if (p.builder.isFullySigned()) {
|
|
|
|
$scope.send(ntxid, function() {
|
|
|
|
$scope.update();
|
|
|
|
});
|
|
|
|
}
|
2014-05-16 21:19:52 -07:00
|
|
|
else
|
|
|
|
$scope.update();
|
2014-05-16 14:33:06 -07:00
|
|
|
}
|
|
|
|
});
|
2014-04-16 13:50:10 -07:00
|
|
|
};
|
2014-04-20 17:53:54 -07:00
|
|
|
|
2014-05-16 21:19:52 -07:00
|
|
|
$scope.getTransactions = function(cb) {
|
2014-04-22 21:55:00 -07:00
|
|
|
var w =$rootScope.wallet;
|
2014-04-24 19:13:55 -07:00
|
|
|
if (w) {
|
2014-05-16 21:19:52 -07:00
|
|
|
console.log('### Querying last transactions...'); //TODO
|
|
|
|
var addresses = w.getAddressesStr();
|
2014-04-24 19:13:55 -07:00
|
|
|
if (addresses.length > 0) {
|
2014-05-16 21:19:52 -07:00
|
|
|
return w.blockchain.getTransactions(addresses, cb);
|
2014-04-24 19:13:55 -07:00
|
|
|
}
|
2014-04-22 23:37:17 -07:00
|
|
|
}
|
2014-05-16 21:19:52 -07:00
|
|
|
return cb();
|
2014-04-22 21:55:00 -07:00
|
|
|
};
|
|
|
|
|
2014-05-08 14:14:49 -07:00
|
|
|
$scope.getShortNetworkName = function() {
|
|
|
|
return config.networkName.substring(0,4);
|
|
|
|
};
|
|
|
|
|
2014-04-22 22:01:54 -07:00
|
|
|
$scope.reject = function (ntxid) {
|
2014-04-24 18:43:19 -07:00
|
|
|
$scope.loading = true;
|
2014-05-15 08:51:52 -07:00
|
|
|
$rootScope.txAlertCount = 0;
|
2014-04-22 22:01:54 -07:00
|
|
|
var w = $rootScope.wallet;
|
|
|
|
w.reject(ntxid);
|
2014-05-20 08:30:20 -07:00
|
|
|
$rootScope.$flashMessage = {type:'warning', message: 'Transaction rejected by you'};
|
2014-05-13 01:02:21 -07:00
|
|
|
$scope.loading = false;
|
2014-04-22 22:01:54 -07:00
|
|
|
};
|
|
|
|
|
2014-03-26 05:18:42 -07:00
|
|
|
});
|