diff --git a/src/modules/[chain]/cosmwasm/WasmStore.ts b/src/modules/[chain]/cosmwasm/WasmStore.ts index 515053ea..74f0180a 100644 --- a/src/modules/[chain]/cosmwasm/WasmStore.ts +++ b/src/modules/[chain]/cosmwasm/WasmStore.ts @@ -27,6 +27,7 @@ export interface WasmRequestRegistry extends AbstractRegistry { cosmwasm_contract_address_raw_query_data: Request; cosmwasm_contract_address_smart_query_data: Request; cosmwasm_contract_address_state: Request; + cosmwasm_wasm_contracts_creator: Request; } export const DEFAULT: WasmRequestRegistry = { @@ -57,6 +58,10 @@ export const DEFAULT: WasmRequestRegistry = { url: '/cosmwasm/wasm/v1/contract/{address}/state', adapter, }, + cosmwasm_wasm_contracts_creator: { + url: '/cosmwasm/wasm/v1/contracts/creator/{creator_address}', + adapter, + }, }; class WasmRestClient extends BaseRestClient { @@ -79,6 +84,11 @@ class WasmRestClient extends BaseRestClient { getWasmContracts(address: string) { return this.request(this.registry.cosmwasm_contract_address, { address }); } + getWasmContractsByCreator(creator_address: string, page?: PageRequest) { + if(!page) page = new PageRequest() + const query = `?${page.toQueryString()}` + return this.request(this.registry.cosmwasm_wasm_contracts_creator, { creator_address }, query); + } getWasmContractHistory(address: string) { return this.request(this.registry.cosmwasm_contract_address_history, { address, diff --git a/src/modules/[chain]/cosmwasm/[code_id]/contracts.vue b/src/modules/[chain]/cosmwasm/[code_id]/contracts.vue index 0119a7d9..54d603b4 100644 --- a/src/modules/[chain]/cosmwasm/[code_id]/contracts.vue +++ b/src/modules/[chain]/cosmwasm/[code_id]/contracts.vue @@ -21,9 +21,20 @@ const wasmStore = useWasmStore(); function loadContract(pageNum: number) { const pr = new PageRequest(); pr.setPage(pageNum); - wasmStore.wasmClient.getWasmCodeContracts(props.code_id, pr).then((x) => { - response.value = x; - }); + if(String(props.code_id).search(/^[\d]+$/) > -1){ + // query with code id + wasmStore.wasmClient.getWasmCodeContracts(props.code_id, pr).then((x) => { + response.value = x; + }) + } else { + // query by creator + wasmStore.wasmClient.getWasmContractsByCreator(props.code_id, pr).then((x) => { + response.value = { + contracts: x.contract_addresses, + pagination: x.pagination, + }; + }) + } } loadContract(1); diff --git a/src/modules/[chain]/cosmwasm/index.vue b/src/modules/[chain]/cosmwasm/index.vue index 5b4a0da5..8644408b 100644 --- a/src/modules/[chain]/cosmwasm/index.vue +++ b/src/modules/[chain]/cosmwasm/index.vue @@ -5,6 +5,7 @@ import { ref } from 'vue'; import type { PaginabledCodeInfos } from './types'; import { PageRequest } from '@/types'; import PaginationBar from '@/components/PaginationBar.vue'; +import router from '@/router'; const props = defineProps(['chain']); @@ -13,6 +14,7 @@ const codes = ref({} as PaginabledCodeInfos); const pageRequest = ref(new PageRequest()) const wasmStore = useWasmStore(); const dialog = useTxDialog() +const creator = ref("") function pageload(pageNum: number) { pageRequest.value.setPage(pageNum) @@ -21,10 +23,19 @@ function pageload(pageNum: number) { }); } pageload(1) + +function myContracts() { + router.push(`/${props.chain}/cosmwasm/${creator.value}/contracts`) +}