From 3b6224db13e33ffd9b872de9ee4e7f2d68a89a1f Mon Sep 17 00:00:00 2001 From: name-user1 Date: Thu, 19 Jan 2023 10:34:28 +0300 Subject: [PATCH 1/9] Warming Module --- .env.example | 17 --- components/Lister.tsx | 17 +++ components/Sidebar.tsx | 1 + pages/collections/warmup.tsx | 194 +++++++++++++++++++++++++++++++++++ 4 files changed, 212 insertions(+), 17 deletions(-) delete mode 100644 .env.example create mode 100644 components/Lister.tsx create mode 100644 pages/collections/warmup.tsx diff --git a/.env.example b/.env.example deleted file mode 100644 index 386ce93..0000000 --- a/.env.example +++ /dev/null @@ -1,17 +0,0 @@ -APP_VERSION=0.3.7 - -NEXT_PUBLIC_PINATA_ENDPOINT_URL=https://api.pinata.cloud/pinning/pinFileToIPFS -NEXT_PUBLIC_SG721_CODE_ID=274 -NEXT_PUBLIC_VENDING_MINTER_CODE_ID=275 -NEXT_PUBLIC_VENDING_FACTORY_ADDRESS="stars1j4qn9krchp5xs8nued4j4vcr4j654wxkhf7acy76734xe5fsz08sku28s2" -NEXT_PUBLIC_BASE_FACTORY_ADDRESS="stars1c6juqgd7cm80afpmuszun66rl9zdc4kgfht8fk34tfq3zk87l78sdxngzv" -NEXT_PUBLIC_SG721_NAME_ADDRESS="stars1fx74nkqkw2748av8j7ew7r3xt9cgjqduwn8m0ur5lhe49uhlsasszc5fhr" -NEXT_PUBLIC_BASE_MINTER_CODE_ID=613 -NEXT_PUBLIC_WHITELIST_CODE_ID=277 - - -NEXT_PUBLIC_API_URL=https://nft-api.elgafar-1.stargaze-apis.com -NEXT_PUBLIC_BLOCK_EXPLORER_URL=https://testnet-explorer.publicawesome.dev/stargaze -NEXT_PUBLIC_NETWORK=testnet -NEXT_PUBLIC_STARGAZE_WEBSITE_URL=https://testnet.publicawesome.dev -NEXT_PUBLIC_WEBSITE_URL=https:// \ No newline at end of file diff --git a/components/Lister.tsx b/components/Lister.tsx new file mode 100644 index 0000000..aa12fc8 --- /dev/null +++ b/components/Lister.tsx @@ -0,0 +1,17 @@ +import React from 'react' + +export interface ListerProps { + data: string + key: string +} + +function Lister({ data, key }: ListerProps) { + return ( + + {key}-{data} + + ) +} + +// eslint-disable-next-line import/no-default-export +export default Lister diff --git a/components/Sidebar.tsx b/components/Sidebar.tsx index 5e44882..4398384 100644 --- a/components/Sidebar.tsx +++ b/components/Sidebar.tsx @@ -14,6 +14,7 @@ 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 new file mode 100644 index 0000000..b3d64b1 --- /dev/null +++ b/pages/collections/warmup.tsx @@ -0,0 +1,194 @@ +import axios from 'axios' +import { Button } from 'components/Button' +import { dispatchQuery } from 'components/collections/queries/query' +import { ContractPageHeader } from 'components/ContractPageHeader' +import { AddressInput } from 'components/forms/FormInput' +import { useInputState } from 'components/forms/FormInput.hooks' +import Lister from 'components/Lister' +import { useContracts } from 'contexts/contracts' +import type { NextPage } from 'next' +import { NextSeo } from 'next-seo' +import { useEffect, useMemo, useState } from 'react' +import { toast } from 'react-hot-toast' +import { useQuery } from 'react-query' +import { withMetadata } from 'utils/layout' +import { links } from 'utils/links' + +const CollectionQueriesPage: NextPage = () => { + const { baseMinter: baseMinterContract, vendingMinter: vendingMinterContract, sg721: sg721Contract } = useContracts() + const type = 'config' + const sg721ContractAddress = `sg721ContractState.value` + const [doneList, setDoneList] = useState([]) + const [processList, setProcessList] = useState([]) + const [numTokens, setNumTokens] = useState(0) + const [pers, setPers] = useState(0) + const minterContractState = useInputState({ + id: 'minter-contract-address', + name: 'minter-contract-address', + title: 'Minter Address', + subtitle: 'Address of the Minter contract', + }) + const minterContractAddress = minterContractState.value + + const vendingMinterMessages = useMemo( + () => vendingMinterContract?.use(minterContractAddress), + [vendingMinterContract, minterContractAddress], + ) + const baseMinterMessages = useMemo( + () => baseMinterContract?.use(minterContractAddress), + [baseMinterContract, minterContractAddress], + ) + const sg721Messages = useMemo(() => sg721Contract?.use(sg721ContractAddress), [sg721Contract, sg721ContractAddress]) + + const { data: response } = useQuery( + [sg721Messages, baseMinterMessages, vendingMinterMessages, type] as const, + async ({ queryKey }) => { + const [_sg721Messages, _baseMinterMessages_, _vendingMinterMessages, _type] = queryKey + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + const result = await dispatchQuery({ + vendingMinterMessages: _vendingMinterMessages, + baseMinterMessages: _baseMinterMessages_, + sg721Messages: _sg721Messages, + type: _type, + }) + return result + }, + { + placeholderData: null, + onError: (error: any) => { + toast.error(error.message, { style: { maxWidth: 'none' } }) + }, + enabled: Boolean(sg721ContractAddress && minterContractAddress && type), + retry: false, + }, + ) + + useEffect(() => { + if (response) { + setNumTokens(response['num_tokens']) + } + }, [response]) + + useEffect(() => { + if (numTokens !== 0) setPers((100 * doneList.length) / numTokens) + else setPers(0) + }, [doneList.length, numTokens]) + + function chooseAlternate(url: string, attempt: number) { + let alternate + switch (attempt) { + case 1: { + alternate = url.replace('ipfs://', 'https://ipfs.stargaze.zone/ipfs/') + break + } + case 2: { + alternate = url.replace('ipfs://', 'https://ipfs.io/ipfs/') + break + } + case 3: { + alternate = url.replace('ipfs://', 'https://cf-ipfs.com/ipfs/') + break + } + default: { + alternate = url.replace('ipfs://', 'https://ipfs-gw.stargaze-apis.com/ipfs/') + break + } + } + return alternate + } + + 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 + }) + return + } + } catch (e) { + console.log('hata: ', i, e) + } + if (totalAttempt !== 4) { + void warmOne(i, image, attempt === 3 ? 0 : attempt + 1, attempt === 3 ? totalAttempt + 1 : totalAttempt) + } + } + + async function warmingProcess(url: string, attempt: number) { + const link = `${chooseAlternate(url, attempt)}/1` + try { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + const { data, status } = await axios.get(link) + if (status === 200) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + for (let i = 1; i <= response['num_tokens']; 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) + } else toast.error('File can not be reachable at the moment! Please try again later...') + } catch (e) { + console.log(e) + } + } + + return ( +
+ + +
+ +
+
+
+
+
Total
+
Warmed
+
Percentage
+
+
+
{numTokens}
+
{doneList.length}
+
%{pers}
+
+
+
+ +
+
+ +
+ {processList.map((value: number, index: number) => { + return + })} +
+
+ ) +} + +export default withMetadata(CollectionQueriesPage, { center: false }) From fc20a541e26b0890a35f6796dacaa41412a0ec76 Mon Sep 17 00:00:00 2001 From: name-user1 Date: Thu, 19 Jan 2023 10:59:55 +0300 Subject: [PATCH 2/9] Small fixes --- .env.example | 17 +++++++++++++++++ pages/collections/warmup.tsx | 9 +++++---- 2 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..386ce93 --- /dev/null +++ b/.env.example @@ -0,0 +1,17 @@ +APP_VERSION=0.3.7 + +NEXT_PUBLIC_PINATA_ENDPOINT_URL=https://api.pinata.cloud/pinning/pinFileToIPFS +NEXT_PUBLIC_SG721_CODE_ID=274 +NEXT_PUBLIC_VENDING_MINTER_CODE_ID=275 +NEXT_PUBLIC_VENDING_FACTORY_ADDRESS="stars1j4qn9krchp5xs8nued4j4vcr4j654wxkhf7acy76734xe5fsz08sku28s2" +NEXT_PUBLIC_BASE_FACTORY_ADDRESS="stars1c6juqgd7cm80afpmuszun66rl9zdc4kgfht8fk34tfq3zk87l78sdxngzv" +NEXT_PUBLIC_SG721_NAME_ADDRESS="stars1fx74nkqkw2748av8j7ew7r3xt9cgjqduwn8m0ur5lhe49uhlsasszc5fhr" +NEXT_PUBLIC_BASE_MINTER_CODE_ID=613 +NEXT_PUBLIC_WHITELIST_CODE_ID=277 + + +NEXT_PUBLIC_API_URL=https://nft-api.elgafar-1.stargaze-apis.com +NEXT_PUBLIC_BLOCK_EXPLORER_URL=https://testnet-explorer.publicawesome.dev/stargaze +NEXT_PUBLIC_NETWORK=testnet +NEXT_PUBLIC_STARGAZE_WEBSITE_URL=https://testnet.publicawesome.dev +NEXT_PUBLIC_WEBSITE_URL=https:// \ No newline at end of file diff --git a/pages/collections/warmup.tsx b/pages/collections/warmup.tsx index b3d64b1..7c11d4d 100644 --- a/pages/collections/warmup.tsx +++ b/pages/collections/warmup.tsx @@ -66,6 +66,7 @@ const CollectionQueriesPage: NextPage = () => { useEffect(() => { if (response) { setNumTokens(response['num_tokens']) + setPers(0) } }, [response]) @@ -148,11 +149,11 @@ const CollectionQueriesPage: NextPage = () => { return (
- +
@@ -167,7 +168,7 @@ const CollectionQueriesPage: NextPage = () => {
{numTokens}
{doneList.length}
-
%{pers}
+
{(Math.round(pers * 100) / 100).toFixed(2)}%
From de79ffa1db614557173d203ecb27af525174db75 Mon Sep 17 00:00:00 2001 From: name-user1 Date: Thu, 19 Jan 2023 12:12:57 +0300 Subject: [PATCH 3/9] Routing --- pages/collections/warmup.tsx | 43 +++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/pages/collections/warmup.tsx b/pages/collections/warmup.tsx index 7c11d4d..bec6c21 100644 --- a/pages/collections/warmup.tsx +++ b/pages/collections/warmup.tsx @@ -7,6 +7,7 @@ import { useInputState } from 'components/forms/FormInput.hooks' import Lister from 'components/Lister' import { useContracts } from 'contexts/contracts' import type { NextPage } from 'next' +import { useRouter } from 'next/router' import { NextSeo } from 'next-seo' import { useEffect, useMemo, useState } from 'react' import { toast } from 'react-hot-toast' @@ -20,6 +21,7 @@ const CollectionQueriesPage: NextPage = () => { const sg721ContractAddress = `sg721ContractState.value` const [doneList, setDoneList] = useState([]) const [processList, setProcessList] = useState([]) + const [errorList, setErrorList] = useState([]) const [numTokens, setNumTokens] = useState(0) const [pers, setPers] = useState(0) const minterContractState = useInputState({ @@ -40,6 +42,20 @@ const CollectionQueriesPage: NextPage = () => { ) const sg721Messages = useMemo(() => sg721Contract?.use(sg721ContractAddress), [sg721Contract, sg721ContractAddress]) + const router = useRouter() + + useEffect(() => { + if (minterContractState.value.length > 0) { + void router.replace({ query: { minterContractAddress } }) + } + }, [minterContractState.value]) + + useEffect(() => { + const initial = new URL(document.URL).searchParams.get('minterContractAddress') + if (initial && initial.length > 0) minterContractState.onChange(initial) + console.log(minterContractState, minterContractAddress) + }, []) + const { data: response } = useQuery( [sg721Messages, baseMinterMessages, vendingMinterMessages, type] as const, async ({ queryKey }) => { @@ -67,7 +83,10 @@ const CollectionQueriesPage: NextPage = () => { if (response) { setNumTokens(response['num_tokens']) setPers(0) - } + setDoneList([]) + setProcessList([]) + setErrorList([]) + } else setNumTokens(0) }, [response]) useEffect(() => { @@ -79,7 +98,7 @@ const CollectionQueriesPage: NextPage = () => { let alternate switch (attempt) { case 1: { - alternate = url.replace('ipfs://', 'https://ipfs.stargaze.zone/ipfs/') + alternate = url.replace('ipfs://', 'https://cf-ipfs.com/ipfs/') break } case 2: { @@ -87,11 +106,11 @@ const CollectionQueriesPage: NextPage = () => { break } case 3: { - alternate = url.replace('ipfs://', 'https://cf-ipfs.com/ipfs/') + alternate = url.replace('ipfs://', 'https://ipfs-gw.stargaze-apis.com/ipfs/') break } default: { - alternate = url.replace('ipfs://', 'https://ipfs-gw.stargaze-apis.com/ipfs/') + alternate = url.replace('ipfs://', 'https://ipfs.stargaze.zone/ipfs/') break } } @@ -125,6 +144,17 @@ const CollectionQueriesPage: NextPage = () => { } if (totalAttempt !== 4) { void warmOne(i, image, attempt === 3 ? 0 : attempt + 1, attempt === 3 ? totalAttempt + 1 : totalAttempt) + } else { + setErrorList((existingItems) => { + return [i, ...existingItems] + }) + setProcessList((existingItems) => { + const index = existingItems.indexOf(i, 0) + if (index > -1) { + existingItems.splice(index, 1) + } + return existingItems + }) } } @@ -175,6 +205,9 @@ const CollectionQueriesPage: NextPage = () => {
- {processList.map((value: number, index: number) => { + {errorList.map((value: number, index: number) => { return })}
From aeec57bdefb9b64ced35e30da0fe60350dc77e8b Mon Sep 17 00:00:00 2001 From: Serkan Reis Date: Thu, 19 Jan 2023 13:30:16 +0300 Subject: [PATCH 4/9] Query update --- pages/collections/warmup.tsx | 70 ++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 40 deletions(-) diff --git a/pages/collections/warmup.tsx b/pages/collections/warmup.tsx index bec6c21..40c736f 100644 --- a/pages/collections/warmup.tsx +++ b/pages/collections/warmup.tsx @@ -1,71 +1,63 @@ +/* eslint-disable eslint-comments/disable-enable-pair */ +/* eslint-disable @typescript-eslint/no-unsafe-assignment */ import axios from 'axios' import { Button } from 'components/Button' -import { dispatchQuery } from 'components/collections/queries/query' import { ContractPageHeader } from 'components/ContractPageHeader' import { AddressInput } from 'components/forms/FormInput' import { useInputState } from 'components/forms/FormInput.hooks' import Lister from 'components/Lister' import { useContracts } from 'contexts/contracts' +import { dispatchQuery } from 'contracts/vendingMinter/messages/query' import type { NextPage } from 'next' import { useRouter } from 'next/router' import { NextSeo } from 'next-seo' -import { useEffect, useMemo, useState } from 'react' +import { useEffect, useState } from 'react' import { toast } from 'react-hot-toast' import { useQuery } from 'react-query' import { withMetadata } from 'utils/layout' import { links } from 'utils/links' +import { useWallet } from '../../contexts/wallet' + const CollectionQueriesPage: NextPage = () => { - const { baseMinter: baseMinterContract, vendingMinter: vendingMinterContract, sg721: sg721Contract } = useContracts() - const type = 'config' - const sg721ContractAddress = `sg721ContractState.value` + const { vendingMinter: vendingMinterContract } = useContracts() + const wallet = useWallet() + const [doneList, setDoneList] = useState([]) const [processList, setProcessList] = useState([]) const [errorList, setErrorList] = useState([]) const [numTokens, setNumTokens] = useState(0) - const [pers, setPers] = useState(0) + const [percentage, setPercentage] = useState(0) const minterContractState = useInputState({ id: 'minter-contract-address', name: 'minter-contract-address', - title: 'Minter Address', - subtitle: 'Address of the Minter contract', + title: 'Minter Contract Address', + defaultValue: '', + placeholder: 'stars1...', }) const minterContractAddress = minterContractState.value - const vendingMinterMessages = useMemo( - () => vendingMinterContract?.use(minterContractAddress), - [vendingMinterContract, minterContractAddress], - ) - const baseMinterMessages = useMemo( - () => baseMinterContract?.use(minterContractAddress), - [baseMinterContract, minterContractAddress], - ) - const sg721Messages = useMemo(() => sg721Contract?.use(sg721ContractAddress), [sg721Contract, sg721ContractAddress]) - const router = useRouter() useEffect(() => { - if (minterContractState.value.length > 0) { + if (minterContractAddress.length > 0) { void router.replace({ query: { minterContractAddress } }) } - }, [minterContractState.value]) + }, [minterContractAddress]) useEffect(() => { const initial = new URL(document.URL).searchParams.get('minterContractAddress') if (initial && initial.length > 0) minterContractState.onChange(initial) - console.log(minterContractState, minterContractAddress) }, []) const { data: response } = useQuery( - [sg721Messages, baseMinterMessages, vendingMinterMessages, type] as const, - async ({ queryKey }) => { - const [_sg721Messages, _baseMinterMessages_, _vendingMinterMessages, _type] = queryKey - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + [minterContractAddress, vendingMinterContract, wallet] as const, + async () => { + const messages = vendingMinterContract?.use(minterContractAddress) const result = await dispatchQuery({ - vendingMinterMessages: _vendingMinterMessages, - baseMinterMessages: _baseMinterMessages_, - sg721Messages: _sg721Messages, - type: _type, + address: '', + messages, + type: 'config', }) return result }, @@ -74,15 +66,14 @@ const CollectionQueriesPage: NextPage = () => { onError: (error: any) => { toast.error(error.message, { style: { maxWidth: 'none' } }) }, - enabled: Boolean(sg721ContractAddress && minterContractAddress && type), - retry: false, + enabled: Boolean(minterContractAddress && vendingMinterContract), }, ) useEffect(() => { if (response) { setNumTokens(response['num_tokens']) - setPers(0) + setPercentage(0) setDoneList([]) setProcessList([]) setErrorList([]) @@ -90,8 +81,8 @@ const CollectionQueriesPage: NextPage = () => { }, [response]) useEffect(() => { - if (numTokens !== 0) setPers((100 * doneList.length) / numTokens) - else setPers(0) + if (numTokens !== 0) setPercentage((100 * doneList.length) / numTokens) + else setPercentage(0) }, [doneList.length, numTokens]) function chooseAlternate(url: string, attempt: number) { @@ -140,7 +131,7 @@ const CollectionQueriesPage: NextPage = () => { return } } catch (e) { - console.log('hata: ', i, e) + console.log('error: ', i, e) } if (totalAttempt !== 4) { void warmOne(i, image, attempt === 3 ? 0 : attempt + 1, attempt === 3 ? totalAttempt + 1 : totalAttempt) @@ -161,7 +152,6 @@ const CollectionQueriesPage: NextPage = () => { async function warmingProcess(url: string, attempt: number) { const link = `${chooseAlternate(url, attempt)}/1` try { - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment const { data, status } = await axios.get(link) if (status === 200) { // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access @@ -179,11 +169,11 @@ const CollectionQueriesPage: NextPage = () => { return (
- +
@@ -198,7 +188,7 @@ const CollectionQueriesPage: NextPage = () => {
{numTokens}
{doneList.length}
-
{(Math.round(pers * 100) / 100).toFixed(2)}%
+
{(Math.round(percentage * 100) / 100).toFixed(2)}%
From de263c604ecc577654d64dacc0a8b59aacd48b38 Mon Sep 17 00:00:00 2001 From: name-user1 Date: Fri, 20 Jan 2023 16:57:09 +0300 Subject: [PATCH 5/9] Progress bar added --- pages/collections/warmup.tsx | 91 +++++++++++++++++------------------- 1 file changed, 43 insertions(+), 48 deletions(-) diff --git a/pages/collections/warmup.tsx b/pages/collections/warmup.tsx index 40c736f..f4d6c79 100644 --- a/pages/collections/warmup.tsx +++ b/pages/collections/warmup.tsx @@ -1,33 +1,33 @@ /* eslint-disable eslint-comments/disable-enable-pair */ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ +import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' import axios from 'axios' 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 { useContracts } from 'contexts/contracts' -import { dispatchQuery } from 'contracts/vendingMinter/messages/query' 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 { useQuery } from 'react-query' import { withMetadata } from 'utils/layout' import { links } from 'utils/links' -import { useWallet } from '../../contexts/wallet' +interface ConfigResponse { + num_tokens: number + base_token_uri: string +} const CollectionQueriesPage: NextPage = () => { - const { vendingMinter: vendingMinterContract } = useContracts() - const wallet = useWallet() - + const [client, setClient] = useState() + const [baseUri, SetBaseUri] = useState('') const [doneList, setDoneList] = useState([]) const [processList, setProcessList] = useState([]) const [errorList, setErrorList] = useState([]) const [numTokens, setNumTokens] = useState(0) - const [percentage, setPercentage] = useState(0) + const [percentage, setPercentage] = useState('0.00') const minterContractState = useInputState({ id: 'minter-contract-address', name: 'minter-contract-address', @@ -39,6 +39,30 @@ const CollectionQueriesPage: NextPage = () => { const router = useRouter() + useEffect(() => { + async function init() { + setClient(await CosmWasmClient.connect('https://rpc.elgafar-1.stargaze-apis.com/')) //'https://rpc.stargaze-apis.com/')) + } + void init() + }, []) + + useEffect(() => { + async function get() { + if (client && minterContractAddress) { + const res: ConfigResponse = await client.queryContractSmart(minterContractAddress, { + config: {}, + }) + setNumTokens(res.num_tokens) + SetBaseUri(res.base_token_uri) + setPercentage('0.00') + setDoneList([]) + setProcessList([]) + setErrorList([]) + } + } + void get() + }, [minterContractAddress, client]) + useEffect(() => { if (minterContractAddress.length > 0) { void router.replace({ query: { minterContractAddress } }) @@ -50,39 +74,9 @@ const CollectionQueriesPage: NextPage = () => { if (initial && initial.length > 0) minterContractState.onChange(initial) }, []) - const { data: response } = useQuery( - [minterContractAddress, vendingMinterContract, wallet] as const, - async () => { - const messages = vendingMinterContract?.use(minterContractAddress) - const result = await dispatchQuery({ - address: '', - messages, - type: 'config', - }) - return result - }, - { - placeholderData: null, - onError: (error: any) => { - toast.error(error.message, { style: { maxWidth: 'none' } }) - }, - enabled: Boolean(minterContractAddress && vendingMinterContract), - }, - ) - useEffect(() => { - if (response) { - setNumTokens(response['num_tokens']) - setPercentage(0) - setDoneList([]) - setProcessList([]) - setErrorList([]) - } else setNumTokens(0) - }, [response]) - - useEffect(() => { - if (numTokens !== 0) setPercentage((100 * doneList.length) / numTokens) - else setPercentage(0) + if (numTokens !== 0) setPercentage((((Math.round(100 * doneList.length) / numTokens) * 100) / 100).toFixed(2)) + else setPercentage('0') }, [doneList.length, numTokens]) function chooseAlternate(url: string, attempt: number) { @@ -154,8 +148,7 @@ const CollectionQueriesPage: NextPage = () => { try { const { data, status } = await axios.get(link) if (status === 200) { - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access - for (let i = 1; i <= response['num_tokens']; i++) { + 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) } @@ -180,7 +173,7 @@ const CollectionQueriesPage: NextPage = () => {
-
+
Total
Warmed
Percentage
@@ -188,24 +181,26 @@ const CollectionQueriesPage: NextPage = () => {
{numTokens}
{doneList.length}
-
{(Math.round(percentage * 100) / 100).toFixed(2)}%
+
{percentage}%
+
+
+
-
+
-
{errorList.map((value: number, index: number) => { return From 94d7d1571cb5c2b090ceb237087129bb9d7bba65 Mon Sep 17 00:00:00 2001 From: name-user1 Date: Tue, 31 Jan 2023 17:14:58 +0300 Subject: [PATCH 6/9] Minor changes --- components/Sidebar.tsx | 1 - pages/collections/warmup.tsx | 96 ++++++++++++++++++------------------ 2 files changed, 49 insertions(+), 48 deletions(-) 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 - })} -
) } From 55067c9256c1e5787995cfe754f259008aeb0567 Mon Sep 17 00:00:00 2001 From: Serkan Reis Date: Wed, 1 Feb 2023 16:17:39 +0300 Subject: [PATCH 7/9] Update maintainer list --- .github/CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index b480a52..fd55930 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1 +1 @@ -* @findolor @MightOfOaks @name-user1 +* @MightOfOaks @name-user1 @Ninjatosba \ No newline at end of file From 12479437fd3a1cea49b43b86fa630b1e6c774024 Mon Sep 17 00:00:00 2001 From: Serkan Reis Date: Wed, 1 Feb 2023 16:20:42 +0300 Subject: [PATCH 8/9] Update maintainer list - add new line --- .github/CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index fd55930..d175b9e 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1 +1 @@ -* @MightOfOaks @name-user1 @Ninjatosba \ No newline at end of file +* @MightOfOaks @name-user1 @Ninjatosba From 5a8dbcba4fa9a4aadc2ea8b6c4a2e2a0e28468b8 Mon Sep 17 00:00:00 2001 From: Serkan Reis Date: Wed, 1 Feb 2023 16:22:15 +0300 Subject: [PATCH 9/9] Remove Lister.tsx --- components/Lister.tsx | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 components/Lister.tsx diff --git a/components/Lister.tsx b/components/Lister.tsx deleted file mode 100644 index aa12fc8..0000000 --- a/components/Lister.tsx +++ /dev/null @@ -1,17 +0,0 @@ -import React from 'react' - -export interface ListerProps { - data: string - key: string -} - -function Lister({ data, key }: ListerProps) { - return ( - - {key}-{data} - - ) -} - -// eslint-disable-next-line import/no-default-export -export default Lister