-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterface
More file actions
373 lines (346 loc) · 11.3 KB
/
interface
File metadata and controls
373 lines (346 loc) · 11.3 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
import { useCallback, useEffect, useState } from "react";
import {
Connection,
PublicKey,
} from "@solana/web3.js";
import {
Metaplex,
walletAdapterIdentity,
} from "@metaplex-foundation/js";
import styled from "styled-components";
import "./globals.css";
import { Container, } from "@mui/material";
import Button from "@mui/material/Button";
import Paper from "@mui/material/Paper";
import Grid from "@mui/material/Grid";
import Typography from "@mui/material/Typography";
import { WalletAdapterNetwork } from "@solana/wallet-adapter-base";
import { SolanaMobileWalletAdapterWalletName } from "@solana-mobile/wallet-adapter-mobile";
import { useAnchorWallet, useWallet } from "@solana/wallet-adapter-react";
import { WalletDialogButton } from "@solana/wallet-adapter-material-ui";
import { CrossmintPayButton } from "@crossmint/client-sdk-react-ui";
import { CandyMachineState, getCandyMachineState, payMint, allowMint, NFT, merkle } from "./candy-machine";
const ConnectButton = styled(WalletDialogButton)`
width: 100%;
height: 60px;
margin-top: 10px;
margin-bottom: 5px;
background-color: #2e363c !important;
border: 2px solid #ffd839;
border-color: #ffd839 !important;
color: #ffd839 !important;
font-size: 1em !important;
font-family: "Press+Start+2P" normal;
font-weight: normal;
`;
export const MintButton = styled(Button)`
width: 100%;
height: 60px;
margin-top: 10px;
margin-bottom: 5px;
background-color: #2e363c !important;
border: 2px solid #ffd839;
color: #ffff !important;
font-size: 1em !important;
font-family: "Press Start 2P" normal;
font-weight: normal;
`;
export const AmountButton = styled(Button)`
width: 15%;
height: 30px;
margin-top: 10px;
margin-bottom: 5px;
background-color: #2e363c !important;
border: 2px solid #ffd839;
color: #ffff !important;
font-size: 1em !important;
font-family: "Press Start 2P" normal;
font-weight: normal;
`;
export interface HomeProps {
candyMachineId: string;
connection: Connection;
txTimeout: number;
rpcHost: string;
network: WalletAdapterNetwork;
error: string | undefined;
}
const Home = (props: HomeProps) => {
const anchorWallet = useAnchorWallet();
const { connect, connected, publicKey, wallet } = useWallet();
const [candyMachine, setCandyMachine] = useState<CandyMachineState>();
const [nft, setNft] = useState<NFT>();
const [isUserMinting, setIsUserMinting] = useState(false);
const [error, setError] = useState("");
const [mintAmount, setMintAmount] = useState(1);
const metaplex = new Metaplex(props.connection);
const handleDecrement = () => {
if (mintAmount <= 1) return;
setMintAmount(mintAmount - 1);
};
const handleIncrement = () => {
if (mintAmount >= 5) return;
setMintAmount(mintAmount + 1);
};
const refreshCandyMachineState = useCallback(
async () => {
if (!publicKey) {
return;
}
const candyMachine = await getCandyMachineState(metaplex, new PublicKey(props.candyMachineId));
setCandyMachine(candyMachine);
},
[anchorWallet, props.candyMachineId, props.rpcHost]
);
const getPayMintButtonContent = () => {
if (!candyMachine) {
return "Loading...";
}
if (isUserMinting) {
return "Minting in progress..";
} else if (candyMachine.itemsRemaining === 0) {
return "Sold out";
} else {
return "USDC";
}
};
const payMintButtonClicked = async () => {
setIsUserMinting(true);
metaplex.use(walletAdapterIdentity(wallet!.adapter));
const nft = await payMint(metaplex, candyMachine!);
if (nft) {
setNft(nft);
} else {
setError("Wait for it!!!");
}
setIsUserMinting(false);
refreshCandyMachineState();
}
useEffect(() => {
refreshCandyMachineState();
}, [
anchorWallet,
props.candyMachineId,
props.connection,
refreshCandyMachineState,
]);
useEffect(() => {
(function loop() {
setTimeout(() => {
refreshCandyMachineState();
loop();
}, 20000);
})();
}, [refreshCandyMachineState]);
const TitanDogImage = styled("img")`
width: 100%;
height: 100%;
object-fit: cover;
object-position: top;
margin-bottom: 30px;
border-radius: 10%;
border: 3px solid #ffd839;
border-color: #ffd839 !important;
`
return (
<Container style={{ marginTop: -20 }}>
<Container maxWidth="xs" style={{ position: 'relative' }}>
<TitanDogImage src="https://bafybeiazpv2pdgpvvihsgomigo4uaoasrhq4ixhrvqzovf524vggxv53va.ipfs.nftstorage.link/collection.gif" alt="SaibaKongJR" />
<Paper
style={{ padding: 24, background: '#3a434a', borderColor: '#ffd839', border: '3px solid #ffd839', borderRadius: 6 }}
>
{error || props.error ? (
<Typography
variant="h6"
color="textPrimary"
style={{
fontWeight: "bold",
textAlign: "center",
}}
>
{error || props.error}
</Typography>
) : undefined}
{!connected ? (
<ConnectButton
onClick={(e) => {
if (
wallet?.adapter.name === SolanaMobileWalletAdapterWalletName
) {
connect();
e.preventDefault();
}
}}
>
<Typography variant="body2" color="textSecondary" style={{
fontSize: "16px",
fontWeight: "bold",
color: "white",
textAlign: "center",
}}>
Connect Wallet
</Typography>
</ConnectButton>
) : (
<>
<Grid
container
direction="row"
justifyContent="center"
wrap="nowrap"
>
<Grid item xs={3}>
<Typography variant="body2" color="#ffd839" style={{
textAlign: "center", fontFamily: "Press Start 2P"
}}>
Remaining
</Typography>
<Typography
variant="h6"
color="textPrimary"
style={{
fontWeight: "bold",
textAlign: "center",
}}
>
{`${candyMachine ? candyMachine.itemsRemaining : "Loading.."}`}
</Typography>
</Grid>
<Grid item xs={4}>
<Typography
variant="body2"
color="#ffd839"
style={{ fontFamily: "Press Start 2p" }}
>
Price USDC
</Typography>
<Typography
variant="h6"
color="textPrimary"
style={{ fontFamily: "Press Start 2P" }}
>
100
</Typography>
</Grid>
<Grid item xs={4}>
<Typography
variant="h6"
color="#ffd839"
style={{ fontFamily: "Press Start 2P" }}
>
INTERLINKED
</Typography>
</Grid>
</Grid>
<Grid
container
direction="row"
justifyContent="center"
wrap="nowrap"
>
<MintButton onClick={async () => await payMintButtonClicked()} disabled={isUserMinting || candyMachine?.itemsRemaining === 0}>
<Typography variant="body2" color="textSecondary" style={{
fontSize: "16px",
fontWeight: "bold",
color: "white",
textAlign: "center",
}}>
{ getPayMintButtonContent() }
</Typography>
</MintButton>
</Grid>
<Grid item xs={3}>
<Typography variant="body2" color="#ffd839" style={{
textAlign: "center", fontFamily: "Press Start 2P"
}}>
For future use... maybe.
</Typography>
</Grid>
<Grid
container
direction="row"
justifyContent="center"
wrap="nowrap"
>
</Grid>
</>
)}
<Grid
container
direction="row"
justifyContent="center"
wrap="nowrap"
>
</Grid>
<Grid item xs={3}>
<Typography variant="body2" color="#ffd839" style={{
textAlign: "center", fontFamily: "Press Start 2P"
}}>
Mint up to 5 per transaction using Crossmint.
</Typography>
</Grid>
<Grid
container
direction="row"
justifyContent="center"
wrap="nowrap"
>
<AmountButton onClick={handleDecrement}>
<Typography variant="body2" color="textSecondary" style={{
fontSize: "8px",
fontWeight: "bold",
color: "white",
textAlign: "center",
}}>
D
</Typography>
</AmountButton>
<input
readOnly
type="number"
value={mintAmount}
/>
<AmountButton onClick={handleIncrement}>
<Typography variant="body2" color="textSecondary" style={{
fontSize: "8px",
fontWeight: "bold",
color: "white",
textAlign: "center",
}}>
U
</Typography>
</AmountButton>
</Grid>
<CrossmintPayButton
paymentMethod="fiat"
clientId="812cca81-db82-40cd-be64-cd62daacf27b"
mintConfig={{"type":"candy-machine",
"mintingGroup":"pay",
"quantity": mintAmount}}
environment="production"
className="my-custom-crossmint-button"
/>
<CrossmintPayButton
paymentMethod="ETH"
clientId="812cca81-db82-40cd-be64-cd62daacf27b"
mintConfig={{"type":"candy-machine",
"mintingGroup":"pay",
"quantity": mintAmount}}
environment="production"
className="my-custom-crossmint-button"
/>
<CrossmintPayButton
paymentMethod="SOL"
clientId="812cca81-db82-40cd-be64-cd62daacf27b"
mintConfig={{"type":"candy-machine",
"mintingGroup":"pay",
"quantity": mintAmount}}
environment="production"
className="my-custom-crossmint-button"
/>
</Paper>
</Container>
</Container>
);
};
export default Home;