Skip to content

Commit

Permalink
support creation of v1 quest chains
Browse files Browse the repository at this point in the history
  • Loading branch information
dan13ram committed Aug 15, 2022
1 parent 7a47537 commit a716d09
Show file tree
Hide file tree
Showing 77 changed files with 14,838 additions and 15 deletions.
40 changes: 26 additions & 14 deletions pages/create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
VStack,
} from '@chakra-ui/react';
import { Signer } from 'ethers';
import { randomBytes } from 'ethers/lib/utils';
import { InferGetStaticPropsType } from 'next';
import Head from 'next/head';
import { useRouter } from 'next/router';
Expand All @@ -25,7 +26,8 @@ import NFTMetadataForm from '@/components/CreateChain/NFTMetadataForm';
import { QuestChainTile } from '@/components/QuestChainTile';
import { getGlobalInfo } from '@/graphql/globalInfo';
import { useLatestCreatedQuestChainsDataForAllChains } from '@/hooks/useLatestCreatedQuestChainsDataForAllChains';
import { QuestChainFactory, QuestChainFactory__factory } from '@/types/v0';
import { QuestChainFactory, QuestChainFactory__factory } from '@/types/v1';
import { QuestChainCommons } from '@/types/v1/contracts/QuestChainFactory';
import { awaitQuestChainAddress, waitUntilBlock } from '@/utils/graphHelpers';
import { handleError, handleTxLoading } from '@/utils/helpers';
import { isSupportedNetwork, useWallet } from '@/web3';
Expand All @@ -35,7 +37,7 @@ type Props = InferGetStaticPropsType<typeof getStaticProps>;
const Create: React.FC<Props> = ({ globalInfo }) => {
const router = useRouter();

const { provider, chainId } = useWallet();
const { address, provider, chainId } = useWallet();

const factoryContract: QuestChainFactory | undefined = useMemo(() => {
if (!isSupportedNetwork(chainId)) return;
Expand Down Expand Up @@ -71,19 +73,29 @@ const Create: React.FC<Props> = ({ globalInfo }) => {
editorAddresses,
reviewerAddresses,
}: RolesFormValues) => {
if (!chainId || !isSupportedNetwork(chainId) || !factoryContract) return;
if (
!address ||
!chainId ||
!isSupportedNetwork(chainId) ||
!factoryContract
)
return;

let tid = toast.loading(
'Waiting for Confirmation - Confirm the transaction in your Wallet',
);
try {
const tx = await factoryContract.createWithRoles(
chainUri,
nftUri,
adminAddresses,
editorAddresses,
reviewerAddresses,
);
const info: QuestChainCommons.QuestChainInfoStruct = {
details: chainUri,
tokenURI: nftUri,
owners: [address],
admins: adminAddresses,
editors: editorAddresses,
reviewers: reviewerAddresses,
quests: [],
paused: false,
};
const tx = await factoryContract.create(info, randomBytes(32));
toast.dismiss(tid);
tid = handleTxLoading(tx.hash, chainId);
const receipt = await tx.wait(1);
Expand All @@ -100,9 +112,9 @@ const Create: React.FC<Props> = ({ globalInfo }) => {
setNFTUri('');
setStep(0);

const address = await awaitQuestChainAddress(receipt);
if (address) {
router.push(`/chain/${chainId}/${address}`);
const questChainAddress = await awaitQuestChainAddress(receipt);
if (questChainAddress) {
router.push(`/chain/${chainId}/${questChainAddress}`);
} else {
setShowForm(false);
setTimeout(() => setShowForm(true), 50);
Expand All @@ -112,7 +124,7 @@ const Create: React.FC<Props> = ({ globalInfo }) => {
handleError(error);
}
},
[chainId, factoryContract, router, chainUri, nftUri],
[address, chainId, factoryContract, router, chainUri, nftUri],
);

const [show3DBeta, setShow3DBeta] = useState(false);
Expand Down
Loading

0 comments on commit a716d09

Please sign in to comment.