Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/contracts/diamondABI/localAddresses.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"diamondAddress":"0x99bbA657f2BbC93c02D617f8bA121cB8Fc104Acf","dathleteFacetAddress":"0x1613beB3B2C4f22Ee086B2b38C1476A3cE7f78E8","challengesFacetAddress":"0x851356ae760d987E095750cCeb3bC6014560891C","challengeTransferFacet":"0xf5059a5D33d5853360D16C683c16e67980206f36","daoFacetAddress":"0x95401dc811bb5740090279Ba06cfA8fcF6113778","shopFacetAddress":"0x998abeb3E57409262aE5b751f60747921B33613E","prtcleAddress":"0xB5d592f85ab2D955c25720EbE6FF8D4d1E1Be300"}
{"diamondAddress":"0x8f86403A4DE0BB5791fa46B8e795C547942fE4Cf","dathleteFacetAddress":"0xf5059a5D33d5853360D16C683c16e67980206f36","challengesFacetAddress":"0x95401dc811bb5740090279Ba06cfA8fcF6113778","challengeTransferFacet":"0x998abeb3E57409262aE5b751f60747921B33613E","daoFacetAddress":"0x70e0bA845a1A0F2DA3359C97E0285013525FFC49","shopFacetAddress":"0x4826533B4897376654Bb4d4AD88B7faFD0C98528","prtcleAddress":"0xB5d592f85ab2D955c25720EbE6FF8D4d1E1Be300"}
33 changes: 33 additions & 0 deletions packages/web/hooks/useGetNewestChallengeType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { isAddress } from 'ethers/lib/utils';
import { useCallback, useEffect, useState } from 'react';
import { getNewestChallengeType } from '/utils';

export const useGetNewestChallengeType = (web3Provider) => {
const [activeChallenge, setActiveChallenge] = useState();

const updateNewestChallengeType = useCallback(() => {
let stale = false;

getNewestChallengeType(web3Provider)
.then((challengeType) => {
if (!stale) {
setActiveChallenge(challengeType);
}
})
.catch((e) => {
console.log('e: ', e);
if (!stale) {
setActiveChallenge(null);
}
});

return () => {
stale = true;
setActiveChallenge();
};
}, [web3Provider]);

useEffect(() => updateNewestChallengeType(), [updateNewestChallengeType]);

return activeChallenge;
};
37 changes: 12 additions & 25 deletions packages/web/pages/mint.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useEffect, useState, useCallback } from 'react';
import constants from '../../contracts/diamondABI/localAddresses.json';
import styled from 'styled-components';
import usePoller from '/hooks/usePoller';
import { useGetNewestChallengeType } from '../hooks/useGetNewestChallengeType';

import diamondABI from '../../contracts/diamondABI/diamond.json';
import dynamic from 'next/dynamic';
Expand All @@ -21,13 +22,12 @@ const progressLabels = ['Challenge Type', 'Upload', 'Confirm'];
const Mint = (props) => {
const { web3Provider, address } = props;
const { diamondAddress } = constants;
const activeChallenge = useGetNewestChallengeType(web3Provider);
console.log('activeChallenge: ', activeChallenge);

const [videoUrl, setVideoUrl] = useState('');
const [diamondContract, setDiamondContract] = useState();
const [activeChallenge, setActiveChallenge] = useState({});
const [index, setIndex] = useState(0);



useEffect(() => {
if (!address || !web3Provider) return;
Expand All @@ -39,22 +39,12 @@ const Mint = (props) => {
setDiamondContract(contract);
}, [address, web3Provider]);

const getNewestChallengeType = async () => {
if (!diamondContract) return;
try {
const challengeType = await diamondContract.getNewestChallengeType();
setActiveChallenge(challengeType);
} catch (e) {
console.log(e);
}
};

const addChallengeTypes = useCallback(
async (types) => {
const finalizedTypes = types.map((type, index) => {
return {
id: activeChallenge.id + index + 1,

canBeTransferred: false,
...type,
};
Expand All @@ -66,12 +56,7 @@ const Mint = (props) => {
[diamondContract]
);

usePoller(
() => {
getNewestChallengeType();
},
props.pollTime ? props.pollTime : 1999
);
usePoller(() => {}, props.pollTime ? props.pollTime : 1999);

return (
<Main>
Expand All @@ -94,11 +79,13 @@ const Mint = (props) => {
</Form>
</Formik>
{!!videoUrl && <Player autoPlay={true} controls url={videoUrl} />} */}
<div>
<p>{activeChallenge.name}</p>
<p>{activeChallenge.id}</p>
{/* <SelfIdForm videoUrl={videoUrl} /> */}
</div>
{activeChallenge && (
<div>
<p>{activeChallenge.name}</p>
<p>{activeChallenge.id}</p>
{/* <SelfIdForm videoUrl={videoUrl} /> */}
</div>
)}
</Main>
);
};
Expand Down
30 changes: 30 additions & 0 deletions packages/web/utils/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { ethers } from 'ethers';
import challengeAbi from '../../contracts/diamondABI/diamond.json';
import localAddresses from '../../contracts/diamondABI/localAddresses.json';

export const isAddress = (address) => {
try {
ethers.utils.getAddress(address);
return true;
} catch (e) {
return false;
}
};

export const getContract = (address, abi, web3Provider) => {
if (!isAddress(address) || address === ethers.constants.AddressZero) {
throw Error('Invalid address');
}
return new ethers.Contract(address, abi, web3Provider.getSigner());
};

export const getNewestChallengeType = (web3Provider) => {
console.log('web3Provider: ', web3Provider);
const contract = getContract(
localAddresses.diamondAddress,
challengeAbi,
web3Provider
).getNewestChallengeType();
console.log('contract: ', contract);
return contract;
};