-
Notifications
You must be signed in to change notification settings - Fork 281
/
index.js
321 lines (298 loc) · 8.74 KB
/
index.js
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
/* eslint-disable react-hooks/exhaustive-deps */
import React, { useContext, useEffect, useState } from 'react'
import { useParams } from 'react-router-dom'
import { HicetnuncContext } from '../../context/HicetnuncContext'
import { getWalletBlockList } from '../../constants'
import { Loading } from '../../components/loading'
import { Button, Primary } from '../../components/button'
import { Page, Container, Padding } from '../../components/layout'
import { renderMediaType } from '../../components/media-types'
import { ItemInfo } from '../../components/item-info'
import { Menu } from '../../components/menu'
import { BottomBanner } from '../../components/bottom-banner'
import { Info, Collectors, Swap, Burn, History } from './tabs'
import styles from './styles.module.scss'
import './style.css'
const axios = require('axios')
const TABS = [
{ title: 'info', component: Info }, // public tab
{ title: 'listings', component: Collectors }, // public tab
{ title: 'history', component: History },
{ title: 'swap', component: Swap, private: true, restricted: true }, // private tab (users only see if they are the creators or own a copy)
{ title: 'burn', component: Burn, private: true }, // private tab (users only see if they are the creators or own a copy)
]
const query_objkt = `
query objkt($id: bigint!) {
hic_et_nunc_token_by_pk(id: $id) {
id
mime
timestamp
display_uri
description
artifact_uri
metadata
creator {
address
name
}
thumbnail_uri
title
supply
royalties
swaps {
amount
amount_left
id
price
timestamp
creator {
address
name
}
contract_version
status
royalties
creator_id
is_valid
}
token_holders(where: {quantity: {_gt: "0"}}) {
holder_id
quantity
holder {
name
}
}
token_tags {
tag {
tag
}
}
trades(order_by: {timestamp: asc}) {
amount
swap {
price
}
seller {
address
name
}
buyer {
address
name
}
timestamp
}
}
}
`
async function fetchObjkt(id) {
const { errors, data } = await fetchGraphQL(query_objkt, 'objkt', {
id: id
})
if (errors) {
console.error(errors)
}
const result = data.hic_et_nunc_token_by_pk
console.log(result)
return result
}
async function fetchGraphQL(operationsDoc, operationName, variables) {
let result = await fetch(process.env.REACT_APP_GRAPHQL_API, {
method: 'POST',
body: JSON.stringify({
query: operationsDoc,
variables: variables,
operationName: operationName,
}),
})
return await result.json()
}
export const ObjktDisplay = () => {
const { id } = useParams()
const context = useContext(HicetnuncContext)
const [loading, setLoading] = useState(true)
const [tabIndex, setTabIndex] = useState(0)
const [nft, setNFT] = useState()
const [error, setError] = useState(false)
const [restricted, setRestricted] = useState(false)
const [ban, setBans] = useState([])
const address = context.acc?.address
const proxy = context.getProxy()
const getRestrictedAddresses = async () =>
await axios
.get(
'https://raw.githubusercontent.com/hicetnunc2000/hicetnunc-reports/main/filters/w.json'
)
.then((res) => res.data)
useEffect(async () => {
let objkt = await fetchObjkt(id)
await context.setAccount()
if (getWalletBlockList().includes(objkt.creator.address)) {
setRestricted(true)
objkt.restricted = true
setNFT(objkt)
} else {
objkt.ban = await getRestrictedAddresses()
objkt.restricted = false
setNFT(objkt)
}
setLoading(false)
/* GetOBJKT({ id })
.then(async (objkt) => {
if (Array.isArray(objkt)) {
setError(
"There's a problem loading this OBJKT. Please report it on Github."
)
setLoading(false)
} else {
await context.setAccount()
setNFT(objkt)
setLoading(false)
}
})
.catch((e) => {
if (e.response && e.response.data.error) {
setError(
`(http ${e.response.data.error.http_status}) ${e.response.data.error.message}`
)
} else if (e.response && e.response.data) {
setError(`(http ${e.response.status}) ${e.response.data}`)
} else if (e.request) {
setError(
`There's a problem loading this OBJKT. Please report it on Github. ${e.message}`
)
} else {
setError(
`There's a problem loading this OBJKT. Please report it on Github. ${e}`
)
}
setLoading(false)
}) */
}, [])
const Tab = TABS[tabIndex].component
return (
<Page title={nft?.title}>
{loading && (
<Container>
<Padding>
<Loading />
</Padding>
</Container>
)}
{error && (
<Container>
<Padding>
<p>{error}</p>
</Padding>
<Padding>
<Button href="https://github.com/hicetnunc2000/hicetnunc/issues">
<Primary>
<strong>Report</strong>
</Primary>
</Button>
</Padding>
</Container>
)}
{!loading && (
!context.progress ?
<>
<Container>
<Padding>
{restricted && (
<div style={{ color: 'white', background: 'black', textAlign: 'center' }}>
restricted OBJKT
</div>
)}
</Padding>
</Container>
<div
style={{
position: 'relative',
display: 'block',
width: '100%'
}}
className="objkt-display">
<div className={
nft.mime == 'application/x-directory' || nft.mime == 'image/svg+xml' ? 'objktview-zipembed objktview ' + styles.objktview :
[(
nft.mime == 'video/mp4' ||
nft.mime == 'video/ogv' ||
nft.mime == 'video/quicktime' ||
nft.mime == 'video/webm' ||
nft.mime == 'application/pdf' ? 'no-fullscreen' : 'objktview ' + styles.objktview
)]
}>
{renderMediaType({
mimeType: nft.mime,
artifactUri: nft.artifact_uri,
displayUri: nft.display_uri,
creator: nft.creator,
objkt: nft.id,
interactive: true,
displayView: false
})}
</div>
<div>
<Container>
<Padding>
<ItemInfo {...nft} isDetailView />
</Padding>
</Container>
<Container>
<Padding>
<Menu>
{TABS.map((tab, index) => {
// if nft.owners exist and this is a private route, try to hide the tab.
// if nft.owners fails, always show route!
if (nft?.restricted && tab.restricted) {
return null
}
if (nft?.token_holders && tab.private) {
let holders_arr = nft.token_holders.map(
(e) => e.holder_id
)
if (
holders_arr.includes(address) === false &&
nft.creator.address !== address &&
nft.creator.address !== proxy
) {
// user is not the creator now owns a copy of the object. hide
return null
}
}
return (
<Button
key={tab.title}
onClick={() => setTabIndex(index)}
>
<Primary selected={tabIndex === index}>
{tab.title}
</Primary>
</Button>
)
})}
</Menu>
</Padding>
</Container>
<Tab {...nft} address={address} />
</div>
</div>
</>
:
<Container>
<Padding>
<div>
<p style={{
position: 'absolute',
left: '46%',
top: '45%',
}}>{context.message}</p>
{context.progress && <Loading />}
</div>
</Padding>
</Container>
)}
<div style={{ height: '40px' }}></div>
</Page>
)
}