Skip to content
This repository was archived by the owner on Dec 26, 2023. It is now read-only.

Commit cfeca71

Browse files
BrianBrian
authored andcommitted
Code cleanup
Removed comments from code Added some static text to translations Moved Token Search website to constants. Moved Infura ID to env variable Added responsiveness to Mint Page Resize buttons and Text based on screen width Highlighted link Highlighted Link to Token Search Page Generic Human Readable Message Added generic error message for failed transaction.
1 parent abf10d6 commit cfeca71

File tree

6 files changed

+39
-52
lines changed

6 files changed

+39
-52
lines changed

frontend/public/locales/en/common.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,23 @@
2323
"copyLinkToNFT": "Copy link to NFT",
2424
"linkCopied": "Link copied to clipboard",
2525
"tokenUnavailable": "Token ID may not be available",
26-
"errorString": "error",
27-
"successString" : "success",
2826
"NFTMintSuccess": "Your NFT should now be in your wallet!",
2927
"TokenMintMessage": "Token Minted",
3028
"tokenIDPlaceholder": "Enter Token ID",
3129
"mintTokenText" : "Mint your Token",
3230
"connectWalletText": "Connect Wallet",
3331
"ethereumNetworkPrompt": "Please Connect to the Ethereum Network",
3432
"availableTokensText": "View the available Token IDs",
35-
"mintPageHeader": "DDAO Token Minter",
33+
"mintPageHeader": "DEVS Token Minter",
3634
"projectsList": "A list of community projects created by the Developer DAO community.",
3735
"ddaoTokenSearch": "DDAO Token Search",
3836
"ddaoUnofficalFrontend": "Developer DAO Unofficial Frontend",
3937
"ddaoTokenVisualizer": "Developer DAO Token Visualizer",
4038
"by": "by",
4139
"otherTokensOwnedByThisAddress":"Other Tokens owned by this address",
4240
"noOtherTokens":"No other tokens owned by this address",
43-
"userCancelTransaction": "Transaction Cancelled by User"
41+
"userCancelTransaction": "Transaction Cancelled by User",
42+
"transactionSending": "Transaction Being Sent",
43+
"here": "here",
44+
"errorMinting": "Unable to Mint NFT"
4445
}

frontend/src/components/DirectMint/DirectMint.tsx

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
DEVELOPER_DAO_CONTRACT,
1414
ERROR_CODE_TX_REJECTED_BY_USER,
1515
MAINNET_NETWORK_ID,
16-
INFURA_ID,
1716
} from '../../utils/DeveloperDaoConstants';
1817

1918
import MINT_CONTRACT from '../../artifacts/ddao.json';
@@ -27,15 +26,13 @@ interface DirectMintProps {
2726

2827
const providerOptions = {
2928
walletconnect: {
30-
package: WalletConnectProvider, // required
29+
package: WalletConnectProvider,
3130
options: {
32-
infuraId: INFURA_ID, // required
31+
infuraId: process.env.INFURA_ID,
3332
},
3433
},
3534
};
3635

37-
// Logic & buttons needed for Direct Minting
38-
// Can be reused anywhere else as needed
3936
const DirectMint = ({ developerId }: DirectMintProps) => {
4037
const { t } = useTranslation();
4138
const [userWallet, setUserWallet] = useState('');
@@ -47,9 +44,9 @@ const DirectMint = ({ developerId }: DirectMintProps) => {
4744

4845
useEffect(() => {
4946
const web3Modal = new Web3Modal({
50-
network: 'mainnet', // optional
51-
cacheProvider: false, // optional
52-
providerOptions, // required
47+
network: 'mainnet',
48+
cacheProvider: false,
49+
providerOptions,
5350
});
5451
setWeb3Modal(web3Modal);
5552
}, []);
@@ -66,7 +63,6 @@ const DirectMint = ({ developerId }: DirectMintProps) => {
6663
const accounts = await _web3.listAccounts();
6764
const { chainId } = await _web3.getNetwork();
6865

69-
// MetaMask does not give you all accounts, only the selected account
7066
const selectedAccount = accounts[0];
7167

7268
setUserWallet(selectedAccount);
@@ -90,17 +86,14 @@ const DirectMint = ({ developerId }: DirectMintProps) => {
9086
return;
9187
}
9288

93-
// Subscribe to accounts change
9489
_provider.on('accountsChanged', (accounts: string) => {
9590
fetchAccountData();
9691
});
9792

98-
// Subscribe to chainId change
9993
_provider.on('chainChanged', (chainId: string) => {
10094
fetchAccountData();
10195
});
10296

103-
// Subscribe to networkId change
10497
_provider.on('networkChanged', (networkId: string) => {
10598
setNetworkError(false);
10699
fetchAccountData();
@@ -117,63 +110,42 @@ const DirectMint = ({ developerId }: DirectMintProps) => {
117110
event,
118111
) => {
119112
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.
126113
const tx = await mint_contract.claim(tokenID);
127114

128-
//Alert transaction is in progress
129115
toast({
130-
title: 'Transaction Being Sent',
116+
title: t('transactionSending'),
131117
isClosable: true,
132118
});
133119

134-
// We use .wait() to wait for the transaction to be mined. This method
135-
// returns the transaction's receipt.
136120
const receipt = await tx.wait();
137121

138-
// The receipt, contains a status flag, which is 0 to indicate an error.
139122
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.
142123
throw new Error('Transaction failed');
143124
}
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.
147125
} 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.
150126
if (error.code === ERROR_CODE_TX_REJECTED_BY_USER) {
151-
// resetFields();
152127
toast({
153128
title: t('userCancelTransaction'),
154129
status: 'error',
155130
isClosable: true,
156131
});
157132
return;
158133
}
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+
162135
toast({
163-
title: error.code,
136+
title: t('errorMinting'),
164137
description: t('tokenUnavailable'),
165-
status: t('errorString'),
138+
status: 'error',
166139
isClosable: true,
167140
});
168141
setTokenID('');
169142
return;
170143
}
171-
// If we leave the try/catch, we aren't sending a tx anymore, so we clear
172-
// this part of the state.
144+
173145
toast({
174146
title: t('TokenMintMessage'),
175147
description: t('NFTMintSuccess'),
176-
status: t('successString'),
148+
status: 'success',
177149
isClosable: true,
178150
});
179151
setTokenID('');
@@ -182,7 +154,13 @@ const DirectMint = ({ developerId }: DirectMintProps) => {
182154
return (
183155
<>
184156
{!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+
>
186164
{t('connectWalletText')}
187165
</Button>
188166
)}
@@ -204,6 +182,7 @@ const DirectMint = ({ developerId }: DirectMintProps) => {
204182
onClick={createTokenHandler}
205183
disabled={!userWallet || networkError}
206184
mt="10"
185+
fontSize={{ base: 's', sm: 'xl' }}
207186
>
208187
{t('mintTokenText')}
209188
</Button>

frontend/src/components/DirectMint/DirectMintBox.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
Link,
1212
} from '@chakra-ui/react';
1313
import { useTranslation } from 'next-i18next';
14+
import { TOKEN_FINDER_URL } from '../../utils/DeveloperDaoConstants';
1415

1516
// Layout for the Direct Mint Box
1617
// used on the minting page
@@ -19,14 +20,21 @@ const DirectMintBox = () => {
1920
return (
2021
<>
2122
<Container maxW="container.md" centerContent>
22-
<Box borderWidth="4px" borderRadius="lg" w="75%" padding="20">
23+
<Box
24+
borderWidth="4px"
25+
borderRadius="lg"
26+
w={{ base: '75%', s: '90%' }}
27+
padding="20"
28+
>
2329
<Stack spacing={6} align="center">
2430
<Logo w={52} h={52} />
25-
<Heading>{t('mintPageHeader')}</Heading>
26-
<Text>
31+
<Heading fontSize={{ base: '1.25rem', sm: '2rem' }}>
32+
{t('mintPageHeader')}
33+
</Heading>
34+
<Text fontSize={{ base: 'xs', sm: 'xl' }}>
2735
{t('availableTokensText')}{' '}
28-
<Link href="https://ddao.ibby.dev" isExternal>
29-
here
36+
<Link color="#3182ce" href={TOKEN_FINDER_URL} isExternal>
37+
{t('here')}
3038
</Link>
3139
</Text>
3240
<DirectMint />

frontend/src/components/Nav/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function Nav() {
3838
{t('home')}
3939
</Link>
4040
<Link href="/mint" passHref>
41-
Mint your token
41+
{t('mintTokenText')}
4242
</Link>
4343
<Link href="/projects" passHref>
4444
{t('projects')}

frontend/src/pages/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import Logo from '../components/Logo';
2323
import PageLayout from '../layout/Page';
2424
import DevName from '../components/Search/Dev/DevName';
2525
import { useNftImageContent } from '../utils/useNftImageContent';
26-
import DirectMint from '../components/DirectMint/DirectMint';
2726
import OtherDevsByOwnerContainer from '../components/Search/OtherDevsByOwner/OtherDevsByOwner';
2827

2928
function App() {

frontend/src/utils/DeveloperDaoConstants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const ETHER_SCAN_LINK_PREFIX = 'https://etherscan.io/address';
66
export const SITE_URL = 'https://developerdao.com';
77
export const ERROR_CODE_TX_REJECTED_BY_USER = 4001;
88
export const MAINNET_NETWORK_ID = 1;
9-
export const INFURA_ID = '86ddbc7b94ff40af908eaed373ac95d6';
9+
export const TOKEN_FINDER_URL = 'http://ddao.ibby.dev';
1010

1111
export const DEVELOPER_DAO_CONTRACT_ABI = [
1212
{ inputs: [], stateMutability: 'nonpayable', type: 'constructor' },

0 commit comments

Comments
 (0)