11<template >
22 <div class =" arguments-wrapper" >
33 <b-field :label =" $t(label)" class =" balance" >
4- <b-input v-model =" value " @input =" handleInput" type =" number" step =" 0.001" min =" 0" />
4+ <b-input v-model =" inputValue " @input =" handleInput" type =" number" step =" 0.001" min =" 0" />
55 <p class =" control balance" >
6- <b-select v-model =" selectedUnit" @input =" handleInput" >
6+ <b-select :disabled = " !calculate " v-model =" selectedUnit" @input =" handleInput" >
77 <option v-for =" u in units" v-bind:key =" u.value" v-bind:value =" u.value" >
88 {{ u.name }}
99 </option >
1414</template >
1515
1616<script lang="ts" >
17- import { Component , Prop , Vue , Watch , Emit } from ' vue-property-decorator' ;
17+ import { Component , Prop , Vue , Watch , Emit , Mixins } from ' vue-property-decorator' ;
1818import Balance from ' @/params/components/Balance.vue' ;
1919import { units as defaultUnits } from ' @/params/constants' ;
2020import { Unit } from ' @/params/types' ;
2121import shouldUpdate from ' @/utils/shouldUpdate' ;
2222import { Debounce } from ' vue-debounce-decorator' ;
23+ import ChainMixin from ' @/utils/mixins/chainMixin' ;
2324
2425const components = { Balance }
2526
@@ -28,27 +29,27 @@ type BalanceType = {
2829}
2930
3031@Component ({ components })
31- export default class BalanceInput extends Vue {
32- private value : number = 0 ;
32+ export default class BalanceInput extends Mixins ( ChainMixin ) {
33+ @ Prop ({ type: [ Number , String ], default: 0 }) value ! : number ;
3334 protected units: Unit [] = defaultUnits ;
3435 private selectedUnit: number = 1 ;
3536 @Prop ({ default: ' balance' }) public label! : string ;
37+ @Prop ({ default: true }) public calculate! : boolean ;
3638
37-
38- get chainProperties() {
39- return this .$store .getters .getChainProperties ;
39+ get inputValue(): number {
40+ return this .value ;
4041 }
4142
42- get decimals() : number {
43- return this .chainProperties . tokenDecimals
43+ set inputValue( value : number ) {
44+ this .handleInput ( value );
4445 }
4546
46- get unit( ): string {
47- return this .chainProperties . tokenSymbol
47+ formatSelectedValue( value : number ): number {
48+ return value * ( 10 ** this .decimals ) * this . selectedUnit
4849 }
4950
5051 get calculatedBalance() {
51- return this .value * ( 10 ** this .decimals ) * this . selectedUnit
52+ return this .formatSelectedValue ( this .inputValue )
5253 }
5354
5455 protected mapper(unit : Unit ) {
@@ -62,23 +63,10 @@ export default class BalanceInput extends Vue {
6263 this .units = defaultUnits .map (this .mapper );
6364 }
6465
65- // @Watch('$store.getters.getChainProperties.tokenSymbol')
66- // protected updateUnit(val: string, oldVal: string) {
67- // console.log('@Watch(unit)', val, oldVal)
68- // if (shouldUpdate(val, oldVal)) {
69- // this.units = defaultUnits.map(u => {
70- // if (u.name === '-') {
71- // return { ...u, name: val }
72- // }
73- // return u
74- // })
75- // }
76- // }
77-
7866 @Debounce (200 )
7967 @Emit (' input' )
80- public handleInput() {
81- return this .calculatedBalance ;
68+ public handleInput(value : number ) {
69+ return this .calculate ? this . formatSelectedValue ( value ) : value ;
8270 }
8371}
8472 </script >
0 commit comments