add query from ibc

This commit is contained in:
liangping 2023-03-03 16:12:34 +08:00
parent c712a0da46
commit c8b52f99db

View File

@ -2,12 +2,27 @@
<div> <div>
<b-card title="Query NFT"> <b-card title="Query NFT">
<b-form-group> <b-form-group>
<b-form-radio-group
v-if="isWasm"
v-model="keyType"
:aria-describedby="ariaDescribedby"
name="radio-sub-component"
>
<b-form-radio value="contract">
Search By Contract ID
</b-form-radio>
<b-form-radio value="ibc">
Search From IBC Path
</b-form-radio>
</b-form-radio-group>
<b-form-input <b-form-input
v-if="isWasm" v-if="isWasm"
v-model="contractId" v-model="contractId"
placeholder="Wasm Contract Id: e.g. stars1y26zydcynhdz3t93wzsx4ww9nh9fz9gup6s5k45jqn7nsl36kefsdhdnvv" class="my-1"
:placeholder="`Wasm Contract Id: e.g. ${sample}`"
/> />
<b-form-input <b-form-input
v-if="!isWasm || keyType==='contract'"
v-model="tokenId" v-model="tokenId"
placeholder="Token ID, e.g. mynft" placeholder="Token ID, e.g. mynft"
/> />
@ -30,13 +45,15 @@
<script> <script>
import { import {
BCard, BFormGroup, BFormInput, BButton, BCard, BFormGroup, BFormInput, BButton, BFormRadioGroup, BFormRadio,
} from 'bootstrap-vue' } from 'bootstrap-vue'
import ObjectFieldComponent from './components/ObjectFieldComponent' import ObjectFieldComponent from './components/ObjectFieldComponent'
export default { export default {
components: { components: {
BButton, BButton,
BFormRadio,
BFormRadioGroup,
BCard, BCard,
BFormGroup, BFormGroup,
BFormInput, BFormInput,
@ -47,6 +64,7 @@ export default {
data: {}, data: {},
contractId: '', contractId: '',
tokenId: '', tokenId: '',
keyType: 'contract',
} }
}, },
computed: { computed: {
@ -56,6 +74,11 @@ export default {
isWasm() { isWasm() {
return ['juno', 'stargaze'].includes(this.chainName) return ['juno', 'stargaze'].includes(this.chainName)
}, },
sample() {
return this.keyType === 'contract'
? 'stars1y26zydcynhdz3t93wzsx4ww9nh9fz9gup6s5k45jqn7nsl36kefsdhdnvv'
: 'wasm.stars1ve46fjrhcrum94c7d8yc2wsdz8cpuw73503e8qn9r44spr6dw0lsvmvtqh/channel-207/denom'
},
}, },
mounted() { mounted() {
const { denom } = this.$route.params const { denom } = this.$route.params
@ -68,10 +91,26 @@ export default {
methods: { methods: {
fetchWasmNFT() { fetchWasmNFT() {
if (this.isWasm) { if (this.isWasm) {
this.$http.getWasmQuery(this.contractId, `{"all_nft_info":{"token_id": "${this.tokenId}"}}`) if (this.keyType === 'contract') {
.then(res => { this.$http.getWasmQuery(this.contractId, `{"all_nft_info":{"token_id": "${this.tokenId}"}}`)
this.data = res .then(res => {
}) this.data = res.data
})
} else {
const keys = this.contractId.split('/')
if (keys.length === 3) {
const contractId = keys[0].replace('wasm.', '')
const query = `{"nft_contract": {"class_id" : "${this.contractId}"}}`
this.$http.getWasmQuery(contractId, query)
.then(contract => {
const tokenId = keys[2]
this.$http.getWasmQuery(contract.data, `{"all_nft_info":{"token_id": "${tokenId}"}}`)
.then(res => {
this.data = res.data
})
})
}
}
} else { } else {
this.$http.getNFTDenom(this.tokenId).then(res => { this.$http.getNFTDenom(this.tokenId).then(res => {
this.data = res.denom this.data = res.denom