Skip to content

Commit

Permalink
special pages for brokend junks
Browse files Browse the repository at this point in the history
  • Loading branch information
hmisty committed Jan 10, 2024
1 parent 388db7a commit 1f52e90
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
15 changes: 12 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,22 @@ angular.module('ethExplorer', ['ngRoute','ui.bootstrap'])
.run(function($rootScope) {
var web3 = new Web3();

var protocol = location.protocol;
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.jnsdao.com'; //'j.blockcoach.com'; //location.hostname; // FIXME manual fix
//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 = '//' + hostname + ':' + port; // 使用相对协议,在https页面混合http请求?
var eth_node_url = '//' + rpc_service; // 使用相对协议,在https页面混合http请求?

web3.setProvider(new web3.providers.HttpProvider(eth_node_url));
$rootScope.web3 = web3;
Expand Down
33 changes: 29 additions & 4 deletions scripts/controllers/junksInfoController.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ angular.module('ethExplorer')
$scope.allPages.push(i);
}

// ONLY AFTER SEALED: special pages 1000 - 1002 for broken ones (total: 299)
$scope.allPages.push(1000, 1001, 1002)

// punk list
$scope.allCryptoJunks = [];
// get total supply & rendering
Expand Down Expand Up @@ -91,9 +94,31 @@ angular.module('ethExplorer')

const contract = new web3.eth.Contract(cryptojunks_ABI, cryptojunks_contract_address);

// calculate which junks to show
const length = 100; //100 junks per page
const begin = pageId * length;
var junkIds = [];

if (pageId < 100) { // normal #0 - #9999
const begin = pageId * length;

for (var i = 0; i < length; i++) {
const tokenId = begin + i;
junkIds.push(tokenId);
}
} else if (pageId >= 1000 && pageId < 1003) { // special pages for broken
const golden_idx = references;
const broken_idx = golden_idx['broken'];

const begin = (pageId - 1000) * length;

for (var i = 0; i < length; i++) {
const tokenId = broken_idx[begin + i];
junkIds.push(tokenId);
}
}
console.log(junkIds);

// helper func
function getCryptoJunkById(tokenId) {
contract.methods.tokenURI(tokenId).call(function (e2, tokenURI) {
if (e2) {
Expand Down Expand Up @@ -150,11 +175,11 @@ angular.module('ethExplorer')
}

if (junkId == undefined) { // not specified, show all
for (var i = 0; i < length; i++) {
const tokenId = begin + i;
for (const i in junkIds) {
const tokenId = junkIds[i];
getCryptoJunkById(tokenId);
}
} else {
} else { // specified junkId, show only one
const tokenId = junkId;
getCryptoJunkById(tokenId);
}
Expand Down
Loading

0 comments on commit 1f52e90

Please sign in to comment.