@@ -13,7 +13,6 @@ import {
13
13
DEVELOPER_DAO_CONTRACT ,
14
14
ERROR_CODE_TX_REJECTED_BY_USER ,
15
15
MAINNET_NETWORK_ID ,
16
- INFURA_ID ,
17
16
} from '../../utils/DeveloperDaoConstants' ;
18
17
19
18
import MINT_CONTRACT from '../../artifacts/ddao.json' ;
@@ -27,15 +26,13 @@ interface DirectMintProps {
27
26
28
27
const providerOptions = {
29
28
walletconnect : {
30
- package : WalletConnectProvider , // required
29
+ package : WalletConnectProvider ,
31
30
options : {
32
- infuraId : INFURA_ID , // required
31
+ infuraId : process . env . INFURA_ID ,
33
32
} ,
34
33
} ,
35
34
} ;
36
35
37
- // Logic & buttons needed for Direct Minting
38
- // Can be reused anywhere else as needed
39
36
const DirectMint = ( { developerId } : DirectMintProps ) => {
40
37
const { t } = useTranslation ( ) ;
41
38
const [ userWallet , setUserWallet ] = useState ( '' ) ;
@@ -47,9 +44,9 @@ const DirectMint = ({ developerId }: DirectMintProps) => {
47
44
48
45
useEffect ( ( ) => {
49
46
const web3Modal = new Web3Modal ( {
50
- network : 'mainnet' , // optional
51
- cacheProvider : false , // optional
52
- providerOptions, // required
47
+ network : 'mainnet' ,
48
+ cacheProvider : false ,
49
+ providerOptions,
53
50
} ) ;
54
51
setWeb3Modal ( web3Modal ) ;
55
52
} , [ ] ) ;
@@ -66,7 +63,6 @@ const DirectMint = ({ developerId }: DirectMintProps) => {
66
63
const accounts = await _web3 . listAccounts ( ) ;
67
64
const { chainId } = await _web3 . getNetwork ( ) ;
68
65
69
- // MetaMask does not give you all accounts, only the selected account
70
66
const selectedAccount = accounts [ 0 ] ;
71
67
72
68
setUserWallet ( selectedAccount ) ;
@@ -90,17 +86,14 @@ const DirectMint = ({ developerId }: DirectMintProps) => {
90
86
return ;
91
87
}
92
88
93
- // Subscribe to accounts change
94
89
_provider . on ( 'accountsChanged' , ( accounts : string ) => {
95
90
fetchAccountData ( ) ;
96
91
} ) ;
97
92
98
- // Subscribe to chainId change
99
93
_provider . on ( 'chainChanged' , ( chainId : string ) => {
100
94
fetchAccountData ( ) ;
101
95
} ) ;
102
96
103
- // Subscribe to networkId change
104
97
_provider . on ( 'networkChanged' , ( networkId : string ) => {
105
98
setNetworkError ( false ) ;
106
99
fetchAccountData ( ) ;
@@ -117,63 +110,42 @@ const DirectMint = ({ developerId }: DirectMintProps) => {
117
110
event ,
118
111
) => {
119
112
try {
120
- // If a transaction fails, we save that error in the component's state.
121
- // We only save one such error, so before sending a second transaction, we
122
- // clear it.
123
-
124
- // We send the transaction, and save its hash in the Dapp's state. This
125
- // way we can indicate that we are waiting for it to be mined.
126
113
const tx = await mint_contract . claim ( tokenID ) ;
127
114
128
- //Alert transaction is in progress
129
115
toast ( {
130
- title : 'Transaction Being Sent' ,
116
+ title : t ( 'transactionSending' ) ,
131
117
isClosable : true ,
132
118
} ) ;
133
119
134
- // We use .wait() to wait for the transaction to be mined. This method
135
- // returns the transaction's receipt.
136
120
const receipt = await tx . wait ( ) ;
137
121
138
- // The receipt, contains a status flag, which is 0 to indicate an error.
139
122
if ( receipt . status === 0 ) {
140
- // We can't know the exact error that make the transaction fail once it
141
- // was mined, so we throw this generic one.
142
123
throw new Error ( 'Transaction failed' ) ;
143
124
}
144
-
145
- // If we got here, the transaction was successful, so you may want to
146
- // update your state. Here, we update the user's balance.
147
125
} catch ( error : any ) {
148
- // We check the error code to see if this error was produced because the
149
- // user rejected a tx. If that's the case, we do nothing.
150
126
if ( error . code === ERROR_CODE_TX_REJECTED_BY_USER ) {
151
- // resetFields();
152
127
toast ( {
153
128
title : t ( 'userCancelTransaction' ) ,
154
129
status : 'error' ,
155
130
isClosable : true ,
156
131
} ) ;
157
132
return ;
158
133
}
159
- // Other errors are logged and stored in the Dapp's state. This is used to
160
- // show them to the user, and for debugging.
161
- //console.error(error);
134
+
162
135
toast ( {
163
- title : error . code ,
136
+ title : t ( 'errorMinting' ) ,
164
137
description : t ( 'tokenUnavailable' ) ,
165
- status : t ( 'errorString' ) ,
138
+ status : 'error' ,
166
139
isClosable : true ,
167
140
} ) ;
168
141
setTokenID ( '' ) ;
169
142
return ;
170
143
}
171
- // If we leave the try/catch, we aren't sending a tx anymore, so we clear
172
- // this part of the state.
144
+
173
145
toast ( {
174
146
title : t ( 'TokenMintMessage' ) ,
175
147
description : t ( 'NFTMintSuccess' ) ,
176
- status : t ( 'successString' ) ,
148
+ status : 'success' ,
177
149
isClosable : true ,
178
150
} ) ;
179
151
setTokenID ( '' ) ;
@@ -182,7 +154,13 @@ const DirectMint = ({ developerId }: DirectMintProps) => {
182
154
return (
183
155
< >
184
156
{ ! userWallet && (
185
- < Button w = "100%" colorScheme = "blue" onClick = { connectWallet } mt = "10" >
157
+ < Button
158
+ w = "100%"
159
+ colorScheme = "blue"
160
+ onClick = { connectWallet }
161
+ mt = "10"
162
+ fontSize = { { base : 's' , sm : 'xl' } }
163
+ >
186
164
{ t ( 'connectWalletText' ) }
187
165
</ Button >
188
166
) }
@@ -204,6 +182,7 @@ const DirectMint = ({ developerId }: DirectMintProps) => {
204
182
onClick = { createTokenHandler }
205
183
disabled = { ! userWallet || networkError }
206
184
mt = "10"
185
+ fontSize = { { base : 's' , sm : 'xl' } }
207
186
>
208
187
{ t ( 'mintTokenText' ) }
209
188
</ Button >
0 commit comments