Merge pull request #153 from colkito/bug/search-by-height
fixed search when put a txid
This commit is contained in:
commit
b2d0ef6c60
|
@ -4,41 +4,49 @@ angular.module('insight.search').controller('SearchController',
|
||||||
function($scope, $routeParams, $location, $timeout, Global, Block, Transaction, Address, BlockByHeight) {
|
function($scope, $routeParams, $location, $timeout, Global, Block, Transaction, Address, BlockByHeight) {
|
||||||
$scope.global = Global;
|
$scope.global = Global;
|
||||||
|
|
||||||
|
var _badQuery = function() {
|
||||||
|
$scope.badQuery = true;
|
||||||
|
|
||||||
|
$timeout(function() {
|
||||||
|
$scope.badQuery = false;
|
||||||
|
}, 2000);
|
||||||
|
};
|
||||||
|
|
||||||
$scope.search = function() {
|
$scope.search = function() {
|
||||||
var q = $scope.q;
|
var q = $scope.q;
|
||||||
|
|
||||||
$scope.badQuery = false;
|
$scope.badQuery = false;
|
||||||
|
|
||||||
BlockByHeight.get({
|
Block.get({
|
||||||
blockHeight: q
|
blockHash: q
|
||||||
}, function(hash) {
|
}, function() {
|
||||||
$scope.q = '';
|
$scope.q = '';
|
||||||
$location.path('/block/' + hash.blockHash);
|
$location.path('block/' + q);
|
||||||
}, function() { // block by height not found
|
}, function () { //block not found, search on TX
|
||||||
Block.get({
|
Transaction.get({
|
||||||
blockHash: q
|
txId: q
|
||||||
}, function() {
|
}, function() {
|
||||||
$scope.q = '';
|
$scope.q = '';
|
||||||
$location.path('block/' + q);
|
$location.path('tx/' + q);
|
||||||
}, function () { //block not found, search on TX
|
}, function () { //tx not found, search on Address
|
||||||
Transaction.get({
|
Address.get({
|
||||||
txId: q
|
addrStr: q
|
||||||
}, function() {
|
}, function() {
|
||||||
$scope.q = '';
|
$scope.q = '';
|
||||||
$location.path('tx/' + q);
|
$location.path('address/' + q);
|
||||||
}, function () { //tx not found, search on Address
|
}, function () { // block by height not found
|
||||||
Address.get({
|
if (isFinite(q)) { // ensure that q is a finite number. A logical height value.
|
||||||
addrStr: q
|
BlockByHeight.get({
|
||||||
}, function() {
|
blockHeight: q
|
||||||
$scope.q = '';
|
}, function(hash) {
|
||||||
$location.path('address/' + q);
|
$scope.q = '';
|
||||||
}, function () { //address not found, fail :(
|
$location.path('/block/' + hash.blockHash);
|
||||||
$scope.badQuery = true;
|
}, function() { //not found, fail :(
|
||||||
$timeout(function() {
|
_badQuery();
|
||||||
$scope.badQuery = false;
|
});
|
||||||
}, 2000);
|
}
|
||||||
$scope.q = q;
|
else {
|
||||||
});
|
_badQuery();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue