2014-03-26 09:18:42 -03:00
|
|
|
'use strict';
|
|
|
|
|
|
2014-03-28 14:08:14 -04:00
|
|
|
angular.module('copay.transactions').controller('TransactionsController',
|
2014-05-13 04:03:09 -03:00
|
|
|
function($scope, $rootScope, 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;
|
2014-04-25 17:53:19 -03:00
|
|
|
|
2014-04-20 21:53:54 -03:00
|
|
|
$scope.send = function (ntxid) {
|
2014-04-24 22:43:19 -03:00
|
|
|
$scope.loading = true;
|
2014-05-15 12:51:52 -03:00
|
|
|
$rootScope.txAlertCount = 0;
|
2014-04-20 21:53:54 -03:00
|
|
|
var w = $rootScope.wallet;
|
|
|
|
|
w.sendTx(ntxid, function(txid) {
|
2014-04-22 23:07:20 -03:00
|
|
|
console.log('[transactions.js.68:txid:] SENTTX CALLBACK',txid); //TODO
|
2014-04-20 21:53:54 -03:00
|
|
|
$rootScope.flashMessage = txid
|
2014-05-09 11:28:35 -04:00
|
|
|
? {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'}
|
|
|
|
|
;
|
2014-05-13 04:03:09 -03:00
|
|
|
controllerUtils.updateTxs();
|
2014-05-13 05:02:21 -03:00
|
|
|
$scope.loading = false;
|
2014-04-20 21:53:54 -03:00
|
|
|
$rootScope.$digest();
|
|
|
|
|
});
|
2014-04-17 18:06:09 -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;
|
|
|
|
|
var ret = w.sign(ntxid);
|
2014-04-18 19:28:28 -03:00
|
|
|
|
2014-04-21 20:28:57 -03:00
|
|
|
if (!ret) {
|
|
|
|
|
$rootScope.flashMessage = {type:'error', message: 'There was an error signing the Transaction'};
|
2014-05-13 04:03:09 -03:00
|
|
|
controllerUtils.updateTxs();
|
2014-05-13 05:02:21 -03:00
|
|
|
$scope.loading = false;
|
|
|
|
|
$rootScope.$digest();
|
2014-04-21 20:28:57 -03:00
|
|
|
return;
|
|
|
|
|
}
|
2014-04-23 16:02:23 -03:00
|
|
|
var p = w.txProposals.getTxProposal(ntxid);
|
2014-04-23 22:43:17 -03:00
|
|
|
if (p.builder.isFullySigned()) {
|
2014-04-20 21:53:54 -03:00
|
|
|
$scope.send(ntxid);
|
2014-05-13 05:02:21 -03:00
|
|
|
controllerUtils.updateTxs();
|
2014-04-18 19:28:28 -03:00
|
|
|
}
|
|
|
|
|
else {
|
2014-05-13 04:03:09 -03:00
|
|
|
controllerUtils.updateTxs();
|
2014-05-13 05:02:21 -03:00
|
|
|
$scope.loading = false;
|
2014-04-20 21:53:54 -03:00
|
|
|
$rootScope.$digest();
|
2014-04-18 19:28:28 -03:00
|
|
|
}
|
2014-04-16 17:50:10 -03:00
|
|
|
};
|
2014-04-20 21:53:54 -03:00
|
|
|
|
2014-04-23 01:55:00 -03:00
|
|
|
$scope.getTransactions = function() {
|
|
|
|
|
var w =$rootScope.wallet;
|
2014-04-24 23:13:55 -03:00
|
|
|
if (w) {
|
|
|
|
|
var addresses = w.getAddressesStr();
|
2014-04-23 01:55:00 -03:00
|
|
|
|
2014-04-24 23:13:55 -03:00
|
|
|
if (addresses.length > 0) {
|
|
|
|
|
w.blockchain.getTransactions(addresses, function(txs) {
|
|
|
|
|
$scope.blockchain_txs = txs;
|
|
|
|
|
$rootScope.$digest();
|
|
|
|
|
});
|
|
|
|
|
}
|
2014-04-23 03:37:17 -03:00
|
|
|
}
|
2014-04-23 01:55:00 -03:00
|
|
|
};
|
|
|
|
|
|
2014-05-08 18:14:49 -03:00
|
|
|
$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;
|
2014-05-15 12:51:52 -03:00
|
|
|
$rootScope.txAlertCount = 0;
|
2014-04-23 02:01:54 -03:00
|
|
|
var w = $rootScope.wallet;
|
|
|
|
|
w.reject(ntxid);
|
|
|
|
|
$rootScope.flashMessage = {type:'warning', message: 'Transaction rejected by you'};
|
2014-05-13 05:02:21 -03:00
|
|
|
$scope.loading = false;
|
2014-04-23 02:01:54 -03:00
|
|
|
};
|
|
|
|
|
|
2014-03-26 09:18:42 -03:00
|
|
|
});
|