-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
94 lines (89 loc) · 3.82 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
'use strict';
angular.module('ethExplorer', ['ngRoute','ui.bootstrap'])
.config(function($routeProvider, $locationProvider) {
$routeProvider.
when('/', {
templateUrl: 'views/main.html',
controller: 'mainCtrl'
}).
when('/block/:blockId', {
templateUrl: 'views/blockInfos.html',
controller: 'blockInfosCtrl'
}).
when('/tx/:transactionId', { // make it compatible with metamask
templateUrl: 'views/transactionInfos.html',
controller: 'transactionInfosCtrl'
}).
when('/address/:addressId', {
templateUrl: 'views/addressInfo.html',
controller: 'addressInfoCtrl'
}).
when('/did/:jnsId', {
templateUrl: 'views/addressInfo.html',
controller: 'addressInfoCtrl'
}).
when('/cryptojunks', {
templateUrl: 'views/junksInfo.html',
controller: 'junksInfoCtrl'
}).
when('/cryptojunks/page/:pageId', {
templateUrl: 'views/junksInfo.html',
controller: 'junksInfoCtrl'
}).
when('/cryptojunks/page/:pageId/id/:junkId', {
templateUrl: 'views/junksInfo.html',
controller: 'junksInfoCtrl'
}).
when('/redpacket/:redpacketId', {
templateUrl: 'views/redpacketInfo.html',
controller: 'redpacketInfoCtrl'
}).
when('/redpacket', {
templateUrl: 'views/redpacketInfo.html',
controller: 'redpacketInfoCtrl'
}).
when('/jns/:jnsId', {
templateUrl: 'views/jnsInfo.html',
controller: 'jnsInfoCtrl'
}).
when('/jnsvote/', {
templateUrl: 'views/jnsVoteInfo.html',
controller: 'jnsVoteInfoCtrl'
}).
otherwise({
redirectTo: '/'
});
// use the HTML5 History API. needs base href and server-side rewrite.
$locationProvider.html5Mode(false); // FIXME use # for pure static deployment
})
.run(function($rootScope) {
var web3 = new Web3();
const protocol = location.protocol;
const hostname = location.hostname;
var rpc_service;
if (hostname == 'localhost') {
rpc_service = 'rpc.jnsdao.com'; // for dev
} else {
rpc_service = hostname.replace('jscan', 'rpc'); // jscan to use corresponding rpc, e.g. jscan.jnsdao.com -> rpc.jnsdao.com
}
//var hostname = 'localhost';
//var hostname = 'rpc.liujiaolian.com';
//var hostname = 'rpc.jnsdao.com'; //location.hostname; // FIXME manual fix
var port = protocol == 'http:' ? 8502 : 8503;
rpc_service += ':' + port;
//var port = (hostname == 'localhost' || hostname == '127.0.0.1')? 8501 : (protocol == 'http:' ? 8502 : 8503); //XXX yuanma rpc, geth:8501, nginx:8502, nginx-https:8503
//var eth_node_url = protocol + '//' + hostname + ':' + port; // adaptive to http & https
var eth_node_url = '//' + rpc_service; // 使用相对协议,在https页面混合http请求?
web3.setProvider(new web3.providers.HttpProvider(eth_node_url));
$rootScope.web3 = web3;
window.web3 = web3; //XXX inject it to console for debugging
function sleepFor( sleepDuration ){
var now = new Date().getTime();
while(new Date().getTime() < now + sleepDuration){ /* do nothing */ }
}
var connected = false;
//if(!web3.isConnected()) {
if (!web3.eth.net.isListening()) { // fix: make it compatible with web3 1.8.2
dialogModalShowTxt('无法连接到区块链网络', '无法连接到RPC服务,请检查你的网络连接是否畅通');
}
});