From c0fe72ca45c2be3e5859055c04f4643be6659053 Mon Sep 17 00:00:00 2001 From: "zapaz.eth" Date: Thu, 2 May 2024 12:10:21 +0200 Subject: [PATCH] add network stat page --- common/src/common/networks.ts | 28 +++-- .../src/resolver/resolver-get-collection.ts | 13 +++ config/src/config.handlebars.json | 2 +- config/src/testnets.handlebars.json | 5 +- pnpm-lock.yaml | 6 - .../src/components/Global/Navigation.svelte | 23 ++-- sveltekit/package.json | 2 - sveltekit/src/lib/components/Stats.svelte | 16 ++- .../src/lib/components/StatsNetwork.svelte | 42 +++++++ .../lib/components/StatsNetworkLine.svelte | 105 +++++++++++++++++ .../src/lib/components/StatsNetworks.svelte | 108 +++--------------- sveltekit/src/lib/stores/statsCounts.ts | 48 ++++++++ sveltekit/src/routes/stats/+layout.ts | 10 ++ .../src/routes/stats/[chainId]/+page.svelte | 6 + sveltekit/svelte.config.js | 1 + 15 files changed, 281 insertions(+), 134 deletions(-) create mode 100644 sveltekit/src/lib/components/StatsNetwork.svelte create mode 100644 sveltekit/src/lib/components/StatsNetworkLine.svelte create mode 100644 sveltekit/src/lib/stores/statsCounts.ts create mode 100644 sveltekit/src/routes/stats/+layout.ts create mode 100644 sveltekit/src/routes/stats/[chainId]/+page.svelte diff --git a/common/src/common/networks.ts b/common/src/common/networks.ts index 989b23877..1ff5003c3 100644 --- a/common/src/common/networks.ts +++ b/common/src/common/networks.ts @@ -20,12 +20,20 @@ const networks = (() => { const getAllSameType = (chainId: chainIdish): NetworkType[] => getAllActive().filter((nw: NetworkType) => isMainnet(nw.chainId) === isMainnet(chainId)); - const getAllMainnets = (): NetworkType[] => getAllActive().filter((nw: NetworkType) => isMainnet(nw.chainId)); + const getAllMainnetIds = (): number[] => + getAllActive() + .filter((nw: NetworkType) => isMainnet(nw.chainId)) + .map((nw) => nw.chainId); - const getAllTestnets = (): NetworkType[] => getAllActive().filter((nw: NetworkType) => isTestnet(nw.chainId)); + const getAllTestnetIds = (): number[] => + getAllActive() + .filter((nw: NetworkType) => isTestnet(nw.chainId)) + .map((nw) => nw.chainId); - const getAllOpMainnets = (): NetworkType[] => - getAllActive().filter((nw: NetworkType) => isOpStack(nw.chainId) && isMainnet(nw.chainId)); + const getAllOpMainnetIds = (): number[] => + getAllActive() + .filter((nw: NetworkType) => isOpStack(nw.chainId) && isMainnet(nw.chainId)) + .map((nw) => nw.chainId); const get = (chainId: chainIdish): NetworkType | undefined => _networksMap?.get(Number(chainId)); @@ -56,9 +64,9 @@ const networks = (() => { const isLayer2 = (chainId: chainIdish): boolean => !isLayer1(chainId); const isOpStack = (chainId: chainIdish): boolean => get(chainId)?.opstack || false; - const getChainName = (chainId: chainIdish): string | undefined => get(chainId)?.chainName; - const getChainLabel = (chainId: chainIdish): string | undefined => - get(chainId)?.chainLabel || strUpFirst(strSanitize(getChainName(chainId))); + const getChainName = (chainId: chainIdish): string => get(chainId)?.chainName || ""; + const getChainLabel = (chainId: chainIdish): string => + get(chainId)?.chainLabel || strUpFirst(strSanitize(getChainName(chainId))) || ""; const getMainnetName = (chainId: chainIdish) => isTestnet(chainId) ? getChainName(getLinkedMainnet(chainId)) : getChainName(chainId); @@ -74,9 +82,9 @@ const networks = (() => { getAllActive, getAllInactive, getAllSameType, - getAllMainnets, - getAllTestnets, - getAllOpMainnets, + getAllMainnetIds, + getAllTestnetIds, + getAllOpMainnetIds, getBlur, getBlurUrl, diff --git a/common/src/resolver/resolver-get-collection.ts b/common/src/resolver/resolver-get-collection.ts index 0eeef7412..22a8cb47a 100644 --- a/common/src/resolver/resolver-get-collection.ts +++ b/common/src/resolver/resolver-get-collection.ts @@ -58,6 +58,18 @@ const resolverAreCollections = async (chainId: number, collections: Array => { + console.log(resolverGetCollectionsAddresses, chainId); + + const nftsResolver = await resolverGetContract(chainId); + + const addresses = await nftsResolver.getAddresses(); + // console.log("resolverGetCollections openNFTsStructOutput", collectionInfos); + + console.log(resolverGetCollectionsAddresses, chainId, addresses); + return addresses; +}; + const resolverGetCollections = async ( chainId: number, account = ADDRESS_ZERO @@ -103,6 +115,7 @@ const resolverCountCollections = async (chainId: number): Promise + /////////////////////////////////// + export let chainId: number | undefined = undefined; + export let back: string | undefined = undefined; + /////////////////////////////////// const onProd = versionGet().branch === "main"; $: onMainNet = networks.isMainnet(chainId); @@ -33,7 +38,14 @@ diff --git a/sveltekit/package.json b/sveltekit/package.json index 4aaccd674..df12f10fb 100644 --- a/sveltekit/package.json +++ b/sveltekit/package.json @@ -32,8 +32,6 @@ "type": "module", "dependencies": { "@kredeum/common": "workspace:^", - "@kredeum/contracts": "workspace:^", - "@kredeum/providers": "workspace:^", "@kredeum/svelte": "workspace:^" } } \ No newline at end of file diff --git a/sveltekit/src/lib/components/Stats.svelte b/sveltekit/src/lib/components/Stats.svelte index c98f7b4a1..45565b7fb 100644 --- a/sveltekit/src/lib/components/Stats.svelte +++ b/sveltekit/src/lib/components/Stats.svelte @@ -16,16 +16,14 @@ let tabsMounted: TabsMounted = { Mainnets: true, OPnets: false, - Testnets: false, - Inactives: false + Testnets: false }; let tabActive = "Mainnets"; - const getNetworks = (tab: string): NetworkType[] => { - if (tab === "OPnets") return networks.getAllOpMainnets(); - if (tab === "Testnets") return networks.getAllTestnets(); - if (tab === "Inactives") return networks.getAllInactive(); - return networks.getAllMainnets(); + const getChainIds = (tab: string): number[] => { + if (tab === "OPnets") return networks.getAllOpMainnetIds(); + if (tab === "Testnets") return networks.getAllTestnetIds(); + return networks.getAllMainnetIds(); }; $: console.log(tabsMounted); @@ -33,7 +31,7 @@ - + @@ -58,7 +56,7 @@ {#each Object.entries(tabsMounted) as [tabKey, tabMounted]} {#if tabMounted} - + {/if} {/each} diff --git a/sveltekit/src/lib/components/StatsNetwork.svelte b/sveltekit/src/lib/components/StatsNetwork.svelte new file mode 100644 index 000000000..9ecb89468 --- /dev/null +++ b/sveltekit/src/lib/components/StatsNetwork.svelte @@ -0,0 +1,42 @@ + + + + + + + + +

Kredeum NFTs Factory - Statistics {networks.getChainLabel(chainId).toUpperCase()}

+
+ + +

+ {chainId} +

+ + {#await resolverGetCollectionsAddresses(chainId)} + ... + {:then collections} + {#each collections as collection} + + {/each} + {:catch} + --- + {/await} +
+
diff --git a/sveltekit/src/lib/components/StatsNetworkLine.svelte b/sveltekit/src/lib/components/StatsNetworkLine.svelte new file mode 100644 index 000000000..3050895b4 --- /dev/null +++ b/sveltekit/src/lib/components/StatsNetworkLine.svelte @@ -0,0 +1,105 @@ + + +{#if chainId} + + {chainId} + {networks.getChainName(chainId)} + + {#await countCollections(chainId)} + ... + {:then value} + {value} + {:catch} + --- + {/await} + + + + + {getShortAddress(factoryGetAddress(chainId))} + + + + + {getShortAddress(resolverGetAddress(chainId))} + + + + + {getShortAddress(getAddressOpenNFTsTemplate(chainId))} + + + + + {getShortAddress(getAddressOpenAutoMarket(chainId))} + + + +{/if} + + diff --git a/sveltekit/src/lib/components/StatsNetworks.svelte b/sveltekit/src/lib/components/StatsNetworks.svelte index 0d63b5f22..efa29dc54 100644 --- a/sveltekit/src/lib/components/StatsNetworks.svelte +++ b/sveltekit/src/lib/components/StatsNetworks.svelte @@ -1,63 +1,29 @@ - + @@ -66,41 +32,8 @@ - {#each networksSorted || networks as network} - - - - - - - - - - + {#each chainIds as chainId, index} + {/each}
Chain IDChain
Name
{done}/{networks.length}
Chain
Name
{updated}/{chainIds.length}
Collections
Count
{total}
OpenNFTs
Factory
OpenNFTs
Resolver
{network.chainId}{network.chainName} - {#await countCollections(network.chainId)} - ... - {:then count} - {count} - {:catch} - --- - {/await} - - - {getShortAddress(factoryGetAddress(network.chainId))} - - - - {getShortAddress(resolverGetAddress(network.chainId))} - - - - {getShortAddress(getAddressOpenNFTsTemplate(network.chainId))} - - - - {getShortAddress(getAddressOpenAutoMarket(network.chainId))} - -
@@ -110,8 +43,7 @@ border-collapse: collapse; } - th, - td { + th { padding: 8px; text-align: right; border-bottom: 1px solid #ddd; @@ -125,18 +57,4 @@ tr:hover { background-color: #f5f5f5; } - - .addr { - font-family: "Courier New", monospace; - } - .addr a { - color: #007bff; - text-decoration: none; - transition: color 0.2s; - } - - .addr a:hover { - color: #0056b3; - text-decoration: underline; - } diff --git a/sveltekit/src/lib/stores/statsCounts.ts b/sveltekit/src/lib/stores/statsCounts.ts new file mode 100644 index 000000000..3066efeea --- /dev/null +++ b/sveltekit/src/lib/stores/statsCounts.ts @@ -0,0 +1,48 @@ +import type { Writable } from "svelte/store"; +import { get, writable } from "svelte/store"; + +// STORES // + +// number of collection counts updates +const stats: Writable = writable(0); + +// collection count per chainId +const statsCounts: Writable> = writable(new Map()); + +// total collection count of all chainIds +const statsTotal: Writable = writable(0); + +// FUNCTIONS // + +// chainIds with collection counts +const statsChainIds = (): number[] => [...get(statsCounts).keys()]; + +// get collection count of chainId +const statsChain = (chainId: number): number => get(statsCounts).get(chainId) || 0; + +// subtotal collection count of specific set of chainIds +const statsSubTotal = (chainIds: number[]): number => chainIds.reduce((sum, chainId) => sum + statsChain(chainId), 0); + +const statsSubTotalUpdated = (chainIds: number[]): number => + chainIds.reduce((sum, chainId) => sum + (get(statsCounts).get(chainId) ? 1 : 0), 0); + +// update stats +const statsUpdate = (chainId: number, value: number) => { + statsCounts.update((map) => { + // update total collection count + statsTotal.update((sum) => sum + value - (map.get(chainId) || 0)); + + // set collection count for chainId + map.set(chainId, value); + + // increment number of collection updates + stats.update((n) => n + 1); + + console.log("statsCounts.update ~ map:", map); + return map; + }); +}; + +const statsSort = (chainIds: number[]): number[] => chainIds.sort((a, b) => statsChain(b) - statsChain(a)); + +export { stats, statsCounts, statsTotal, statsChainIds, statsSort, statsChain, statsSubTotal, statsSubTotalUpdated, statsUpdate }; diff --git a/sveltekit/src/routes/stats/+layout.ts b/sveltekit/src/routes/stats/+layout.ts new file mode 100644 index 000000000..94a25ecf8 --- /dev/null +++ b/sveltekit/src/routes/stats/+layout.ts @@ -0,0 +1,10 @@ +import type { Load } from "@sveltejs/kit"; + +const prerender = false; +const ssr = false; + +const load: Load = async () => { + return {}; +}; + +export { prerender, ssr, load }; diff --git a/sveltekit/src/routes/stats/[chainId]/+page.svelte b/sveltekit/src/routes/stats/[chainId]/+page.svelte new file mode 100644 index 000000000..054a216d8 --- /dev/null +++ b/sveltekit/src/routes/stats/[chainId]/+page.svelte @@ -0,0 +1,6 @@ + + + diff --git a/sveltekit/svelte.config.js b/sveltekit/svelte.config.js index 208167b5d..a9571a5b1 100644 --- a/sveltekit/svelte.config.js +++ b/sveltekit/svelte.config.js @@ -14,6 +14,7 @@ const config = { adapter: adapter({ pages: "web/dapp", assets: "web/dapp", + fallback: "200.html", precompress: false, strict: true })