Wallet/js/controllers/transactions.js

71 lines
2.2 KiB
JavaScript
Raw Normal View History

2014-03-26 09:18:42 -03:00
'use strict';
2014-04-18 19:28:28 -03:00
var bitcore = require('bitcore');
2014-03-26 09:18:42 -03:00
angular.module('copay.transactions').controller('TransactionsController',
2014-04-18 19:08:01 -03:00
function($scope, $rootScope, $location) {
2014-03-26 09:18:42 -03:00
$scope.title = 'Transactions';
var _updateTxs = function() {
2014-04-20 20:24:24 -03:00
console.log('[transactions.js.10:_updateTxs:]'); //TODO
2014-04-18 11:19:39 -03:00
var w =$rootScope.wallet;
var inT = w.getTxProposals();
2014-04-18 19:28:28 -03:00
var txs = [];
2014-04-18 11:19:39 -03:00
inT.forEach(function(i){
2014-04-21 07:27:45 -03:00
var tx = i.builder.build();
var outs = [];
2014-04-18 19:28:28 -03:00
tx.outs.forEach(function(o) {
2014-04-18 19:28:28 -03:00
var addr = bitcore.Address.fromScriptPubKey(o.getScript(), config.networkName)[0].toString();
if (!w.addressIsOwn(addr)) {
2014-04-18 11:33:49 -03:00
outs.push({
2014-04-18 19:28:28 -03:00
address: addr,
2014-04-18 11:33:49 -03:00
value: bitcore.util.valueToBigInt(o.getValue())/bitcore.util.COIN,
});
2014-04-18 19:28:28 -03:00
}
});
2014-04-21 07:27:45 -03:00
// extra fields
i.outs = outs;
i.fee = i.feeSat/bitcore.util.COIN;
i.missingSignatures = tx.countInputMissingSignatures(0);
txs.push(i);
});
2014-04-21 13:16:15 -03:00
console.log('[transactions.js.35:txs:]',txs); //TODO
2014-04-18 19:28:28 -03:00
$scope.txs = txs;
2014-04-20 21:53:54 -03:00
w.removeListener('txProposalsUpdated',_updateTxs)
2014-04-20 20:24:24 -03:00
w.once('txProposalsUpdated',_updateTxs);
};
2014-04-20 21:53:54 -03:00
$scope.send = function (ntxid) {
var w = $rootScope.wallet;
w.sendTx(ntxid, function(txid) {
console.log('[transactions.js.68:txid:] SENTTX CALLBACK',txid); //TODO
$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-16 17:50:10 -03:00
$scope.sign = function (ntxid) {
var w = $rootScope.wallet;
var ret = w.sign(ntxid);
2014-04-18 19:28:28 -03:00
_updateTxs();
var p = w.getTxProposal(ntxid);
if (p.txp.builder.isFullySigned()) {
2014-04-20 21:53:54 -03:00
$scope.send(ntxid);
2014-04-18 19:28:28 -03:00
}
else {
$rootScope.flashMessage = ret
? {type:'success', message: 'Transactions signed'}
: {type:'error', message: 'There was an error signing the Transaction'}
;
2014-04-20 21:53:54 -03:00
_updateTxs();
$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-21 13:16:15 -03:00
_updateTxs();
2014-03-26 09:18:42 -03:00
});