forked from factoria-org/skinnerbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mint.html
111 lines (111 loc) · 3.92 KB
/
mint.html
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
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.7.7/handlebars.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/js/nice-select2.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta2/css/all.min.css" rel="stylesheet">
<link href="https://unpkg.com/[email protected]/dist/css/nice-select2.css" rel="stylesheet">
<link href="style.css" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/web3/1.7.0-rc.0/web3.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/f0.js"></script>
<script id="template" type="text/x-handlebars-template">
<img src="{{image}}">
<h1><a href=".">{{title}}</a></h1>
<div class='label'>{{price}}</div>
<div class='label'>{{current}}/{{supply}}</div>
<div class='minter'>
<select id='count'>
<option value="" selected disabled hidden>Select mint count</option>
{{#each items}}
<option value={{count}}>{{count}}</option>
{{/each}}
</select>
<button id='mint'>Mint</button>
</div>
<div class='console'></div>
<div class='loading hidden'>
<i class="fa-solid fa-chevron-up fa-flip"></i> minting...
</div>
</script>
<script id="mint-template" type="text/x-handlebars-template">
<table class='table'>
<tr>
<th><img src="opensea.png"></th>
<th><img src="rarible.png"></th>
</tr>
{{#each items}}
<tr>
<td><a class='token' target="_blank" href="{{opensea}}">token #{{tokenId}}</a></td>
<td><a class='token' target="_blank" href="{{rarible}}">token #{{tokenId}}</a></td>
</tr>
{{/each}}
</table>
</script>
<script>
const f0 = new F0()
const { key, address } = f0.parseURL(location.href)
const template = Handlebars.compile(document.querySelector("#template").innerHTML);
const mintTemplate = Handlebars.compile(document.querySelector("#mint-template").innerHTML);
document.addEventListener("DOMContentLoaded", async () => {
await window.ethereum.send('eth_requestAccounts');
let c = await fetch("box.json").then((r) => {
return r.json()
})
try {
await f0.init({
web3: new Web3(window.ethereum),
contract: address,
network: c.network
})
let invite = await f0.invite(key)
let placeholder = await f0.placeholder()
const name = await f0.name()
const symbol = await f0.symbol()
const nextId = await f0.nextId()
const config = await f0.config()
let items = []
for(let i=1; i<=invite.condition.converted.limit; i++) {
items.push(i)
}
document.querySelector(".box").innerHTML = template({
image: placeholder.converted.image,
title: `${name} (${symbol})`,
items: items.map((item) => { return { count: item } }),
max: invite.condition.converted.limit,
price: `${invite.condition.converted.eth} ETH`,
current: nextId,
supply: config.converted.supply,
account: f0.account,
key: key,
})
NiceSelect.bind(document.querySelector("select"))
document.querySelector("#mint").addEventListener("click", async (e) => {
document.querySelector(".minter").classList.add("hidden")
document.querySelector(".loading").classList.remove("hidden")
let count = parseInt(document.querySelector("#count").value)
if (count === 0) {
alert("Please enter a number greater than 0")
} else {
let tokens = await f0.mint(key, count)
document.querySelector(".loading").classList.add("hidden")
document.querySelector(".console").innerHTML = mintTemplate({
items: tokens.map((token) => {
return {
opensea: token.links.opensea,
rarible: token.links.rarible,
tokenId: token.tokenId
}
})
})
}
})
} catch (e) {
document.querySelector(".box").innerHTML = `<h1>${e.message.toLowerCase()}</h1>`
}
})
</script>
</head>
<body>
<div class='box'></div>
</body>
</html>