Minor changes

This commit is contained in:
name-user1 2023-01-31 17:14:58 +03:00
parent de263c604e
commit 94d7d1571c
2 changed files with 49 additions and 48 deletions

View File

@ -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 },

View File

@ -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<CosmWasmClient>()
const [baseUri, SetBaseUri] = useState('')
const [doneList, setDoneList] = useState<number[]>([])
const [processList, setProcessList] = useState<number[]>([])
const [doneCount, setDoneCount] = useState(0)
const [errorList, setErrorList] = useState<number[]>([])
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 = () => {
<div className="flex flex-col mr-20 w-4/5 text-xl border border-stargaze">
<div className="flex flex-row mt-2 w-full text-center">
<div className="w-1/3">Total</div>
<div className="w-1/3">Warmed</div>
<div className="w-1/3">Done</div>
<div className="w-1/3">Error</div>
<div className="w-1/3">Percentage</div>
</div>
<div className="flex flex-row w-full text-center">
<div className="w-1/3">{numTokens}</div>
<div className="w-1/3">{doneList.length}</div>
<div className="w-1/3">{doneCount}</div>
<div className="w-1/3">{errorList.length}</div>
<div className="w-1/3">{percentage}%</div>
</div>
<div className="flex justify-center w-full">
<progress className="my-5 mx-2 w-4/5 h-2 progress" max="100" value={percentage} />
</div>
</div>
<div className="content-center">
<div className="flex flex-row content-center p-10">
<Button
isDisabled={baseUri === ''}
isLoading={isLoading}
onClick={() => {
setDoneList([])
setProcessList([])
setErrorList([])
void warmingProcess(baseUri, 0)
setIsLoading(true)
if (errorList.length === 0) {
setDoneCount(0)
setErrorList([])
void warmingProcess(baseUri, 0, false)
} else {
setDoneCount(doneCount - errorList.length)
void warmingProcess(baseUri, 0, true)
}
}}
>
Start
{(numTokens === 0 || errorList.length === 0) && <span>Start</span>}
{numTokens !== 0 && errorList.length > 0 && <span>Start</span>}
</Button>
</div>
</div>
<div className="grid grid-cols-5 p-4 space-x-8">
{errorList.map((value: number, index: number) => {
return <Lister key={index.toString()} data={value.toString()} />
})}
</div>
</section>
)
}