Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenandrews committed Sep 6, 2024
1 parent d8ad397 commit 2cacc26
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 35 deletions.
2 changes: 2 additions & 0 deletions src/ic/stoic-identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ function _postToPopup(data, resolve, reject) {
//Keep it open?
} else {
_stoicTimer = setTimeout(() => {
_stoicOpenConnection = false;
_stoicTimer = false;
_removeFrame(thisIndex);
}, 5000);
}
Expand Down
82 changes: 47 additions & 35 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,53 +52,65 @@ var _stats = [],
lastUpdate = false,
earnData = {};
const _getStats = async () => {
var collections = (
await fetch('https://us-central1-entrepot-api.cloudfunctions.net/api/collections').then(r =>
r.json(),
)
const collections = (
await fetch('https://us-central1-entrepot-api.cloudfunctions.net/api/collections')
.then(r => r.json())
)
.map(a => ({...a, canister: a.id}))
.map(a => ({ ...a, canister: a.id }))
.filter(a => _isCanister(a.canister));
var pxs = [];
var _ts = [];
for (var i = 0; i < collections.length; i++) {

let pxs = [];
let _ts = [];

for (let i = 0; i < collections.length; i++) {
if (!collections[i].market) {
_ts.push({
canister: collections[i].canister,
stats: false,
});
} else {
pxs.push(
(c =>
api
.token(c)
.stats()
.then(r => {
return {canister: c, stats: r};
}))(collections[i].canister),
);
pxs.push((c =>
api
.token(c)
.stats()
.then(r => ({ canister: c, stats: r }))
)(collections[i].canister));
}
}
const results = await Promise.all(pxs.map(p => p.catch(e => e)));
const validResults = results.filter(result => !(result instanceof Error));
_stats = validResults.concat(_ts);

// Helper function to fetch stats in batches
const fetchInBatches = async (batchSize = 20, delay = 5000) => {
let _stats = [];
for (let i = 0; i < pxs.length; i += batchSize) {
// Get the current batch of promises
const batch = pxs.slice(i, i + batchSize);

// Wait for the batch to resolve
const results = await Promise.all(batch.map(p => p.catch(() => null)));

// Filter out any null (failed) results
const validResults = results.filter(result => result !== null);

// Add valid results to the stats array
_stats = _stats.concat(validResults);

// Wait 5 seconds before fetching the next batch
if (i + batchSize < pxs.length) {
await new Promise(resolve => setTimeout(resolve, delay));
}
}
return _stats;
};

// Fetch stats in batches
const batchStats = await fetchInBatches(80, 2000);

// Combine the batch stats with the pre-existing stats (_ts)
_stats = batchStats.concat(_ts);

return _stats;
// (c => {
// api.token(c).stats().then(r => {
// res = {
// canister : c,
// stats : r
// };
// _stats.push(res);
// }).catch(e => {
// res = {
// canister : c,
// stats : false
// };
// _stats.push(res);
// });
// })(collections[i].canister);
};

const icpbunnyimg = i => {
const icbstorage = [
'efqhu-yqaaa-aaaaf-qaeda-cai',
Expand Down

0 comments on commit 2cacc26

Please sign in to comment.