-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcollection_templates.html
More file actions
145 lines (124 loc) · 6.31 KB
/
Copy pathcollection_templates.html
File metadata and controls
145 lines (124 loc) · 6.31 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
<!-- Example Template to showcase how you could load NFT Templates on your website -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous"> <style>
.my-card {
background-color: rgba(245, 245, 245, 0.7);
margin-bottom: 1rem;
}
</style>
<div class="container mt-4 mb-4">
<div class="row mb-2 justify-content-center">
<!-- Dropdown for Hyperion API Endpoint -->
<div class="col-md-6 text-center text-md-start mb-2 mb-md-0">
<select id="rpcSelector" class="form-select">
<!-- Options will be populated by JavaScript -->
</select>
</div>
<!-- Form for Selecting NFT Collection -->
<div class="col-md-6 text-center text-md-start">
<form id="collectionForm" class="d-flex justify-content-center justify-content-md-start">
<input id="collectionInput" type="text" class="form-control" pattern="[a-z1-5.]{1,12}" placeholder="Enter collection" required>
<button type="submit" class="btn btn-primary ml-2">Update</button>
</form>
</div>
</div>
</div>
<div class="container">
<div class="row justify-content-center" id="cardContainer">
<!-- NFT Templates will show up here -->
</div>
</div>
<script>
// You can edit the default Atomic API Endpoint
let RpcEndpoint = "https://wax-atomic-api.eosphere.io"
// You can edit the default NFT Collection
let Collection = "anyo.b1"
// You can edit the default number of templates to load, 1-100
let NumTemplates = 6
// You can edit the default IPFS endpoint to fetch IPFS data from.
// Don't use the NFThive IPFS api if you expect a lot of traffic.
// It's not designed to be used for third party products
const IpfsEndpoint = "https://ipfs.hivebp.io/ipfs/"
// You can edit this list of Hyperion APIs if you want
const endpoints = {
"https://wax-atomic-api.eosphere.io": "wax-atomic-api.eosphere.io",
"https://wax-aa.eu.eosamsterdam.net": "wax-aa.eu.eosamsterdam.net",
"https://atomic-wax.tacocrypto.io": "atomic-wax.tacocrypto.io",
"https://atomic.hivebp.io": "atomic.hivebp.io"
};
async function fetchData(RpcEndpoint, Collection, num_templates) {
try {
const response = await fetch(RpcEndpoint + "/atomicassets/v1/templates?collection_name="+ Collection +"&page=1&limit="+ NumTemplates + "&order=desc&sort=created");
const data = await response.json();
createCards(data.data);
} catch (error) {
console.error("Error fetching data:", error);
}
}
function createCards(items) {
const container = document.getElementById("cardContainer");
container.innerHTML = '';
items.forEach(item => {
const card = document.createElement('div');
card.className = 'col-md-4 d-flex justify-content-center';
let media = item.immutable_data.img;
if (item.immutable_data.video) {
media = item.immutable_data.video;
}
// Check if the media is an IPFS hash
if (media.startsWith('Qm') && media.length === 46) {
media = IpfsEndpoint + media;
}
const content = `
<div class="card my-card mb-4">
<div class="card-header d-flex justify-content-between">
<div id="template_id" data-bs-toggle="tooltip" data-bs-placement="top" title="The Template ID">#${item.template_id}</div>
<div id="issued_supply" data-bs-toggle="tooltip" data-bs-placement="top" title="Number of Issued NFTs in this Template">${item.issued_supply}</div>
</div>
<div class="card-body text-center">
<img src="${media}" class="img-fluid" style="max-height: 200px; object-fit: contain;" alt="${item.immutable_data.name}">
</div>
<div class="card-footer">
<div id="template_name" data-bs-toggle="tooltip" data-bs-placement="top" title="The Template Name">
<strong>${item.immutable_data.name || ''}</strong>
</div>
<div>${item.immutable_data.description || ''}</div>
<div class="d-flex justify-content-between">
<div id="schema_name" data-bs-toggle="tooltip" data-bs-placement="top" title="The Template Schema Name">${item.schema.schema_name || ''}</div>
<div id="created_at" data-bs-toggle="tooltip" data-bs-placement="top" title="The Date The Template was Created">${new Date(parseInt(item.schema.created_at_time)).toLocaleDateString()}</div>
</div>
</div>
</div>
`;
card.innerHTML = content;
container.appendChild(card);
});
}
document.addEventListener("DOMContentLoaded", function(){
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
return new bootstrap.Tooltip(tooltipTriggerEl);
});
});
document.addEventListener("DOMContentLoaded", function () {
document.getElementById('rpcSelector').addEventListener('change', function () {
RpcEndpoint = this.value;
fetchData(RpcEndpoint, Collection, NumTemplates);
});
document.getElementById('collectionForm').addEventListener('submit', function (e) {
e.preventDefault();
Collection = document.getElementById('collectionInput').value;
fetchData(RpcEndpoint, Collection, NumTemplates);
});
});
function UpdateDropdown() {
const dropdown = document.getElementById('rpcSelector');
dropdown.innerHTML = '';
for (const [key, value] of Object.entries(endpoints)) {
const option = document.createElement('option');
option.value = key;
option.text = value;
dropdown.appendChild(option);
}};
UpdateDropdown();
fetchData(RpcEndpoint, Collection, NumTemplates);
</script>