From 08f3a8da3ead0c280504ae55ffb2ec3daf11deca Mon Sep 17 00:00:00 2001 From: Serkan Reis Date: Thu, 29 Jun 2023 22:26:09 +0300 Subject: [PATCH] Trigger collection sync following collection creation --- pages/collections/create.tsx | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/pages/collections/create.tsx b/pages/collections/create.tsx index 7f8c2eb..301c533 100644 --- a/pages/collections/create.tsx +++ b/pages/collections/create.tsx @@ -9,6 +9,7 @@ import { toUtf8 } from '@cosmjs/encoding' import { coin } from '@cosmjs/proto-signing' import { Sidetab } from '@typeform/embed-react' +import axios from 'axios' import clsx from 'clsx' import { Alert } from 'components/Alert' import { Anchor } from 'components/Anchor' @@ -41,7 +42,7 @@ import type { DispatchExecuteArgs as VendingFactoryDispatchExecuteArgs } from 'c import { dispatchExecute as vendingFactoryDispatchExecute } from 'contracts/vendingFactory/messages/execute' import type { NextPage } from 'next' import { NextSeo } from 'next-seo' -import { useEffect, useMemo, useRef, useState } from 'react' +import { useCallback, useEffect, useMemo, useRef, useState } from 'react' import { toast } from 'react-hot-toast' import { upload } from 'services/upload' import { compareFileArrays } from 'utils/compareFileArrays' @@ -55,6 +56,7 @@ import { SG721_CODE_ID, SG721_UPDATABLE_CODE_ID, STARGAZE_URL, + SYNC_COLLECTIONS_API_URL, VENDING_FACTORY_ADDRESS, VENDING_FACTORY_FLEX_ADDRESS, VENDING_FACTORY_UPDATABLE_ADDRESS, @@ -1103,6 +1105,17 @@ const CollectionCreationPage: NextPage = () => { ) } } + + const syncCollections = useCallback(async () => { + const collectionAddress = + minterType === 'openEdition' ? openEditionMinterDetails?.sg721ContractAddress : sg721ContractAddress + if (collectionAddress) { + await axios.get(`${SYNC_COLLECTIONS_API_URL}/${collectionAddress}`).catch((error) => { + console.error('Sync collections: ', error) + }) + } + }, [minterType, openEditionMinterDetails?.sg721ContractAddress, sg721ContractAddress]) + useEffect(() => { if ( vendingMinterContractAddress !== null || @@ -1116,6 +1129,7 @@ const CollectionCreationPage: NextPage = () => { (minterType === 'openEdition' && openEditionMinterDetails?.openEditionMinterContractAddress) || (minterType === 'base' && vendingMinterContractAddress !== null && isMintingComplete) ) { + void syncCollections() if (sidetabRef.current) { setTimeout(() => { // eslint-disable-next-line @typescript-eslint/no-unsafe-call @@ -1128,6 +1142,7 @@ const CollectionCreationPage: NextPage = () => { openEditionMinterDetails?.openEditionMinterContractAddress, isMintingComplete, minterType, + syncCollections, ]) useEffect(() => {