-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
103 lines (82 loc) · 3.83 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
window.addEventListener('load', () => {
const META = 3000000;
axios.get('https://api.catarse.me/project_details?project_id=eq.122021')
.then((projectRes) => {
let data = projectRes.data[0];
let pledged = data.pledged;
document.getElementById('progressbar-conf').style.width = `${calcPercent(pledged)}%`;
document.getElementById('pledged').innerHTML = `${formatMoney(pledged)}`;
axios.get('https://api.catarse.me/reward_details?project_id=eq.122021')
.then((detailsRes) => {
let data = detailsRes.data;
let waiting = 0;
data.forEach((d) => {
let minimum = d.minimum_value;
let wait = d.waiting_payment_count;
waiting += minimum * wait;
});
let total = pledged + waiting;
document.getElementById('progressbar-wait').style.width = pledged >= META ? '0%' : `${(waiting + pledged) >= META ? calcPercent(META - pledged) : calcPercent(waiting)}%`;
document.getElementById('waiting').innerHTML = `${formatMoney(waiting)}`;
document.getElementById('total-value').innerHTML = `${formatMoney(total)}`;
})
.catch((error) => {
console.log(error);
});
})
.catch((error) => {
console.log(error);
});
setInterval(() => {
axios.get('https://api.catarse.me/project_details?project_id=eq.122021')
.then((projectRes) => {
let data = projectRes.data[0];
let pledged = data.pledged;
document.getElementById('progressbar-conf').style.width = `${calcPercent(pledged)}%`;
document.getElementById('pledged').innerHTML = `${formatMoney(pledged)}`;
axios.get('https://api.catarse.me/reward_details?project_id=eq.122021')
.then((detailsRes) => {
let data = detailsRes.data;
let waiting = 0;
data.forEach((d) => {
let minimum = d.minimum_value;
let wait = d.waiting_payment_count;
waiting += minimum * wait;
});
let total = pledged + waiting;
document.getElementById('progressbar-wait').style.width = pledged >= META ? '0%' : `${(waiting + pledged) >= META ? calcPercent(META - pledged) : calcPercent(waiting)}%`;
document.getElementById('waiting').innerHTML = `${formatMoney(waiting)}`;
document.getElementById('total-value').innerHTML = `${formatMoney(total)}`;
})
.catch((error) => {
console.log(error);
});
})
.catch((error) => {
console.log(error);
});
}, 10000);
});
function formatMoney(number = 0, prefix = true) {
try {
return prefix
?
number.toLocaleString('pt-BR', { style: 'currency', currency: 'BRL', maximumFractionDigits: 2, minimumFractionDigits: 2 }).includes(',')
? number.toLocaleString('pt-BR', { style: 'currency', currency: 'BRL', maximumFractionDigits: 2, minimumFractionDigits: 2 })
: `${number.toLocaleString('pt-BR', { style: 'currency', currency: 'BRL', maximumFractionDigits: 2, minimumFractionDigits: 2 })},00`
:
number.toLocaleString('pt-BR', { currency: 'BRL', maximumFractionDigits: 2, minimumFractionDigits: 2 }).includes(',')
? number.toLocaleString('pt-BR', { currency: 'BRL', maximumFractionDigits: 2, minimumFractionDigits: 2 })
: `${number.toLocaleString('pt-BR', { currency: 'BRL', maximumFractionDigits: 2, minimumFractionDigits: 2 })},00`
} catch {
return `${'0'.toLocaleString('pt-BR', { currency: 'BRL', maximumFractionDigits: 2, minimumFractionDigits: 2 })
},00`
}
}
function calcPercent(number = 0, total = 3000000) {
return (number * 100) / total;
}
// Detalhes do Projeto:
// https://api.catarse.me/project_details?project_id=eq.122021
// Detalhes de Recompensa:
// https://api.catarse.me/reward_details?project_id=eq.122021