Skip to content

Commit

Permalink
refacto
Browse files Browse the repository at this point in the history
  • Loading branch information
zapaz committed May 2, 2024
1 parent 1dc39b4 commit fd8efe9
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 45 deletions.
4 changes: 2 additions & 2 deletions common/src/collection/collection-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { collectionMerge } from "../collection/collection-get";
import { alchemyActive, alchemyCollections } from "../apis/api-alchemy";
import { covalentActive, covalentCollections } from "../apis/api-covalent";
import { thegraphActive, thegraphCollections } from "../apis/api-thegraph";
import { resolverFilterCollections, resolverGetCollections } from "../resolver/resolver-get-collection";
import { resolverFilterCollections, resolverGetCollectionsInfos } from "../resolver/resolver-get-collection";
import { networks } from "../common/networks";
// import { infuraActive, infuraCollections } from "../apis/api-infura";

Expand Down Expand Up @@ -67,7 +67,7 @@ const collectionList = async (
const removed = lengthBefore - collectionsApi.size;
if (removed > 0) console.info("collectionList collectionsApi removed", removed);

collectionsResolver = await resolverGetCollections(chainId, account);
collectionsResolver = await resolverGetCollectionsInfos(chainId, account);
// console.log("collectionList collectionsResolver", collectionsResolver);

// MERGE collectionsApi and collectionsResolver
Expand Down
49 changes: 27 additions & 22 deletions common/src/resolver/resolver-get-collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,63 +58,68 @@ const resolverAreCollections = async (chainId: number, collections: Array<string
return checks;
};

// const resolverGetCollections = async (chainId: number): Promise<CollectionType[]> => {
// console.log("resolverGetCollections >", chainId);
// const collections: CollectionType[] = [];

// const nftsResolver = await resolverGetContract(chainId);
// const colls = await nftsResolver.getCo();

// console.log("resolverGetCollections <", collections);
// return collections;
// };

const resolverGetCollectionsAddresses = async (chainId: number): Promise<string[]> => {
console.log(resolverGetCollectionsAddresses, chainId);
// console.log("resolverGetCollectionsAddresses", chainId);

const nftsResolver = await resolverGetContract(chainId);

const addresses = await nftsResolver.getAddresses();
// console.log("resolverGetCollections openNFTsStructOutput", collectionInfos);
// console.log("resolverGetCollectionsInfos openNFTsStructOutput", collectionInfos);

console.log(resolverGetCollectionsAddresses, chainId, addresses);
// console.log("resolverGetCollectionsAddresses", chainId, addresses);
return addresses;
};

const resolverGetCollections = async (
const resolverGetCollectionsInfos = async (
chainId: number,
account = ADDRESS_ZERO
): Promise<Map<string, CollectionType>> => {
// console.log(`resolverGetCollections ${keyCollections(chainId, account)}\n`, chainId, account);
console.log("resolverGetCollectionsInfos >", chainId, account);

const collections: Map<string, CollectionType> = new Map();

const nftsResolver = await resolverGetContract(chainId);

const collectionInfos = await nftsResolver.getOpenNFTsCollectionsInfos(account);
// console.log("resolverGetCollections openNFTsStructOutput", collectionInfos);
const collectionsInfos = await nftsResolver.getOpenNFTsCollectionsInfos(account);
console.log("resolverGetCollectionsInfos openNFTsStructOutput", collectionsInfos);

if (collectionInfos[0].length !== collectionInfos[1].length) {
console.error("ERROR resolverGetCollections", collectionInfos);
if (collectionsInfos[0].length !== collectionsInfos[1].length) {
console.error("ERROR resolverGetCollectionsInfos", collectionsInfos);
}

for (let index = 0; index < collectionInfos[0].length; index++) {
for (let index = 0; index < collectionsInfos[0].length; index++) {
const collection = resolverConvOpenNFTsCollectionInfos(
chainId,
[collectionInfos[0][index], collectionInfos[1][index]],
[collectionsInfos[0][index], collectionsInfos[1][index]],
account
);
// console.log("collection", collection);
console.log("collection", collection);
collections.set(keyCollection(chainId, collection.address), collection);
}

// console.log(`resolverGetCollections ${chainId} ${account}\n`, collections);
console.log("resolverGetCollectionsInfos <", collections);
return collections;
};

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

return countCollectionsCache.get(chainId);
const nftsResolver = await resolverGetContract(chainId);
return Number(await nftsResolver.countAddresses());
};

export {
resolverCountCollections,
resolverGetCollections,
resolverGetCollectionsInfos,
resolverGetCollectionsAddresses,
resolverGetCollection,
resolverAreCollections,
Expand Down
4 changes: 2 additions & 2 deletions svelte/src/components/Global/Navigation.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@
<!-- experimental -->
{#if !onProd}
<!-- only on testnets -->
{#if !onMainNet}
<!-- {#if !onMainNet}
<li class="active">
<ConfigModal />
</li>
{/if}
{/if} -->
<li class="active">
<p>
<a href={config.base}>
Expand Down
81 changes: 65 additions & 16 deletions sveltekit/src/lib/components/StatsNetwork.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@
import { networks } from "@kredeum/common/src/common/networks";
import HomeLayout from "@kredeum/svelte/src/components/Global/HomeLayout.svelte";
import Navigation from "@kredeum/svelte/src/components/Global/Navigation.svelte";
import { resolverGetCollectionsAddresses } from "@kredeum/common/src/resolver/resolver-get-collection";
import {
resolverGetCollectionsInfos,
resolverGetCollectionsAddresses
} from "@kredeum/common/src/resolver/resolver-get-collection";
import { explorerCollectionUrl, getShortAddress } from "@kredeum/common/src/common/config";
///////////////////////////////////////
// <StatsNetwork {chainId} />
///////////////////////////////////////
export let chainId: number;
///////////////////////////////////////
resolverGetCollectionsInfos(chainId).then(console.log);
</script>

<HomeLayout>
Expand All @@ -23,20 +28,64 @@
</span>

<span slot="content">
<h1>
{chainId}
</h1>

{#await resolverGetCollectionsAddresses(chainId)}
...
{:then collections}
{#each collections as collection}
<div>
<a href={explorerCollectionUrl(chainId, collection)} target="_blank">{collection}</a>
</div>
{/each}
{:catch}
---
{/await}
<table>
<caption> <h1>{networks.getChainName(chainId)} #{chainId}</h1></caption>
<thead>
<tr>
<th>Total Supply</th>
<th>View</th>
<th>Collections Addresses</th>
</tr>
</thead>
<tbody>
{#await resolverGetCollectionsAddresses(chainId)}
...
{:then collections}
{#each collections as collection}
<tr>
<td>1</td>
<td><a href={explorerCollectionUrl(chainId, collection)} target="_blank">{collection}</a></td>
<td>
<a href={explorerCollectionUrl(chainId, collection)} target="_blank">{collection}</a>
</td>
</tr>
{/each}
{:catch}
---
{/await}
</tbody>
</table>
</span>
</HomeLayout>

<style>
table {
border-collapse: collapse;
}
th {
padding: 8px;
text-align: center;
border-bottom: 1px solid #ddd;
width: 180px;
}
th {
background-color: #f2f2f2;
}
tr:hover {
background-color: #f5f5f5;
}
tr:hover {
background-color: #f5f5f5;
}
td {
font-family: "Courier New", monospace;
padding: 8px;
text-align: center;
border-bottom: 1px solid #ddd;
width: 180px;
}
</style>
8 changes: 6 additions & 2 deletions sveltekit/src/lib/components/StatsNetworkLine.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
import { resolverCountCollections } from "@kredeum/common/src/resolver/resolver-get-collection";
import { networks } from "@kredeum/common/src/common/networks";
import { statsUpdate } from "../stores/statsCounts";
import { statsCounts, statsUpdate } from "../stores/statsCounts";
import { onMount } from "svelte";
///////////////////////////////////////
// <Addresses networks={networks} />
Expand All @@ -21,10 +22,11 @@
///////////////////////////////////////
const countCollections = async (chainId: number): Promise<number | undefined> => {
if ($statsCounts.has(chainId)) return $statsCounts.get(chainId);
const count = await resolverCountCollections(chainId);
if (count !== undefined) statsUpdate(chainId, count);
console.log("countCollections:", chainId, count);
return count;
};
</script>
Expand Down Expand Up @@ -89,9 +91,11 @@
color: #0056b3;
text-decoration: underline;
}
.addr {
font-family: "Courier New", monospace;
}
.addr a {
color: #007bff;
text-decoration: none;
Expand Down
2 changes: 1 addition & 1 deletion sveltekit/src/lib/components/StatsNetworks.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
</tr>
</thead>
<tbody>
{#each chainIds as chainId, index}
{#each chainIds as chainId}
<StatsNetworkLine {chainId} />
{/each}
</tbody>
Expand Down

0 comments on commit fd8efe9

Please sign in to comment.