Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
zapaz committed Apr 27, 2024
1 parent 691cda7 commit 7f3d9f3
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 24 deletions.
19 changes: 13 additions & 6 deletions common/src/resolver/resolver-get-collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,26 @@ const resolverGetCollections = async (
return collections;
};

const countCollectionsCache = new Map<number, number>();
const resolverCountCollections = async (chainId: number): Promise<number | undefined> => {
if (!countCollectionsCache.has(chainId)) {
const resolverGetCollectionsAddresses = async (chainId: number): Promise<Array<string>> => {
const nftsResolver = await resolverGetContract(chainId);
return await nftsResolver.getAddresses();

};

const collectionsCache = new Map<number, number>();
const resolverGetCollectionsCount = async (chainId: number): Promise<number | undefined> => {
if (!collectionsCache.has(chainId)) {
const nftsResolver = await resolverGetContract(chainId);
const countCollections = Number(await nftsResolver.countAddresses());
countCollectionsCache.set(chainId, countCollections);
collectionsCache.set(chainId, countCollections);
}

return countCollectionsCache.get(chainId);
return collectionsCache.get(chainId);
};

export {
resolverCountCollections,
resolverGetCollectionsCount,
resolverGetCollectionsAddresses,
resolverGetCollections,
resolverGetCollection,
resolverAreCollections,
Expand Down
63 changes: 45 additions & 18 deletions sveltekit/src/routes/stats/Addresses.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,55 @@
getAddressOpenAutoMarket,
explorerContractUrl
} from "@kredeum/common/src/common/config";
import { resolverCountCollections } from "@kredeum/common/src/resolver/resolver-get-collection";
import {
resolverGetCollections,
resolverGetCollectionsAddresses,
resolverGetCollectionsCount
} from "@kredeum/common/src/resolver/resolver-get-collection";
///////////////////////////////////////
// <Addresses networks={networks} />
///////////////////////////////////////
export let networks: NetworkType[];
///////////////////////////////////////
let i = 0;
let total = 0;
let done = 0;
let counts = new Map<number, number>();
const refreshCount = () => {
total = [...counts].reduce((tot, [k, n]) => tot + (n || 0), 0);
done = [...counts].filter((n) => n !== undefined).length;
if (done === networks.length) sortNetworks();
};
let refresh = 0;
let collectionsAllCounts: Map<number, number> = new Map();
let collectionsAllAddresses: Map<number, Array<string>> = new Map();
const countCollections = async (chainId: number): Promise<number | undefined> => {
let count = counts.get(chainId);
const collectionsCount = async (chainId: number): Promise<number | undefined> => {
let count = collectionsAllCounts.get(chainId);
if (count === undefined) {
count = (await resolverCountCollections(chainId)) || 0;
counts.set(chainId, count);
count = (await resolverGetCollectionsCount(chainId)) || 0;
collectionsAllCounts.set(chainId, count);
refreshCount();
}
return count;
};
let refresh = 0;
const collectionsAddresses = async (chainId: number): Promise<Array<string>> => {
let addrs = collectionsAllAddresses.get(chainId);
if (addrs === undefined) {
addrs = await resolverGetCollectionsAddresses(chainId);
collectionsAllAddresses.set(chainId, addrs);
}
return addrs;
};
const refreshCount = () => {
total = [...collectionsAllCounts].reduce((tot, [k, n]) => tot + (n || 0), 0);
done = [...collectionsAllCounts].filter((n) => n !== undefined).length;
if (done === networks.length) sortNetworks();
};
const sortNetworks = () => {
console.log("sortNetworks ~ sortNetworks:", networks);
networks.sort((a: NetworkType, b: NetworkType) => (counts.get(b.chainId) || 0) - (counts.get(a.chainId) || 0));
refresh++;
networks.sort(
(a: NetworkType, b: NetworkType) =>
(collectionsAllCounts.get(b.chainId) || 0) - (collectionsAllCounts.get(a.chainId) || 0)
);
// refresh++;
};
onMount(() => {});
Expand All @@ -54,6 +71,7 @@
<th>Chain ID</th>
<th>Chain<br />Name<br />{done}/{networks.length}</th>
<th>Collections<br />Count<br />{total}</th>
<th>Collections<br />Addresses<br /></th>
<th>OpenNFTs<br />Factory</th>
<th>OpenNFTs<br />Resolver</th>
<th>OpenNFTsV4<br />Template</th>
Expand All @@ -67,15 +85,24 @@
<td>{network.chainId}</td>
<td>{network.chainName}</td>
<td>
{#await countCollections(network.chainId)}
{#await collectionsCount(network.chainId)}
...
{:then count}
{count}
{++i}
{count}
{:catch}
---
{/await}
</td>
<td>
{#await collectionsAddresses(network.chainId)}
...
{:then addrs}
{addrs}
{:catch}
---
{/await}
</td>

<td class="addr">
<a href={factoryGetExplorerUrl(network.chainId)} target="_blank">
{getShortAddress(factoryGetAddress(network.chainId))}
Expand Down

0 comments on commit 7f3d9f3

Please sign in to comment.