Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
prevetal committed Jan 22, 2024
1 parent d471fd8 commit 3581fe8
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 74 deletions.
40 changes: 14 additions & 26 deletions src/components/account/Charts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,6 @@
loading = store.demo ? ref(false) : ref(true),
chartActive = ref(1)
// var totals = reactive({
// liquid: 0,
// staked: 0,
// unbonding: 0,
// rewards: 0,
// outside: 0,
// ibc: 0,
// liquid_rewards: 0
// }),
// groupByDenom = ref([])
onBeforeMount(async () => {
// Get data
Expand All @@ -87,7 +76,8 @@
loading.value = true
for (const wallet of store.account.wallets) {
for (let network of wallet.networks) {
console.log(wallet)
for (const network of wallet.networks) {
try {
// Set network info
await fetch(`${store.networks[network.name].index_api}/account/account_balance/${generateAddress(store.networks[network.name].address_prefix, wallet.address)}`)
Expand Down Expand Up @@ -162,10 +152,10 @@
let duplicate = network.groupByDenom.find(e => e.symbol == el.symbol)
if(duplicate) {
duplicate.amount += el.amount
duplicate.amount += el.amount / Math.pow(10, el.exponent)
} else {
network.groupByDenom.push({
'amount': el.amount,
'amount': el.amount / Math.pow(10, el.exponent),
'logo': el.logo,
'symbol': el.symbol
})
Expand All @@ -179,17 +169,17 @@
response.liquid.ibc.forEach(el => {
// Sum total
network.total.ibc += el.amount
network.total.ibc += el.amount / Math.pow(10, el.exponent)
// Group by denom
// AddGroupByDenom(network, el)
let duplicate = network.groupByDenom.find(e => e.symbol == el.symbol)
if(duplicate) {
duplicate.amount += el.amount
duplicate.amount += el.amount / Math.pow(10, el.exponent)
} else {
network.groupByDenom.push({
'amount': el.amount,
'amount': el.amount / Math.pow(10, el.exponent),
'logo': el.logo,
'symbol': el.symbol
})
Expand All @@ -210,10 +200,10 @@
let duplicate = network.groupByDenom.find(e => e.symbol == el.symbol)
if(duplicate) {
duplicate.amount += el.amount
duplicate.amount += el.amount / Math.pow(10, el.exponent)
} else {
network.groupByDenom.push({
'amount': el.amount,
'amount': el.amount / Math.pow(10, el.exponent),
'logo': el.logo,
'symbol': el.symbol
})
Expand All @@ -234,10 +224,10 @@
let duplicate = network.groupByDenom.find(e => e.symbol == el.symbol)
if(duplicate) {
duplicate.amount += el.amount
duplicate.amount += el.amount / Math.pow(10, el.exponent)
} else {
network.groupByDenom.push({
'amount': el.amount,
'amount': el.amount / Math.pow(10, el.exponent),
'logo': el.logo,
'symbol': el.symbol
})
Expand All @@ -253,7 +243,7 @@
// Sum total
if (store.prices.find(e => e.symbol == el.symbol)) {
if(el.amount * Math.pow(10, el.exponent) >= 1) {
network.total.rewards += el.amount
network.total.rewards += el.amount / Math.pow(10, el.exponent)
}
}
Expand All @@ -265,10 +255,10 @@
let duplicate = network.groupByDenom.find(e => e.symbol == el.symbol)
if(duplicate) {
duplicate.amount += el.amount
duplicate.amount += el.amount / Math.pow(10, el.exponent)
} else {
network.groupByDenom.push({
'amount': el.amount,
'amount': el.amount / Math.pow(10, el.exponent),
'logo': el.logo,
'symbol': el.symbol
})
Expand Down Expand Up @@ -300,8 +290,6 @@
return 0
})
}
console.log(network)
})
} catch (error) {
console.error(error)
Expand Down
2 changes: 1 addition & 1 deletion src/components/account/Stats.vue
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
for (let network of wallet.networks) {
try {
// Set network info
await fetch(`${store.networks[store.currentNetwork].index_api}/account/account_info/${generateAddress(store.networks[store.currentNetwork].address_prefix, wallet.address)}`)
await fetch(`${store.networks[network.name].index_api}/account/account_info/${generateAddress(store.networks[network.name].address_prefix, wallet.address)}`)
.then(res => res.json())
.then(response => {
// Set network info
Expand Down
22 changes: 17 additions & 5 deletions src/components/account/charts/ChartAccounts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@


<script setup>
import { onBeforeMount, computed, reactive, ref } from 'vue'
import { onBeforeMount, computed, reactive, ref, watch } from 'vue'
import { useGlobalStore } from '@/stores'
import { currencyСonversion } from '@/utils'
Expand All @@ -60,8 +60,9 @@
ChartJS.register(ArcElement)
const store = useGlobalStore(),
chart = ref(null),
const store = useGlobalStore()
var chart = ref(null),
chartDatasets = reactive([]),
chartActiveLegend = ref(null),
chartData = computed(() => ({
Expand Down Expand Up @@ -100,10 +101,21 @@
})
onBeforeMount(() => {
onBeforeMount(() => init())
watch(computed(() => store.currentNetwork), () => {
// Reset chart
chartDatasets = reactive([])
init()
})
// Init
function init() {
// Set data for chart
store.account.wallets.forEach(el => chartDatasets.push(el.totalTokens))
})
}
// Mouse enter on legend
Expand Down
28 changes: 22 additions & 6 deletions src/components/account/charts/ChartAssets.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@

<div class="price">
<div>
{{ $filters.toFixed(currencyСonversion(item.amount / Math.pow(10, store.networks[store.currentNetwork].exponent), store.networks[store.currentNetwork].token_name), 2) }}
<template v-if="(currencyСonversion(item.amount / Math.pow(10, store.networks[store.currentNetwork].exponent), store.networks[store.currentNetwork].token_name)) < 0.01">&lt; 0.01</template>

<template v-else>{{ $filters.toFixed(currencyСonversion(item.amount / Math.pow(10, store.networks[store.currentNetwork].exponent), store.networks[store.currentNetwork].token_name), 2) }}</template>

{{ store.currentCurrency }}
</div>

Expand All @@ -59,7 +62,7 @@


<script setup>
import { onBeforeMount, computed, reactive, ref } from 'vue'
import { onBeforeMount, computed, reactive, ref, watch } from 'vue'
import { useGlobalStore } from '@/stores'
import { currencyСonversion } from '@/utils'
Expand All @@ -69,8 +72,9 @@
ChartJS.register(ArcElement)
const store = useGlobalStore(),
chart = ref(null),
const store = useGlobalStore()
var chart = ref(null),
chartDatasets = reactive([]),
chartActiveLegend = ref(null),
chartColors = reactive([]),
Expand Down Expand Up @@ -118,7 +122,19 @@
})
onBeforeMount(() => {
onBeforeMount(() => init())
watch(computed(() => store.currentNetwork), () => {
// Reset chart
chartDatasets = reactive([])
chartColors = reactive([])
init()
})
// Init
function init() {
if(store.account.currentWallet != 'all') {
// Get current walllet data
currentWallet.value = store.account.wallets.find(el => el.address == store.account.currentWallet)
Expand Down Expand Up @@ -186,7 +202,7 @@
// Sum chart total
currentData.value.balance.groupByDenom.forEach(el => chartTotal.value += el.amount)
})
}
// Mouse enter on legend
Expand Down
23 changes: 18 additions & 5 deletions src/components/account/charts/ChartNetworks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@


<script setup>
import { onBeforeMount, computed, reactive, ref } from 'vue'
import { onBeforeMount, computed, reactive, ref, watch } from 'vue'
import { useGlobalStore } from '@/stores'
import { currencyСonversion } from '@/utils'
Expand All @@ -67,8 +67,9 @@
ChartJS.register(ArcElement)
const store = useGlobalStore(),
chart = ref(null),
const store = useGlobalStore()
var chart = ref(null),
chartDatasets = reactive([]),
chartActiveLegend = ref(null),
chartColors = reactive([]),
Expand Down Expand Up @@ -112,7 +113,19 @@
})
onBeforeMount(() => {
onBeforeMount(() => init())
watch(computed(() => store.currentNetwork), () => {
// Reset chart
chartDatasets = reactive([])
chartColors = reactive([])
init()
})
// Init
function init() {
if(store.account.currentWallet != 'all') {
// Get current walllet data
currentData.value = store.account.wallets.find(el => el.address == store.account.currentWallet)
Expand Down Expand Up @@ -143,7 +156,7 @@
chartDatasets.push(network.totalTokens)
chartColors.push(network.color)
})
})
}
// Mouse enter on legend
Expand Down
Loading

0 comments on commit 3581fe8

Please sign in to comment.