-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
29 lines (26 loc) · 1002 Bytes
/
app.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
const address = document.getElementById('address');
const submit = document.getElementById('submit');
const output = document.getElementById('output');
submit.onclick = () => {
if (address.value !== '') {
const addr = address.value;
fetch('https://api.compound.finance/api/v2/governance/comp/account?address=' + addr)
.then(response => response.json())
.then((data) => {
try {
let compAllocated = 0;
let compDistributed = 0;
data.markets.forEach(({ comp_allocated, comp_distributed }) => {
compAllocated += +comp_allocated;
compDistributed += +comp_distributed;
});
const compAccrued = compAllocated - compDistributed;
output.innerText = compAccrued + ' COMP accrued';
} catch (error) {
console.error('data', data);
console.error('error', error);
output.innerText = 'Request error. Enter a valid address and try again.';
}
});
}
};