Skip to content

Commit

Permalink
Fix: validate field in token approval forms before adding (#548)
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky authored Jul 20, 2023
1 parent 3d80428 commit c0ea985
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/components/schema/schemaForm/approve/Fa1Approve.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
placeholder="Token contract"
background-color="data"
:rules="rules.address"
maxlength="36"
>
</v-text-field>
<v-text-field
Expand Down
2 changes: 2 additions & 0 deletions src/components/schema/schemaForm/approve/Fa2Approve.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
placeholder="Token contract"
background-color="data"
:rules="rules.address"
maxlength="36"
>
</v-text-field>
<v-text-field
Expand All @@ -28,6 +29,7 @@
:rules="rules.address"
persistent-hint
hint="If you attached a wallet, its address will be pasted automatically"
maxlength="36"
>
</v-text-field>
<v-text-field
Expand Down
19 changes: 12 additions & 7 deletions src/components/schema/schemaForm/approve/TokenAddDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
<v-btn :value="typ.value" :key="typ.value" v-for="typ in tokenTypes" small>{{ typ.name }}</v-btn>
</v-btn-toggle>
</v-col>
<v-col class="pb-0 mb-0" v-if="selectedTokenType == 1">
<Fa1Approve v-model="fa1" :rules="rules"/>
</v-col>
<v-col class="pb-0 mb-0" v-else>
<Fa2Approve v-model="fa2" :rules="rules"/>
<v-col class="pb-0 mb-0" >
<v-form lazy-validation ref="form">
<Fa1Approve v-model="fa1" :rules="rules" v-if="selectedTokenType == 1"/>
<Fa2Approve v-model="fa2" :rules="rules" v-else/>
</v-form>
</v-col>
</v-row>
</v-card-text>
Expand Down Expand Up @@ -118,6 +118,9 @@ export default {
},
methods: {
addToken() {
if (!this.$refs.form.validate()) {
return
}
this.show = false;
if (!this.isEdit) {
if (this.selectedTokenType == 1) {
Expand Down Expand Up @@ -152,12 +155,14 @@ export default {
this.selectedTokenType = 1;
this.fa1 = {
tokenContract: '',
allowance: 0
allowance: 0,
valid: false
}
this.fa2 = {
tokenContract: '',
owner: '',
tokenId: 0
tokenId: 0,
valid: false
}
this.searchToken = null;
let account = Wallet.getLastUsedAccount();
Expand Down
6 changes: 4 additions & 2 deletions src/utils/tz.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ export function validateNat(value) {

export let validationRules = {
contract:[
v => (v && v.length == 36) || 'The length of the contract address is 36 characters',
v => (!!v) || 'Required field',
v => (v.length == 36) || 'The length of the contract address is 36 characters',
v => isKT1Address(v) || 'In this field you should write the address of the contract. It begins with KT.'
],
nat: [
Expand All @@ -161,7 +162,8 @@ export let validationRules = {
v => /^[0-9a-fA-F]*$/.test(v) || 'Only 0-9 and a-f are allowed',
],
address: [
v => (v && v.length == 36) || 'The length of the address is 36 characters',
v => (!!v) || 'Required field',
v => (v.length == 36) || 'The length of the address is 36 characters',
v => isAddress(v) || 'In this field you should write the address'
]
}
Expand Down

0 comments on commit c0ea985

Please sign in to comment.