2014-01-09 10:13:26 -08:00
|
|
|
'use strict';
|
|
|
|
|
2014-01-17 11:49:08 -08:00
|
|
|
angular.module('insight.transactions').controller('transactionsController',
|
2014-01-20 13:09:18 -08:00
|
|
|
function ($scope, $rootScope, $routeParams, $location, Global, Transaction, TransactionsByBlock, TransactionsByAddress, get_socket) {
|
2014-01-09 10:13:26 -08:00
|
|
|
$scope.global = Global;
|
|
|
|
|
2014-01-17 11:49:08 -08:00
|
|
|
$scope.findThis = function() {
|
|
|
|
$scope.findTx($routeParams.txId);
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.findTx = function(txid) {
|
2014-01-09 10:13:26 -08:00
|
|
|
Transaction.get({
|
2014-01-17 11:49:08 -08:00
|
|
|
txId: txid
|
2014-01-09 10:13:26 -08:00
|
|
|
}, function(tx) {
|
|
|
|
$scope.tx = tx;
|
2014-01-20 12:30:49 -08:00
|
|
|
$scope.txs.unshift(tx);
|
2014-01-20 11:11:35 -08:00
|
|
|
}, function(e) {
|
|
|
|
if (e.status === 400) {
|
|
|
|
$rootScope.flashMessage = 'Invalid Transaction ID: ' + $routeParams.txId;
|
|
|
|
}
|
|
|
|
else if (e.status === 503) {
|
|
|
|
$rootScope.flashMessage = 'Backend Error. ' + e.data;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$rootScope.flashMessage = 'Transaction Not Found';
|
|
|
|
}
|
2014-01-17 13:25:48 -08:00
|
|
|
$location.path('/');
|
2014-01-09 10:13:26 -08:00
|
|
|
});
|
|
|
|
};
|
2014-01-14 15:34:01 -08:00
|
|
|
|
|
|
|
$scope.byBlock = function(bId) {
|
|
|
|
TransactionsByBlock.query({
|
2014-01-15 05:22:07 -08:00
|
|
|
block: bId
|
2014-01-14 15:34:01 -08:00
|
|
|
}, function(txs) {
|
|
|
|
$scope.txs = txs;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.byAddress = function(aId) {
|
|
|
|
TransactionsByAddress.query({
|
2014-01-15 05:22:07 -08:00
|
|
|
address: aId
|
2014-01-14 15:34:01 -08:00
|
|
|
}, function(txs) {
|
|
|
|
$scope.txs = txs;
|
|
|
|
});
|
|
|
|
};
|
2014-01-20 09:30:25 -08:00
|
|
|
var socket = get_socket($scope);
|
|
|
|
socket.on('atx', function(tx) {
|
2014-01-20 12:30:49 -08:00
|
|
|
console.log('atx '+tx.txid);
|
|
|
|
var beep = new Audio('/sound/transaction.mp3');
|
|
|
|
beep.play();
|
2014-01-17 11:49:08 -08:00
|
|
|
$scope.findTx(tx.txid);
|
2014-01-20 09:30:25 -08:00
|
|
|
});
|
2014-01-17 11:49:08 -08:00
|
|
|
|
|
|
|
$scope.txs = [];
|
2014-01-14 15:34:01 -08:00
|
|
|
|
2014-01-20 13:09:18 -08:00
|
|
|
});
|