5858 required
5959 />
6060 <small
61- v-if =" contractAddress && existingAsset"
61+ v-if =" contractAddress && existingAsset && !addingToken "
6262 id =" token_with_this_symbol_exits"
6363 class =" text-danger form-text text-right"
6464 >{{ $t('pages.customToken.tokenExists') }}</small
9090 :disabled =" autofilled && !isSymbolEditable"
9191 />
9292 <small
93- v-if =" symbol && symbolError"
93+ v-if =" symbol && symbolError && !addingToken "
9494 id =" token_with_this_symbol_exits"
9595 class =" text-danger form-text text-right"
9696 >{{ symbolError }}</small
9999 <div class =" form-group" >
100100 <label for =" decimals" >{{ $t('pages.customToken.decimals') }}</label >
101101 <input
102- type =" text"
103- v-model =" decimals"
102+ type =" number"
103+ v-model.trim =" decimals"
104+ @keypress =" isNumber($event)"
104105 class =" form-control form-control-sm"
106+ :maxlength =" 2"
105107 id =" decimals"
106108 autocomplete =" off"
107109 required
@@ -139,6 +141,8 @@ import NavBar from '@/components/NavBar.vue'
139141import ChevronDownIcon from ' @/assets/icons/chevron_down.svg'
140142import ChevronUpIcon from ' @/assets/icons/chevron_up.svg'
141143import { DuplicateTokenSymbolError } from ' @liquality/error-parser/dist/src/LiqualityErrors/DuplicateTokenSymbolError'
144+ import { errorToLiqualityErrorString } from ' @liquality/error-parser/dist/src/utils'
145+ import { reportLiqualityError } from ' @liquality/error-parser'
142146
143147export default {
144148 components: {
@@ -156,7 +160,8 @@ export default {
156160 autofilled: false ,
157161 chainDropdownOpen: false ,
158162 isSymbolEditable: false ,
159- chainsWithFetchingTokenDetails: CHAINS_WITH_FETCH_TOKEN_DETAILS
163+ chainsWithFetchingTokenDetails: CHAINS_WITH_FETCH_TOKEN_DETAILS ,
164+ addingToken: false
160165 }
161166 },
162167 computed: {
@@ -178,9 +183,15 @@ export default {
178183 return null
179184 },
180185 canAdd () {
181- if (! this .symbol || ! this .name || ! this .chain || ! this .contractAddress || ! this .decimals )
186+ if (
187+ ! this .symbol ||
188+ ! this .name ||
189+ ! this .chain ||
190+ ! this .contractAddress ||
191+ this .decimals .length <= 0
192+ )
182193 return false
183- if (this .symbolError ) return false
194+ if (this .symbol && this . symbolError ) return false
184195
185196 return true
186197 },
@@ -204,31 +215,43 @@ export default {
204215 ]),
205216 async addToken () {
206217 if (! this .existingAsset ) {
207- // Add only if it does not already exist
208- await this .addCustomToken ({
209- network: this .activeNetwork ,
210- walletId: this .activeWalletId ,
211- chain: this .chain ,
212- contractAddress: this .contractAddress ,
213- name: this .name ,
214- symbol: this .symbol ,
215- decimals: Number (this .decimals )
216- })
218+ try {
219+ this .addingToken = true
220+ // Add only if it does not already exist
221+ await this .addCustomToken ({
222+ network: this .activeNetwork ,
223+ walletId: this .activeWalletId ,
224+ chain: this .chain ,
225+ contractAddress: this .contractAddress ,
226+ name: this .name ,
227+ symbol: this .symbol ,
228+ decimals: Number (this .decimals )
229+ })
217230
218- const isChainEnabledForNative = this .accountsData .find (
219- (account ) => account .chain === this .chain
220- )
231+ const isChainEnabledForNative = this .accountsData .find (
232+ (account ) => account .chain === this .chain
233+ )
234+
235+ if (! isChainEnabledForNative) {
236+ await this .enableChain ()
237+ }
221238
222- if (! isChainEnabledForNative) {
223- await this .enableChain ()
239+ await this .enableAssets ({
240+ network: this .activeNetwork ,
241+ walletId: this .activeWalletId ,
242+ assets: [this .symbol ]
243+ })
244+ this .$router .replace (' /settings/manage-assets' )
245+ } catch (error) {
246+ const liqualityErrorString = errorToLiqualityErrorString (error)
247+ reportLiqualityError (error)
248+ return {
249+ error: liqualityErrorString
250+ }
251+ } finally {
252+ this .addingToken = false
224253 }
225254 }
226- await this .enableAssets ({
227- network: this .activeNetwork ,
228- walletId: this .activeWalletId ,
229- assets: [this .symbol ]
230- })
231- this .$router .replace (' /settings/manage-assets' )
232255 },
233256 async enableChain () {
234257 await this .toggleBlockchain ({
@@ -305,6 +328,14 @@ export default {
305328 this .chainDropdownOpen = false
306329 this .resetFields ()
307330 this .fetchToken ()
331+ },
332+ isNumber (evt ) {
333+ const keysAllowed = [' 0' , ' 1' , ' 2' , ' 3' , ' 4' , ' 5' , ' 6' , ' 7' , ' 8' , ' 9' ]
334+ const keyPressed = evt .key
335+ // The Decimals field can only have 2 digits (0 - 99) and must be a number
336+ if (! keysAllowed .includes (keyPressed) || this .decimals .length == 2 ) {
337+ evt .preventDefault ()
338+ }
308339 }
309340 }
310341}
0 commit comments