forked from m0-foundation/ttg-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.vue
144 lines (120 loc) · 3.58 KB
/
app.vue
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
<template>
<div>
<Head>
<Title>M^0 | Governance</Title>
<Meta charset="utf-8"></Meta>
<Meta content="width=device-width, initial-scale=1" name="viewport" />
<Meta content="/open-graph.jpg" property="og:image" />
<Meta content="/favicon.jpg" property="twitter:image" />
<Link href="/favicon.png" rel="shortcut icon" type="image/x-icon" />
<link
rel="manifest"
href="/manifest.json"
crossorigin="use-credentials"
/>
</Head>
<div v-if="isLoading" class="flex h-dvh">
<div class="m-auto inline-flex">
<div>Loading</div>
<div class="loader-dots"></div>
</div>
</div>
<NuxtLayout v-else />
</div>
</template>
<script lang="ts" setup>
import { UseWagmiPlugin } from "use-wagmi";
import { VueQueryPlugin } from "@tanstack/vue-query";
import { storeToRefs } from "pinia";
import { wait } from "@/utils/misc";
import { Api } from "@/lib/api";
import { watchForExecutedResetProposal } from "@/lib/watchers";
const nuxtApp = useNuxtApp();
const network = useNetworkStore().getNetwork();
const apiStore = useApiClientStore();
const ttg = useTtgStore();
const proposalStore = useProposalsStore();
const votes = useVotesStore();
const { rpc } = storeToRefs(apiStore);
const isLoading = ref(true);
async function onSetup(rpc: string) {
console.log("onSetup with rpc", rpc);
/* setup wagmi client as vue plugin */
const fallbackRpc = network.value.rpc.values![1];
const wagmiConfig = useWagmi(rpc, fallbackRpc);
nuxtApp.vueApp.use(UseWagmiPlugin, { config: wagmiConfig });
nuxtApp.vueApp.use(VueQueryPlugin);
/* setup ttg client */
const api = new Api({
rpcUrl: rpc,
fallbackRpcUrl: fallbackRpc,
config: {
registrar: network.value.contracts.registrar,
multicall3: network.value.contracts.multicall3,
deploymentBlock: BigInt(network.value.contracts.deploymentBlock),
},
});
const registrarValues = await api.registrar.getValues();
ttg.setRegistrarValues(registrarValues);
api.epoch.setEpoch(
registrarValues.clockStartingTimestamp,
registrarValues.clockPeriod,
);
api.setGovernors({
standardGovernor: registrarValues.standardGovernor,
zeroGovernor: registrarValues.zeroGovernor,
emergencyGovernor: registrarValues.emergencyGovernor,
});
apiStore.setClient(api);
return api;
}
const trackError = (error: Error, label: string) =>
console.error(label, { error });
onMounted(async () => {
if (rpc.value) {
await onSetup(rpc.value!);
// this must go first
await ttg
.fetchGovernorsValues()
.catch((e) => trackError(e, "fetchGovernorsValues"));
await ttg.fetchTokens().catch((e) => trackError(e, "fetchTokens"));
await wait(200);
await proposalStore
.fetchAllProposals()
.catch((e) => trackError(e, "fetchAllProposals"));
await wait(200);
await votes.fetchAllVotes().catch((e) => trackError(e, "fetchAllVotes"));
await ttg
.fetchEpoch(ttg.values.clock!)
.catch((e) => trackError(e, "fetchEpoch"));
watchForExecutedResetProposal();
}
isLoading.value = false;
});
/* user has updated the rpc */
watch(
rpc,
(newRpc) => {
console.log("rpc has changed", { newRpc });
onSetup(newRpc!);
},
{ deep: true },
);
</script>
<style>
.loader-dots {
width: 18px;
aspect-ratio: 4;
background: radial-gradient(circle closest-side, #fff 90%, #0000) 0 /
calc(100% / 3) 100% space;
clip-path: inset(0 100% 0 0);
animation: l1 1s steps(4) infinite;
margin-top: 10px;
margin-left: 2px;
}
@keyframes l1 {
to {
clip-path: inset(0 -34% 0 0);
}
}
</style>