copay/js/controllers/transactions.js

72 lines
2.0 KiB
JavaScript
Raw Normal View History

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