insight-ui-mangacoin
Version:
An open-source frontend for the Insight API. The Insight API provides you with a convenient, powerful and simple way to query and broadcast data on the monacoin network and build your own services with it.
61 lines (50 loc) • 1.75 kB
JavaScript
'use strict';
angular.module('insight.address').controller('AddressController',
function($scope, $rootScope, $routeParams, $location, Global, Address, getSocket) {
$scope.global = Global;
var socket = getSocket($scope);
var addrStr = $routeParams.addrStr;
var _startSocket = function() {
socket.on('monacoind/addresstxid', function(data) {
if (data.address === addrStr) {
$rootScope.$broadcast('tx', data.txid);
var base = document.querySelector('base');
var beep = new Audio(base.href + '/sound/transaction.mp3');
beep.play();
}
});
socket.emit('subscribe', 'monacoind/addresstxid', [addrStr]);
};
var _stopSocket = function () {
socket.emit('unsubscribe', 'monacoind/addresstxid', [addrStr]);
};
socket.on('connect', function() {
_startSocket();
});
$scope.$on('$destroy', function(){
_stopSocket();
});
$scope.params = $routeParams;
$scope.findOne = function() {
$rootScope.currentAddr = $routeParams.addrStr;
_startSocket();
Address.get({
addrStr: $routeParams.addrStr
},
function(address) {
$rootScope.titleDetail = address.addrStr.substring(0, 7) + '...';
$rootScope.flashMessage = null;
$scope.address = address;
},
function(e) {
if (e.status === 400) {
$rootScope.flashMessage = 'Invalid Address: ' + $routeParams.addrStr;
} else if (e.status === 503) {
$rootScope.flashMessage = 'Backend Error. ' + e.data;
} else {
$rootScope.flashMessage = 'Address Not Found';
}
$location.path('/');
});
};
});