Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
prevetal committed Feb 26, 2024
1 parent 76550e5 commit 6a15fc2
Show file tree
Hide file tree
Showing 5 changed files with 371 additions and 142 deletions.
180 changes: 51 additions & 129 deletions src/components/account/Charts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
ibc: 0,
liquid_rewards: 0
})
network.totalRewardsPrice = 0
network.totalTokensPrice = 0
network.groupByDenom = []
Expand Down Expand Up @@ -359,6 +360,21 @@
for (const wallet of store.account.wallets) {
for (const network of wallet.networks) {
// Clear previous data
network.total = reactive({
liquid: 0,
staked: 0,
unbonding: 0,
rewards: 0,
outside: 0,
ibc: 0,
liquid_rewards: 0
})
network.totalRewardsPrice = 0
network.totalTokensPrice = 0
network.groupByDenom = []
// Calc liquid tokens
if(network.balance.liquid && network.balance.liquid.native) {
network.balance.liquid.native.forEach(el => {
Expand All @@ -370,7 +386,7 @@
network.total.liquid_rewards += amount
// Calc tokens price
network.totalTokensPrice += amount * el.price
network.totalTokensPrice += amount * formatTokenPrice(store.prices.find(e => e.symbol == el.symbol).price, el.symbol)
// Group by denom
let duplicate = network.groupByDenom.find(e => e.symbol == el.symbol)
Expand All @@ -389,6 +405,7 @@
})
}
// Calc ibc tokens
if(network.balance.liquid && network.balance.liquid.ibc) {
network.balance.liquid.ibc.forEach(el => {
Expand All @@ -399,7 +416,7 @@
network.total.ibc += amountCurrentDenom
// Calc tokens price
network.totalTokensPrice += amount * el.price
network.totalTokensPrice += amount * formatTokenPrice(store.prices.find(e => e.symbol == el.symbol).price, el.symbol)
// Group by denom
let duplicate = network.groupByDenom.find(e => e.symbol == el.symbol)
Expand All @@ -418,6 +435,7 @@
})
}
// Calc staked tokens
if(network.balance.staked) {
network.balance.staked.forEach(el => {
Expand All @@ -428,7 +446,7 @@
network.total.staked += amount
// Calc tokens price
network.totalTokensPrice += amount * el.price
network.totalTokensPrice += amount * formatTokenPrice(store.prices.find(e => e.symbol == el.symbol).price, el.symbol)
// Group by denom
let duplicate = network.groupByDenom.find(e => e.symbol == el.symbol)
Expand All @@ -447,6 +465,7 @@
})
}
// Calc unbonding tokens
if(network.balance.unbonding) {
network.balance.unbonding.forEach(el => {
Expand All @@ -457,7 +476,7 @@
network.total.unbonding += amount
// Calc tokens price
network.totalTokensPrice += amount * el.price
network.totalTokensPrice += amount * formatTokenPrice(store.prices.find(e => e.symbol == el.symbol).price, el.symbol)
// Group by denom
let duplicate = network.groupByDenom.find(e => e.symbol == el.symbol)
Expand All @@ -476,21 +495,21 @@
})
}
// Calc rewards tokens
if(network.balance.rewards) {
network.balance.rewards.forEach(el => {
let amount = formatTokenAmount(el.amount, el.symbol),
amountCurrentDenom = formatAmountToCurrentDenom(amount, el.symbol)
// Sum total
if (store.prices.find(e => e.symbol == el.symbol)) {
if(amount >= 1) {
network.total.rewards += amount
}
}
network.total.rewards += amount
// Calc tokens rewards price
network.totalRewardsPrice += amount * formatTokenPrice(store.prices.find(e => e.symbol == el.symbol).price, el.symbol)
// Calc tokens price
network.totalTokensPrice += amount * el.price
network.totalTokensPrice += amount * formatTokenPrice(store.prices.find(e => e.symbol == el.symbol).price, el.symbol)
// Group by denom
if (store.prices.find(e => e.symbol == el.symbol)) {
Expand All @@ -511,6 +530,7 @@
})
}
// Set network data
network.total.liquid_rewards = network.total.liquid + network.total.rewards
Expand All @@ -524,141 +544,43 @@
}
// Sum wallet total tokens
// Total tokens price
store.account.totalTokensPrice = 0
for (let wallet of store.account.wallets) {
wallet.totalTokens = 0
wallet.totalTokensPrice = 0
for (let network of wallet.networks) {
wallet.totalTokens += network.totalTokens
// Sum wallet total tokens price
wallet.totalTokensPrice += network.totalTokensPrice
// Sum account total tokens price
store.account.totalTokensPrice += network.totalTokensPrice
}
}
// Sum account total tokens
store.account.totalTokens = 0
// Total rewards price
store.account.totalRewardsPrice = 0
for (let wallet of store.account.wallets) {
store.account.totalTokens += wallet.totalTokens
wallet.totalRewardsPrice = 0
for (let network of wallet.networks) {
// Sum wallet total rewards price
wallet.totalRewardsPrice += network.totalRewardsPrice
// Sum account total rewards price
store.account.totalRewardsPrice += network.totalRewardsPrice
}
}
console.log(store.account)
// Hide loader
loading.value = false
}
// // Calc liquid tokens
// function calcLiquidTokens(network, tokens) {
// tokens.forEach(el => {
// // Sum total
// network.totals.liquid += el.amount
// network.totals.liquid_rewards += el.amount
// // Group by denom
// AddGroupByDenom(network, el)
// })
// }
// // Calc IBC tokens
// function calcIBCTokens(tokens) {
// tokens.forEach(el => {
// // Convert to current denom
// el.amountCurrentDenom = el.amount / Math.pow(10, el.exponent) * (store.prices.find(e => e.symbol == el.symbol).price / store.prices.find(e => e.symbol == store.networks[store.currentNetwork].token_name).price)
// // Sum total
// network.totals.ibc += parseFloat(el.amountCurrentDenom * Math.pow(10, store.networks[store.currentNetwork].exponent))
// // Group by denom
// AddGroupByDenom(network, el)
// })
// }
// // Calc staked tokens
// function calcStackedTokens(tokens) {
// tokens.forEach(el => {
// // Sum total
// network.totals.staked += el.amount
// // Group by denom
// AddGroupByDenom(network, el)
// })
// }
// // Calc unbonding tokens
// function calcUnbondingTokens(tokens) {
// tokens.forEach(el => {
// // Sum total
// network.totals.unbonding += el.amount
// // Group by denom
// AddGroupByDenom(network, el)
// })
// }
// // Calc rewards tokens
// function calcRewardsTokens(tokens) {
// tokens.forEach(el => {
// // Convert to current denom
// el.amountCurrentDenom = el.amount / Math.pow(10, el.exponent) * (store.prices.find(e => e.symbol == el.symbol).price / store.prices.find(e => e.symbol == store.networks[store.currentNetwork].token_name).price)
// // Sum total
// if(el.amount * Math.pow(10, el.exponent) >= 1) {
// network.totals.rewards += parseFloat(el.amountCurrentDenom * Math.pow(10, store.networks[store.currentNetwork].exponent))
// }
// network.totals.liquid_rewards = network.totals.liquid + network.totals.rewards
// // Group by denom
// AddGroupByDenom(network, el)
// })
// }
// // Group by denom
// function AddGroupByDenom(network, el) {
// let duplicate = network.groupByDenom.find(e => e.symbol == el.symbol)
// if(duplicate) {
// duplicate.amount += (el.amount / Math.pow(10, el.exponent) * (store.prices.find(e => e.symbol == el.symbol).price / store.prices.find(e => e.symbol == store.networks[store.currentNetwork].token_name).price)) * Math.pow(10, store.networks[store.currentNetwork].exponent)
// } else {
// network.groupByDenom.push({
// 'amount': (el.amount / Math.pow(10, el.exponent) * (store.prices.find(e => e.symbol == el.symbol).price / store.prices.find(e => e.symbol == store.networks[store.currentNetwork].token_name).price)) * Math.pow(10, store.networks[store.currentNetwork].exponent),
// 'logo': el.logo,
// 'symbol': el.symbol
// })
// }
// }
// // Set data in network
// function setDataInNetwork(currentNetwork, response) {
// currentNetwork.address = response.address
// currentNetwork.total = currentNetwork.totals
// currentNetwork.totalTokens = 0
// currentNetwork.totalTokens += currentNetwork.totals.liquid + currentNetwork.totals.staked + currentNetwork.totals.unbonding + currentNetwork.totals.rewards + currentNetwork.totals.outside + currentNetwork.totals.ibc
// currentNetwork.balance = {
// liquid: {
// native: response.liquid && response.liquid.native ? response.liquid.native : null,
// ibc: response.liquid && response.liquid.ibc ? response.liquid.ibc : null
// },
// staked: response.staked,
// unbonding: response.unbonding,
// rewards: response.rewards,
// groupByDenom: currentNetwork.groupByDenom.sort((a, b) => {
// if (a.amount > b.amount) { return -1 }
// if (a.amount < b.amount) { return 1 }
// return 0
// })
// }
// }
// Event "change active chart"
emitter.on('changeActiveChart', chartIndex => chartActive.value = chartIndex)
</script>
Expand Down
4 changes: 2 additions & 2 deletions src/components/account/Networks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</div>

<div class="list">
<router-link to="/account/cosmoshub" class="network" :class="{ active: store.currentNetwork == 'cosmoshub' }">
<router-link :to="{ path: '/account/cosmoshub', query: { demo: store.demo ? true : '' } }" class="network" :class="{ active: store.currentNetwork == 'cosmoshub' }">
<div class="logo">
<img src="/cosmoshub_logo.png" alt="">
</div>
Expand All @@ -18,7 +18,7 @@
</div>
</router-link>

<router-link to="/account/bostrom" class="network" :class="{ active: store.currentNetwork == 'bostrom' }">
<router-link :to="{ path: '/account/bostrom', query: { demo: store.demo ? true : '' } }" class="network" :class="{ active: store.currentNetwork == 'bostrom' }">
<div class="logo">
<img src="/bostrom_logo.png" alt="">
</div>
Expand Down
6 changes: 1 addition & 5 deletions src/components/account/Proposals.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
</div>

<div class="all_link">
<router-link :to="`/proposals/${store.currentNetwork}?demo=true`" class="link" v-if="store.demo">
{{ $t('message.btn_see_more') }} &rarr;
</router-link>

<router-link :to="`/proposals/${store.currentNetwork}`" class="link" v-else>
<router-link :to="{ path: `/proposals/${store.currentNetwork}`, query: { demo: store.demo ? true : '' } }" class="link" v-if="store.demo">
{{ $t('message.btn_see_more') }} &rarr;
</router-link>
</div>
Expand Down
6 changes: 3 additions & 3 deletions src/components/account/Stats.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@
const store = useGlobalStore(),
loading = store.demo ? ref(false) : ref(true),
APR = !store.demo ? ref(0) : ref(0.2125),
totalRewardsPrice = !store.demo ? ref(0) : ref(10.016),
totalTokensPrice = !store.demo ? ref(0) : ref(150.18),
RPDE = !store.demo ? ref(0) : ref(0.4)
totalRewardsPrice = !store.demo ? ref(0) : ref(110.016),
totalTokensPrice = !store.demo ? ref(0) : ref(15070.18),
RPDE = !store.demo ? ref(0) : ref(4000000)
onBeforeMount(async () => {
Expand Down
Loading

0 comments on commit 6a15fc2

Please sign in to comment.