@@ -4,7 +4,24 @@ import React, {
4
4
useState ,
5
5
useEffect ,
6
6
} from 'react' ;
7
- import { useToast , Button , Input , Text } from '@chakra-ui/react' ;
7
+ import {
8
+ useToast ,
9
+ Button ,
10
+ Input ,
11
+ Text ,
12
+ Modal ,
13
+ ModalOverlay ,
14
+ ModalContent ,
15
+ ModalHeader ,
16
+ ModalBody ,
17
+ ModalCloseButton ,
18
+ useDisclosure ,
19
+ CircularProgress ,
20
+ Center ,
21
+ Link ,
22
+ Stack ,
23
+ } from '@chakra-ui/react' ;
24
+ import { ExternalLinkIcon } from '@chakra-ui/icons' ;
8
25
import { ethers } from 'ethers' ;
9
26
import WalletConnectProvider from '@walletconnect/web3-provider' ;
10
27
import Web3Modal from 'web3modal' ;
@@ -39,6 +56,10 @@ const DirectMint = ({ developerId }: DirectMintProps) => {
39
56
const [ tokenID , setTokenID ] = useState ( developerId ? developerId : '' ) ;
40
57
const [ networkError , setNetworkError ] = useState ( false ) ;
41
58
const [ web3Modal , setWeb3Modal ] = useState < Web3Modal > ( ) ;
59
+ const [ txInProgress , setTxInProgress ] = useState ( false ) ;
60
+ const [ txReceipt , setTxReceipt ] = useState ( '' ) ;
61
+
62
+ const { isOpen, onOpen, onClose } = useDisclosure ( ) ;
42
63
43
64
const toast = useToast ( ) ;
44
65
@@ -55,7 +76,8 @@ const DirectMint = ({ developerId }: DirectMintProps) => {
55
76
const _web3 = new ethers . providers . Web3Provider ( _provider ) ;
56
77
_signer = _web3 . getSigner ( ) ;
57
78
mint_contract = new ethers . Contract (
58
- DEVELOPER_DAO_CONTRACT ,
79
+ //DEVELOPER_DAO_CONTRACT,
80
+ '0xbf114c4cbb4e70e6098589a918c84292cb40602a' ,
59
81
MINT_CONTRACT . abi ,
60
82
_signer ,
61
83
) ;
@@ -70,7 +92,8 @@ const DirectMint = ({ developerId }: DirectMintProps) => {
70
92
} ;
71
93
72
94
const _checkNetwork = ( chainId : number ) => {
73
- if ( chainId === MAINNET_NETWORK_ID ) {
95
+ if ( chainId === 4 ) {
96
+ //MAINNET_NETWORK_ID) {
74
97
return true ;
75
98
}
76
99
setNetworkError ( true ) ;
@@ -121,18 +144,17 @@ const DirectMint = ({ developerId }: DirectMintProps) => {
121
144
) => {
122
145
try {
123
146
const tx = await mint_contract . claim ( tokenID ) ;
124
-
125
- toast ( {
126
- title : t ( 'transactionSending' ) ,
127
- isClosable : true ,
128
- } ) ;
147
+ setTxInProgress ( true ) ;
148
+ onOpen ( ) ;
129
149
130
150
const receipt = await tx . wait ( ) ;
151
+ setTxReceipt ( receipt . transactionHash ) ;
131
152
132
153
if ( receipt . status === 0 ) {
133
154
throw new Error ( 'Transaction failed' ) ;
134
155
}
135
156
} catch ( error : any ) {
157
+ setTxInProgress ( false ) ;
136
158
if ( error . code === ERROR_CODE_TX_REJECTED_BY_USER ) {
137
159
toast ( {
138
160
title : t ( 'userCancelTransaction' ) ,
@@ -151,16 +173,15 @@ const DirectMint = ({ developerId }: DirectMintProps) => {
151
173
setTokenID ( '' ) ;
152
174
return ;
153
175
}
154
-
155
- toast ( {
156
- title : t ( 'TokenMintMessage' ) ,
157
- description : t ( 'NFTMintSuccess' ) ,
158
- status : 'success' ,
159
- isClosable : true ,
160
- } ) ;
161
176
setTokenID ( '' ) ;
162
177
} ;
163
178
179
+ const modalCloseHandler = ( ) => {
180
+ setTxInProgress ( false ) ;
181
+ setTxReceipt ( '' ) ;
182
+ onClose ( ) ;
183
+ } ;
184
+
164
185
return (
165
186
< >
166
187
{ ! userWallet && (
@@ -175,38 +196,78 @@ const DirectMint = ({ developerId }: DirectMintProps) => {
175
196
</ Button >
176
197
) }
177
198
{ userWallet && (
178
- < Input
179
- w = "100%"
180
- size = "md "
181
- value = { tokenID }
182
- onChange = { tokenNameHandler }
183
- type = "text"
184
- placeholder = { t ( 'tokenIDPlaceholder' ) }
185
- mt = "10"
186
- > </ Input >
187
- ) }
199
+ < >
200
+ < Input
201
+ w = "100% "
202
+ size = "md"
203
+ value = { tokenID }
204
+ onChange = { tokenNameHandler }
205
+ type = "text"
206
+ placeholder = { t ( 'tokenIDPlaceholder' ) }
207
+ mt = "10"
208
+ > </ Input >
188
209
189
- < Button
190
- w = "100%"
191
- colorScheme = "green"
192
- onClick = { createTokenHandler }
193
- disabled = { ! userWallet || networkError }
194
- mt = "10"
195
- fontSize = { { base : 's' , sm : 'xl' } }
196
- >
197
- { t ( 'mintTokenText' ) }
198
- </ Button >
210
+ < Button
211
+ w = "100%"
212
+ colorScheme = "green"
213
+ onClick = { createTokenHandler }
214
+ disabled = { networkError }
215
+ mt = "10"
216
+ fontSize = { { base : 's' , sm : 'xl' } }
217
+ >
218
+ { t ( 'mintTokenText' ) }
219
+ </ Button >
199
220
200
- { userWallet && (
201
- < Button
202
- w = "100%"
203
- colorScheme = "orange"
204
- onClick = { disconnectWallet }
205
- mt = "10"
206
- fontSize = { { base : 's' , sm : 'xl' } }
207
- >
208
- { t ( 'disconnectWallet' ) }
209
- </ Button >
221
+ { userWallet && (
222
+ < Button
223
+ w = "100%"
224
+ colorScheme = "orange"
225
+ onClick = { disconnectWallet }
226
+ mt = "10"
227
+ fontSize = { { base : 's' , sm : 'xl' } }
228
+ >
229
+ { t ( 'disconnectWallet' ) }
230
+ </ Button >
231
+ ) }
232
+ </ >
233
+ ) }
234
+
235
+ { txInProgress && (
236
+ < Modal isOpen = { isOpen } onClose = { modalCloseHandler } isCentered >
237
+ < ModalOverlay />
238
+ < ModalContent >
239
+ < ModalHeader > Minting your NFT...</ ModalHeader >
240
+ < ModalCloseButton />
241
+ < ModalBody >
242
+ < Center h = "160px" >
243
+ { ! txReceipt && (
244
+ < CircularProgress
245
+ isIndeterminate
246
+ color = "green.300"
247
+ size = "100px"
248
+ />
249
+ ) }
250
+ { txReceipt && (
251
+ < >
252
+ < Stack spacing = { 6 } >
253
+ < Text color = "green.500" fontSize = "lg" >
254
+ Your NFT has been minted!
255
+ </ Text >
256
+ < Link
257
+ fontSize = "lg"
258
+ color = "#3182ce"
259
+ href = { `https://rinkeby.etherscan.io/tx/${ txReceipt } ` }
260
+ isExternal
261
+ >
262
+ View your TX on Etherscan < ExternalLinkIcon mx = "2px" />
263
+ </ Link >
264
+ </ Stack >
265
+ </ >
266
+ ) }
267
+ </ Center >
268
+ </ ModalBody >
269
+ </ ModalContent >
270
+ </ Modal >
210
271
) }
211
272
212
273
{ networkError && < Text color = "red" > { t ( 'ethereumNetworkPrompt' ) } </ Text > }
0 commit comments