Wallet/js/controllers/transactions.js
Matias Alejo Garcia fbede5a903 better tx layout
2014-04-18 11:33:58 -03:00

53 lines
1.4 KiB
JavaScript

'use strict';
angular.module('copay.transactions').controller('TransactionsController',
function($scope, $rootScope, $location, Socket, controllerUtils) {
$scope.title = 'Transactions';
$scope.oneAtATime = true;
var _updateTxs = function() {
var w =$rootScope.wallet;
var inT = w.getTxProposals();
var ts = [];
inT.forEach(function(i){
var b = i.txp.builder;
var tx = b.build();
var one = {
feeSat: b.feeSat,
};
var outs = [];
var bitcore = require('bitcore');
tx.outs.forEach(function(o) {
var s = o.getScript();
var aStr = bitcore.Address.fromScript(s, config.networkName).toString();
if (!w.addressIsOwn(aStr))
outs.push({
address: aStr,
value: bitcore.util.valueToBigInt(o.getValue())/bitcore.util.COIN,
});
});
one.outs = outs;
ts.push(one);
});
$scope.txs = ts;
};
if (!$rootScope.wallet || !$rootScope.wallet.id) {
$location.path('signin');
}
else {
_updateTxs();
var socket = Socket($scope);
socket.on('connect', controllerUtils.handleTransactionByAddress($scope));
}
$scope.sign = function (ntxid) {
var w = $rootScope.wallet;
var ret = w.sign(ntxid);
$rootScope.flashMessage = {type:'success', message: 'Transactions SEND! : ' + ret};
_updateTxs();
};
});