add valuation

This commit is contained in:
liangping 2022-04-06 19:03:25 +08:00
parent dd4869353a
commit 7469cd1178
3 changed files with 38 additions and 7 deletions

View File

@ -380,7 +380,7 @@ export function formatTokenAmount(tokenAmount, decimals = 2, tokenDenom = 'uatom
if (format) { return numberWithCommas(parseFloat(amount.toFixed(decimals))) }
return parseFloat(amount.toFixed(decimals))
}
return parseFloat(amount.toFixed(decimals))
return parseFloat(amount.toFixed(exp))
}
export function isTestnet() {

View File

@ -75,6 +75,9 @@
</b-input-group>
<small class="text-danger">{{ errors[0] }}</small>
</validation-provider>
<b-form-text>
<strong class="text-primary">{{ currencySign }}{{ valuation }}</strong>
</b-form-text>
</b-form-group>
</b-col>
</b-row>
@ -138,7 +141,7 @@ import {
required, email, url, between, alpha, integer, password, min, digits, alphaDash, length,
} from '@validations'
import {
formatToken, formatTokenDenom, getUnitAmount,
formatToken, formatTokenDenom, getUnitAmount, getUserCurrency, getUserCurrencySign,
} from '@/libs/utils'
import vSelect from 'vue-select'
import { coin } from '@cosmjs/amino'
@ -171,6 +174,8 @@ export default {
},
data() {
return {
currency: getUserCurrency(),
currencySign: getUserCurrencySign(),
targetChainId: '',
token: '',
amount: null,
@ -230,6 +235,16 @@ export default {
paths() {
return this.$store.state.chains.ibcPaths
},
valuation() {
const { amount } = this
const d2 = this.printDenom()
if (amount && d2) {
const quote = this.$store.state.chains.quotes[d2]
const price = quote ? quote[this.currency] : 0
return parseFloat((amount * price).toFixed(2))
}
return 0
},
},
mounted() {
this.$emit('update', {
@ -274,7 +289,7 @@ export default {
},
format(v) {
return formatToken(v, this.IBCDenom)
return formatToken(v, this.IBCDenom, 6)
},
printDenom() {
return formatTokenDenom(this.IBCDenom[this.token] || this.token)

View File

@ -92,6 +92,9 @@
</b-input-group>
<small class="text-danger">{{ errors[0] }}</small>
</validation-provider>
<b-form-text>
<strong class="text-primary">{{ currencySign }}{{ valuation }}</strong>
</b-form-text>
</b-form-group>
</b-col>
</b-row>
@ -101,13 +104,14 @@
<script>
import { ValidationProvider } from 'vee-validate'
import {
BRow, BCol, BInputGroup, BInputGroupAppend, BFormInput, BFormGroup, BFormSelect, BFormSelectOption,
BRow, BCol, BInputGroup, BInputGroupAppend, BFormInput, BFormGroup,
BFormSelect, BFormSelectOption, BFormText,
} from 'bootstrap-vue'
import {
required, email, url, between, alpha, integer, password, min, digits, alphaDash, length,
} from '@validations'
import {
formatToken, formatTokenDenom, getUnitAmount,
formatToken, formatTokenDenom, getUnitAmount, getUserCurrency, getUserCurrencySign,
} from '@/libs/utils'
export default {
@ -118,6 +122,7 @@ export default {
BInputGroup,
BInputGroupAppend,
BFormInput,
BFormText,
BFormGroup,
BFormSelect,
BFormSelectOption,
@ -136,6 +141,8 @@ export default {
},
data() {
return {
currency: getUserCurrency(),
currencySign: getUserCurrencySign(),
token: '',
amount: null,
recipient: '',
@ -176,6 +183,16 @@ export default {
IBCDenom() {
return this.$store.state.chains.denoms
},
valuation() {
const { amount } = this
if (amount) {
const d2 = this.printDenom()
const quote = this.$store.state.chains.quotes[d2]
const price = quote ? quote[this.currency] : 0
return parseFloat((amount * price).toFixed(2))
}
return 0
},
},
mounted() {
this.$emit('update', {
@ -193,12 +210,11 @@ export default {
return []
},
format(v) {
return formatToken(v, this.IBCDenom)
return formatToken(v, this.IBCDenom, 6)
},
printDenom() {
return formatTokenDenom(this.IBCDenom[this.token] || this.token)
},
},
}