Skip to content

Commit

Permalink
Fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
prevetal committed Feb 14, 2024
1 parent 32384e4 commit 2329e05
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
16 changes: 7 additions & 9 deletions src/components/account/Charts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<script setup>
import { onBeforeMount, ref, inject, reactive } from 'vue'
import { useGlobalStore } from '@/stores'
import { generateAddress, formatTokenAmount, formatAmountToCurrentDenom } from '@/utils'
import { generateAddress, formatTokenAmount, formatAmountToCurrentDenom, formatTokenPrice } from '@/utils'
// Components
import ChartStakeLiquide from '@/components/account/charts/ChartStakeLiquide.vue'
Expand Down Expand Up @@ -149,7 +149,7 @@
network.total.liquid_rewards += amount
// Calc tokens price
network.totalTokensPrice += amount * el.price
network.totalTokensPrice += amount * formatTokenPrice(el.price, el.symbol)
// Group by denom
let duplicate = network.groupByDenom.find(e => e.symbol == el.symbol)
Expand Down Expand Up @@ -178,7 +178,7 @@
network.total.ibc += amountCurrentDenom
// Calc tokens price
network.totalTokensPrice += amount * el.price
network.totalTokensPrice += amount * formatTokenPrice(el.price, el.symbol)
// Group by denom
let duplicate = network.groupByDenom.find(e => e.symbol == el.symbol)
Expand Down Expand Up @@ -207,7 +207,7 @@
network.total.staked += amount
// Calc tokens price
network.totalTokensPrice += amount * el.price
network.totalTokensPrice += amount * formatTokenPrice(el.price, el.symbol)
// Group by denom
let duplicate = network.groupByDenom.find(e => e.symbol == el.symbol)
Expand Down Expand Up @@ -236,7 +236,7 @@
network.total.unbonding += amount
// Calc tokens price
network.totalTokensPrice += amount * el.price
network.totalTokensPrice += amount * formatTokenPrice(el.price, el.symbol)
// Group by denom
let duplicate = network.groupByDenom.find(e => e.symbol == el.symbol)
Expand Down Expand Up @@ -265,10 +265,10 @@
network.total.rewards += amount
// Calc tokens rewards price
network.totalRewardsPrice += amount * el.price
network.totalRewardsPrice += amount * formatTokenPrice(el.price, el.symbol)
// Calc tokens price
network.totalTokensPrice += amount * el.price
network.totalTokensPrice += amount * formatTokenPrice(el.price, el.symbol)
// Group by denom
if (store.prices.find(e => e.symbol == el.symbol)) {
Expand Down Expand Up @@ -347,8 +347,6 @@
}
}
console.log(store.account)
// Hide loader
loading.value = false
}
Expand Down
20 changes: 17 additions & 3 deletions src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export const sendTx = async ({ txRaw, client }) => {
// Currency conversion
export const currencyСonversion = (amount, currency) => {
let store = useGlobalStore(),
tokenPrice = store.prices.find(el => el.symbol == currency).price,
tokenPrice = formatTokenPrice(store.prices.find(el => el.symbol == currency).price, currency),
toPrice = 1

if (store.currentCurrency != 'USDT') {
Expand All @@ -181,7 +181,7 @@ export const currencyСonversion = (amount, currency) => {
currency = formatTokenName('BTC')
}

toPrice = store.prices.find(el => el.symbol == currency).price
toPrice = formatTokenPrice(store.prices.find(el => el.symbol == currency).price, currency)
}

return amount * (tokenPrice / toPrice)
Expand All @@ -203,7 +203,7 @@ export const formatTokenName = (tokenName) => {
// Formating token amount
export const formatTokenAmount = (amount, tokenName) => {
let store = useGlobalStore(),
formatAmount = '',
formatAmount = 0,
formatableToken = store.formatableTokens.find(el => el.tokenName == tokenName)

formatableToken
Expand All @@ -219,4 +219,18 @@ export const formatAmountToCurrentDenom = (amount, tokenName) => {
let store = useGlobalStore()

return amount * (store.prices.find(e => e.symbol == tokenName).price / store.prices.find(e => e.symbol == store.networks[store.currentNetwork].token_name).price)
}


// Formating token price
export const formatTokenPrice = (price, tokenName) => {
let store = useGlobalStore(),
formatPrice = 0,
formatableToken = store.formatableTokens.find(el => el.tokenName == tokenName)

formatableToken
? formatPrice = price * Math.pow(10, formatableToken.exponent)
: formatPrice = price

return formatPrice
}

0 comments on commit 2329e05

Please sign in to comment.