This repository has been archived by the owner on Oct 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Dashboard.js
111 lines (101 loc) · 2.59 KB
/
Dashboard.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
import React, { useState, useContext, useEffect } from "react";
import Router, { useRouter } from "next/router";
import AppContext from "../../context/AppContext";
import Link from "next/link";
import {
Flex,
Heading,
Text,
Icon,
HStack,
UnorderedList,
ListItem,
Grid,
Box,
Divider,
} from "@chakra-ui/react";
import FlexGradient from "../elements/FlexGradient.js";
import Reload from "../elements/Reload.js";
import { convertVotingPeriod, fromDecimals } from "../../utils/formatters";
import { fetchDaoInfo } from "../../utils/fetchDaoInfo";
import { addresses } from "../../constants/addresses";
import { factoryInstance } from "../../eth/factory";
import { dashboardHelper } from "../../constants/dashboardHelper";
import { correctNetwork } from "../../utils/network";
const proposalTypes = require("../../constants/params");
export default function Dashboard() {
const value = useContext(AppContext);
const {
web3,
loading,
account,
abi,
chainId,
visibleView,
dao,
address,
daoChain,
} = value.state;
const reloadDao = async () => {
fetchData();
};
useEffect(() => {
if (!dao) {
fetchData();
}
}, [chainId]);
async function fetchData() {
value.setLoading(true);
try {
const instance = new web3.eth.Contract(abi, address);
const factory = factoryInstance(addresses[daoChain]["factory"], web3);
const { dao_ } = await fetchDaoInfo(
instance,
factory,
address,
web3,
daoChain,
account
);
value.setDao(dao_);
console.log(dao_);
value.setLoading(false);
} catch (e) {
value.toast(e);
value.setLoading(false);
}
}
return (
<div id="dashboard">
<Reload reload={reloadDao} />
<Grid
gap={5}
templateColumns={{
sm: "repeat(1, 1fr)",
md: "repeat(1, 1fr)",
lg: "repeat(2, 1fr)",
}}
>
{dao == null || web3 == undefined ? (
"Loading . . ."
) : (
<>
{Object.entries(dashboardHelper).map(([k, v]) =>
dashboardHelper[k]["check"] != null &&
dao[dashboardHelper[k]["check"]] == null ? null : (
<div className="gradient-item dashboard-tile">
<Box
key={`component-${k}`}
>
<Heading>{dashboardHelper[k]["title"]}</Heading>
{dashboardHelper[k]["component"]}
</Box>
</div>
)
)}
</>
)}
</Grid>
</div>
);
}