Wallet/js/controllers/transactions.js

113 lines
3.1 KiB
JavaScript
Raw Normal View History

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