-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmint.js
More file actions
117 lines (101 loc) · 3.16 KB
/
mint.js
File metadata and controls
117 lines (101 loc) · 3.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import { ethers } from 'ethers';
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';
import { Formik, Form, Field } from 'formik';
import Player from 'react-player';
import ChallengeTypeScreen from '/components/create/ChallengeTypeScreen';
import { ProgressBar } from '/components/UI';
import { utils } from 'ethers';
const SelfIdForm = dynamic(() => import('/components/SelfIdForm'), {
ssr: false,
});
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 [index, setIndex] = useState(0);
useEffect(() => {
if (!address || !web3Provider) return;
const contract = new ethers.Contract(
diamondAddress,
diamondABI,
web3Provider.getSigner()
);
setDiamondContract(contract);
}, [address, web3Provider]);
const addChallengeTypes = useCallback(
async (types) => {
const finalizedTypes = types.map((type, index) => {
return {
id: activeChallenge.id + index + 1,
canBeTransferred: false,
...type,
};
});
console.log('finalizedTypes: ', finalizedTypes);
await diamondContract.addChallengeTypes(finalizedTypes);
},
[diamondContract]
);
usePoller(() => {}, props.pollTime ? props.pollTime : 1999);
return (
<Main>
<ProgressBar progressLabels={progressLabels} index={index} />
<ChallengeTypeScreen
addChallengeTypes={addChallengeTypes}
setIndex={setIndex}
/>
{/* <Formik
initialValues={{
videoUrl: '',
}}
onSubmit={({ video }) => {
const url = 'https://gateway.pinata.cloud/ipfs/' + video;
setVideoUrl(url);
}}
>
<Form>
<Field id="video" name="video" placeholder="Paste IPFS hash" />
</Form>
</Formik>
{!!videoUrl && <Player autoPlay={true} controls url={videoUrl} />} */}
{activeChallenge && (
<div>
<p>{activeChallenge.name}</p>
<p>{activeChallenge.id}</p>
{/* <SelfIdForm videoUrl={videoUrl} /> */}
</div>
)}
</Main>
);
};
export default Mint;
const Main = styled.main`
display: flex;
justify-content: space-around;
align-items: center;
flex-direction: column;
height: 100vh;
position: relative;
`;
const FormFrame = styled.form`
display: flex;
flex-direction: column;
height: 150px;
justify-content: space-around;
`;
const Input = styled.input``;
const DropzoneWrapper = styled.div`
background-color: lightgrey;
border: 2px dashed;
padding: 1.5rem 1rem;
`;