Skip to content

Commit

Permalink
✨ Add receiver address check
Browse files Browse the repository at this point in the history
  • Loading branch information
lancatlin committed Aug 18, 2022
1 parent 6f8cd37 commit d1dba7f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
26 changes: 16 additions & 10 deletions pages/transfer/_id.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
<p>{{ contentMetadata.name }}</p>
<label>Transfer to:
<input v-model="receiver" type="text" size="40">
<p v-if="receiver && !validateAddress" class="error">Invalid receiver address</p>
<br v-else>
</label>
<button class="button" @click="transfer">
<button class="button" :disabled="!validateAddress" @click="transfer">
Transfer
</button>
<p v-if="isSending">
Expand All @@ -29,14 +31,15 @@
{{ txHash }}
</a>
</p>
<p v-if="error">
<p v-if="error" class="error">
{{ error }}
</p>
</div>
</template>

<script>
import { mapState } from 'vuex'
import { validateAddress } from '@/utils/utils'
import { INDEXER } from '@/config'
export default {
Expand All @@ -49,21 +52,24 @@ export default {
INDEXER,
}),
async fetch () {
this.iscnId = this.$route.params.id
const res = await this.$axios.$get(`/iscn/records?iscn_id=${this.iscnId}`)
const record = res.records[0].data
Object.assign(this, record)
this.contentMetadata.keywords = record.contentMetadata.keywords.split(',').filter(k => k !== '')
},
computed: {
...mapState('wallet', {
walletAddress: state => state.walletAddress,
txHash: state => state.txHash,
isSending: state => state.isSending,
error: state => state.error,
}),
},
async fetch () {
this.iscnId = this.$route.params.id
const res = await this.$axios.$get(`/iscn/records?iscn_id=${this.iscnId}`)
const record = res.records[0].data
Object.assign(this, record)
this.contentMetadata.keywords = record.contentMetadata.keywords.split(',').filter(k => k !== '')
validateAddress () {
return validateAddress(this.receiver)
},
},
methods: {
Expand Down
6 changes: 6 additions & 0 deletions utils/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export function validateAddress (addr) {
console.log(addr)
if (addr.startsWith('cosmos1')) { return addr.length === 45 }
if (addr.startsWith('like1')) { return addr.length === 43 }
return false
}

0 comments on commit d1dba7f

Please sign in to comment.