Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
prevetal committed Feb 19, 2024
1 parent c5578a4 commit bed0608
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/components/account/charts/ChartAssets.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<script setup>
import { onBeforeMount, computed, reactive, ref, watch } from 'vue'
import { useGlobalStore } from '@/stores'
import { currencyСonversion, formatTokenAmount } from '@/utils'
import { currencyСonversion } from '@/utils'
import { Chart as ChartJS, ArcElement } from 'chart.js'
import { Doughnut } from 'vue-chartjs'
Expand Down
10 changes: 7 additions & 3 deletions src/components/modal/ValidatorModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@

<div class="val">
<span>
{{ new Number($filters.toFixed(formatTokenAmount(store.validatorInfo.self_bonded.amount, store.networks[store.validatorInfo.network].token_name), 0)).toLocaleString('en-US') }}
{{ new Number($filters.toFixed(formatTokenAmount(store.validatorInfo.self_bonded.amount, store.networks[store.validatorInfo.network].token_name, true), 0)).toLocaleString('en-US') }}

<template v-if="store.validatorInfo.network == 'bostrom'">
{{ formatTokenName(store.networks[store.validatorInfo.network].token_name, true) }}
</template>
</span>
/
<span>{{ $filters.toFixed(formatTokenAmount(store.validatorInfo.self_bonded.amount, store.networks[store.validatorInfo.network].token_name) / store.validatorInfo.voting_power * 100, 2) }}%</span>
Expand All @@ -112,7 +116,7 @@
</div>

<div class="val">
{{ new Number($filters.toFixed(store.validatorInfo.voting_power, 0)).toLocaleString('en-US') }}
{{ new Number($filters.toFixed(formatTokenAmount(store.validatorInfo.voting_power, store.networks[store.validatorInfo.network].token_name), 2)).toLocaleString('en-US') }} {{ formatTokenName(store.networks[store.validatorInfo.network].token_name) }}
</div>
</div>

Expand All @@ -139,7 +143,7 @@
<script setup>
import { inject, onBeforeMount, ref } from 'vue'
import { useGlobalStore } from '@/stores'
import { formatTokenAmount } from '@/utils'
import { formatTokenAmount, formatTokenName } from '@/utils'
const store = useGlobalStore(),
Expand Down
8 changes: 6 additions & 2 deletions src/stores/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,16 @@ export const useGlobalStore = defineStore('global', {
{
tokenName: 'BOOT',
formatTokenName: 'MBOOT',
exponent: 6
formatTokenNameG: 'GBOOT',
exponent: 6,
exponentG: 9
},
{
tokenName: 'HYDROGEN',
formatTokenName: 'MHYDROGEN',
exponent: 6
formatTokenName: 'GHYDROGEN',
exponent: 6,
exponentG: 9
}
],

Expand Down
42 changes: 26 additions & 16 deletions src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,22 @@ export const sendTx = async ({ txRaw, client }) => {



// Formating token name
export const formatTokenName = (tokenName, giga = false) => {
let store = useGlobalStore(),
newTokenName = ''

if (store.formatableTokens.find(el => el.tokenName == tokenName)) {
giga
? newTokenName = store.formatableTokens.find(el => el.tokenName == tokenName).formatTokenNameG
: newTokenName = store.formatableTokens.find(el => el.tokenName == tokenName).formatTokenName
}

return newTokenName.length ? newTokenName : tokenName
}



// Currency conversion
export const currencyСonversion = (amount, currency) => {
let store = useGlobalStore(),
Expand All @@ -188,27 +204,21 @@ export const currencyСonversion = (amount, currency) => {
}



// Formating token name
export const formatTokenName = (tokenName) => {
let store = useGlobalStore(),
newTokenName = ''

newTokenName = store.formatableTokens.find(el => el.tokenName == tokenName)

return newTokenName ? newTokenName.formatTokenName : tokenName
}


// Formating token amount
export const formatTokenAmount = (amount, tokenName) => {
export const formatTokenAmount = (amount, tokenName, giga = false) => {
let store = useGlobalStore(),
formatAmount = 0,
formatableToken = store.formatableTokens.find(el => el.tokenName == tokenName)

formatableToken
? formatAmount = amount / Math.pow(10, formatableToken.exponent)
: formatAmount = amount / Math.pow(10, store.prices.find(el => el.symbol == tokenName).exponent)
if (giga) {
formatableToken
? formatAmount = amount / Math.pow(10, formatableToken.exponentG)
: formatAmount = amount / Math.pow(10, store.prices.find(el => el.symbol == tokenName).exponent)
} else {
formatableToken
? formatAmount = amount / Math.pow(10, formatableToken.exponent)
: formatAmount = amount / Math.pow(10, store.prices.find(el => el.symbol == tokenName).exponent)
}

return formatAmount
}
Expand Down
2 changes: 1 addition & 1 deletion src/views/Proposal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
activeTab.value = tab
// Set params to URL
urlParams.tab = value
urlParams.tab = tab
}
Expand Down

0 comments on commit bed0608

Please sign in to comment.