2014-03-26 05:18:42 -07:00
|
|
|
'use strict';
|
|
|
|
|
2014-03-28 11:08:14 -07:00
|
|
|
angular.module('copay.transactions').controller('TransactionsController',
|
2014-04-18 15:08:01 -07:00
|
|
|
function($scope, $rootScope, $location) {
|
2014-04-23 08:59:21 -07:00
|
|
|
var bitcore = require('bitcore');
|
|
|
|
|
2014-03-26 05:18:42 -07:00
|
|
|
$scope.title = 'Transactions';
|
2014-04-17 14:06:09 -07:00
|
|
|
var _updateTxs = function() {
|
2014-04-18 07:19:39 -07:00
|
|
|
var w =$rootScope.wallet;
|
2014-04-22 19:07:20 -07:00
|
|
|
if (!w) return;
|
|
|
|
|
2014-04-18 07:19:39 -07:00
|
|
|
var inT = w.getTxProposals();
|
2014-04-18 15:28:28 -07:00
|
|
|
var txs = [];
|
2014-04-18 07:19:39 -07:00
|
|
|
|
2014-04-17 14:06:09 -07:00
|
|
|
inT.forEach(function(i){
|
2014-04-21 03:27:45 -07:00
|
|
|
var tx = i.builder.build();
|
2014-04-17 14:06:09 -07:00
|
|
|
var outs = [];
|
2014-04-18 15:28:28 -07:00
|
|
|
|
2014-04-17 14:06:09 -07:00
|
|
|
tx.outs.forEach(function(o) {
|
2014-04-18 15:28:28 -07:00
|
|
|
var addr = bitcore.Address.fromScriptPubKey(o.getScript(), config.networkName)[0].toString();
|
|
|
|
if (!w.addressIsOwn(addr)) {
|
2014-04-18 07:33:49 -07:00
|
|
|
outs.push({
|
2014-04-18 15:28:28 -07:00
|
|
|
address: addr,
|
2014-04-18 07:33:49 -07:00
|
|
|
value: bitcore.util.valueToBigInt(o.getValue())/bitcore.util.COIN,
|
|
|
|
});
|
2014-04-18 15:28:28 -07:00
|
|
|
}
|
2014-04-17 14:06:09 -07:00
|
|
|
});
|
2014-04-21 03:27:45 -07:00
|
|
|
// extra fields
|
|
|
|
i.outs = outs;
|
2014-04-22 19:07:20 -07:00
|
|
|
i.fee = i.builder.feeSat/bitcore.util.COIN;
|
2014-04-21 03:27:45 -07:00
|
|
|
i.missingSignatures = tx.countInputMissingSignatures(0);
|
|
|
|
txs.push(i);
|
2014-04-17 14:06:09 -07:00
|
|
|
});
|
2014-04-18 15:28:28 -07:00
|
|
|
$scope.txs = txs;
|
2014-04-20 17:53:54 -07:00
|
|
|
w.removeListener('txProposalsUpdated',_updateTxs)
|
2014-04-20 16:24:24 -07:00
|
|
|
w.once('txProposalsUpdated',_updateTxs);
|
2014-04-17 14:06:09 -07:00
|
|
|
};
|
|
|
|
|
2014-04-20 17:53:54 -07:00
|
|
|
$scope.send = function (ntxid) {
|
|
|
|
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: 'Transactions SENT! txid:' + txid}
|
|
|
|
: {type:'error', message: 'There was an error sending the Transaction'}
|
|
|
|
;
|
|
|
|
_updateTxs();
|
|
|
|
$rootScope.$digest();
|
|
|
|
});
|
2014-04-17 14:06:09 -07:00
|
|
|
};
|
|
|
|
|
2014-04-16 13:50:10 -07:00
|
|
|
$scope.sign = function (ntxid) {
|
|
|
|
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'};
|
|
|
|
_updateTxs();
|
|
|
|
$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-21 16:28:57 -07:00
|
|
|
_updateTxs();
|
|
|
|
$rootScope.$digest();
|
2014-04-18 15:28:28 -07:00
|
|
|
}
|
|
|
|
else {
|
2014-04-20 17:53:54 -07:00
|
|
|
_updateTxs();
|
|
|
|
$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
|
|
|
|
2014-04-22 21:55:00 -07:00
|
|
|
$scope.getTransactions = function() {
|
|
|
|
var w =$rootScope.wallet;
|
2014-04-22 23:37:17 -07:00
|
|
|
var addresses = w.getAddressesStr();
|
2014-04-22 21:55:00 -07:00
|
|
|
|
2014-04-22 23:37:17 -07:00
|
|
|
if (addresses.length > 0) {
|
|
|
|
w.blockchain.getTransactions(addresses, function(txs) {
|
|
|
|
$scope.blockchain_txs = txs;
|
|
|
|
$rootScope.$digest();
|
|
|
|
});
|
|
|
|
}
|
2014-04-22 21:55:00 -07:00
|
|
|
};
|
|
|
|
|
2014-04-22 22:01:54 -07:00
|
|
|
$scope.reject = function (ntxid) {
|
|
|
|
var w = $rootScope.wallet;
|
|
|
|
w.reject(ntxid);
|
|
|
|
$rootScope.flashMessage = {type:'warning', message: 'Transaction rejected by you'};
|
|
|
|
_updateTxs();
|
|
|
|
$rootScope.$digest();
|
|
|
|
};
|
|
|
|
|
2014-04-21 09:16:15 -07:00
|
|
|
_updateTxs();
|
2014-03-26 05:18:42 -07:00
|
|
|
});
|