-
Notifications
You must be signed in to change notification settings - Fork 4
/
[id].tsx
85 lines (73 loc) · 1.84 KB
/
[id].tsx
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
import { Page } from "@verto/ui";
import { CACHE_URL, isAddress } from "../../utils/arweave";
import Verto from "@verto/js";
import axios from "axios";
import Community from "../../components/space/Community";
import Collection from "../../components/space/Collection";
import Art from "../../components/space/Art";
const client = new Verto();
const Token = (props) => {
// TODO: custom layout
return (
<Page>
{(props.type === "community" && <Community {...props} />) ||
(props.type === "collection" && <Collection {...props} />) || (
<Art {...props} />
)}
</Page>
);
};
export async function getStaticPaths() {
return {
paths: [],
fallback: "blocking",
};
}
export async function getStaticProps({ params: { id } }) {
if (!isAddress(id))
return {
redirect: {
destination: "/404",
permanent: false,
},
};
const {
data: { type, id: returnedID },
} = await axios.get(`${CACHE_URL}/site/type/${id}`);
if (!type && !returnedID)
return {
redirect: {
destination: "/404",
permanent: false,
},
};
if (type === "collection") {
const { data } = await axios.get(`${CACHE_URL}/site/collection/${id}`);
return {
props: {
...data,
type: "collection",
},
revalidate: 1,
};
} else {
const {
data: { state },
} = await axios.get(`${CACHE_URL}/${id}`);
const res = await client.getPrice(id);
const { data: gecko } = await axios.get(
"https://api.coingecko.com/api/v3/simple/price?ids=arweave&vs_currencies=usd"
);
return {
props: {
id,
name: state.name,
ticker: state.ticker,
price: res ? res.price * gecko.arweave.usd : "--",
type: type || "community",
},
revalidate: 1,
};
}
}
export default Token;