diff --git a/components/Sidebar.tsx b/components/Sidebar.tsx index 4398384..5e44882 100644 --- a/components/Sidebar.tsx +++ b/components/Sidebar.tsx @@ -14,7 +14,6 @@ const routes = [ { text: 'Create a Collection', href: `/collections/create/`, isChild: true }, { text: 'My Collections', href: `/collections/myCollections/`, isChild: true }, { text: 'Collection Actions', href: `/collections/actions/`, isChild: true }, - { text: 'Warm Up', href: `/collections/warmup/`, isChild: true }, { text: 'Contract Dashboards', href: `/contracts/`, isChild: false }, { text: 'Base Minter Contract', href: `/contracts/baseMinter/`, isChild: true }, { text: 'Vending Minter Contract', href: `/contracts/vendingMinter/`, isChild: true }, diff --git a/pages/collections/warmup.tsx b/pages/collections/warmup.tsx index f4d6c79..af8d2cf 100644 --- a/pages/collections/warmup.tsx +++ b/pages/collections/warmup.tsx @@ -6,12 +6,14 @@ import { Button } from 'components/Button' import { ContractPageHeader } from 'components/ContractPageHeader' import { AddressInput } from 'components/forms/FormInput' import { useInputState } from 'components/forms/FormInput.hooks' -import Lister from 'components/Lister' +import type { AppConfig } from 'config' +import { getConfig } from 'config' import type { NextPage } from 'next' import { useRouter } from 'next/router' import { NextSeo } from 'next-seo' import { useEffect, useState } from 'react' import { toast } from 'react-hot-toast' +import { NETWORK } from 'utils/constants' import { withMetadata } from 'utils/layout' import { links } from 'utils/links' @@ -23,11 +25,11 @@ interface ConfigResponse { const CollectionQueriesPage: NextPage = () => { const [client, setClient] = useState() const [baseUri, SetBaseUri] = useState('') - const [doneList, setDoneList] = useState([]) - const [processList, setProcessList] = useState([]) + const [doneCount, setDoneCount] = useState(0) const [errorList, setErrorList] = useState([]) const [numTokens, setNumTokens] = useState(0) const [percentage, setPercentage] = useState('0.00') + const [isLoading, setIsLoading] = useState(false) const minterContractState = useInputState({ id: 'minter-contract-address', name: 'minter-contract-address', @@ -41,7 +43,8 @@ const CollectionQueriesPage: NextPage = () => { useEffect(() => { async function init() { - setClient(await CosmWasmClient.connect('https://rpc.elgafar-1.stargaze-apis.com/')) //'https://rpc.stargaze-apis.com/')) + const config: AppConfig = getConfig(NETWORK) + setClient(await CosmWasmClient.connect(config.rpcUrl)) } void init() }, []) @@ -55,8 +58,7 @@ const CollectionQueriesPage: NextPage = () => { setNumTokens(res.num_tokens) SetBaseUri(res.base_token_uri) setPercentage('0.00') - setDoneList([]) - setProcessList([]) + setDoneCount(0) setErrorList([]) } } @@ -75,9 +77,10 @@ const CollectionQueriesPage: NextPage = () => { }, []) useEffect(() => { - if (numTokens !== 0) setPercentage((((Math.round(100 * doneList.length) / numTokens) * 100) / 100).toFixed(2)) - else setPercentage('0') - }, [doneList.length, numTokens]) + if (doneCount === numTokens) setIsLoading(false) + if (numTokens !== 0) setPercentage(((doneCount / numTokens) * 100).toFixed(2)) + else setPercentage('0.00') + }, [doneCount, numTokens]) function chooseAlternate(url: string, attempt: number) { let alternate @@ -103,29 +106,19 @@ const CollectionQueriesPage: NextPage = () => { } async function warmOne(i: number, image: string, attempt: number, totalAttempt: number) { - setProcessList((existingItems) => { - return [i, ...existingItems] - }) const link = image.replace('1', i.toString()) try { const result = await axios.get(chooseAlternate(link, attempt)) if (result.status === 200) { - setDoneList((existingItems) => { - return [i, ...existingItems] - }) - setProcessList((existingItems) => { - const index = existingItems.indexOf(i, 0) - if (index > -1) { - existingItems.splice(index, 1) - } - return existingItems + setDoneCount((count) => { + return count + 1 }) return } } catch (e) { - console.log('error: ', i, e) + toast.error(e as string) } if (totalAttempt !== 4) { void warmOne(i, image, attempt === 3 ? 0 : attempt + 1, attempt === 3 ? totalAttempt + 1 : totalAttempt) @@ -133,30 +126,35 @@ const CollectionQueriesPage: NextPage = () => { setErrorList((existingItems) => { return [i, ...existingItems] }) - setProcessList((existingItems) => { - const index = existingItems.indexOf(i, 0) - if (index > -1) { - existingItems.splice(index, 1) - } - return existingItems + setDoneCount((count) => { + return count + 1 }) } } - async function warmingProcess(url: string, attempt: number) { + async function warmingProcess(url: string, attempt: number, err: boolean) { const link = `${chooseAlternate(url, attempt)}/1` try { const { data, status } = await axios.get(link) if (status === 200) { - for (let i = 1; i <= numTokens; i++) { - // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access - void warmOne(i, data.image, 0, 0) + if (!err) { + for (let i = 1; i <= numTokens; i++) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access + void warmOne(i, data.image, 0, 0) + } + } else { + const list = errorList + setErrorList([]) + list.forEach((i) => { + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access + void warmOne(i, data.image, 0, 0) + }) } } else if (attempt < 3) { - void warmingProcess(url, attempt + 1) + void warmingProcess(url, attempt + 1, err) } else toast.error('File can not be reachable at the moment! Please try again later...') } catch (e) { - console.log(e) + toast.error(e as string) } } @@ -175,37 +173,41 @@ const CollectionQueriesPage: NextPage = () => {
Total
-
Warmed
+
Done
+
Error
Percentage
{numTokens}
-
{doneList.length}
+
{doneCount}
+
{errorList.length}
{percentage}%
-
+
-
- {errorList.map((value: number, index: number) => { - return - })} -
) }