-
Notifications
You must be signed in to change notification settings - Fork 3
/
topAccounts.js
62 lines (53 loc) · 1.94 KB
/
topAccounts.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
export const useTopAccountsStore = defineStore('topAccounts', () => {
const axios = useAxios()
const rawTopAccounts = ref(null)
const activeAccountsCount = ref(null)
const totalAccountsCount = ref(null)
const { MIDDLEWARE_URL } = useRuntimeConfig().public
const blockchainStatsStore = useBlockchainStatsStore()
const { fetchTotalStats } = useBlockchainStatsStore()
const topAccounts = computed(() =>
rawTopAccounts.value && blockchainStatsStore.totalTokenSupply
? adaptTopAccounts(rawTopAccounts.value, blockchainStatsStore.totalTokenSupply)
: null,
)
function fetchTopAccounts() {
return Promise.allSettled([
fetchAccounts(),
fetchTotalStats(),
fetchActiveAccountsCount(),
fetchTotalAccountsCount(),
])
}
async function fetchAccounts() {
rawTopAccounts.value = null
const { data } = await axios.get(`${MIDDLEWARE_URL}/v3/wealth`)
rawTopAccounts.value = data
}
async function fetchActiveAccountsCount() {
activeAccountsCount.value = null
const { data } = await axios.get(`${MIDDLEWARE_URL}/v3/stats/active-accounts?limit=1`)
activeAccountsCount.value = data.data[0].count
}
async function fetchTotalAccountsCount() {
totalAccountsCount.value = null
const { data } = await axios.get(`${MIDDLEWARE_URL}/v3/stats/total-accounts?interval_by=month&limit=100`)
// todo ask mdw for endpoint
totalAccountsCount.value = data.data.reduce((total, item) => total + parseInt(item.count), 0)
}
function sumCounts(dataString) {
// Parse the input string into an array of objects
// Check if the parsing was successful
if (!Array.isArray(dataArray)) {
throw new TypeError('Invalid input: Expected a valid JSON array')
}
// Sum up all the counts using reduce()
return dataArray.reduce((total, item) => total + parseInt(item.count), 0)
}
return {
fetchTopAccounts,
topAccounts,
activeAccountsCount,
totalAccountsCount,
}
})