From 5bfe2fc381bb6ee252de7ad9eef130895e0170a4 Mon Sep 17 00:00:00 2001 From: avalkov Date: Tue, 16 Aug 2022 11:14:01 +0300 Subject: [PATCH] Integrate simplified schema fetching API --- .env-dev | 2 +- .../components/smart_contract/index.tsx | 4 +-- src/screens/account_details/utils.ts | 31 +++++-------------- 3 files changed, 10 insertions(+), 27 deletions(-) diff --git a/.env-dev b/.env-dev index 414ff83713..86a30d5858 100644 --- a/.env-dev +++ b/.env-dev @@ -5,7 +5,7 @@ PORT=3000 NEXT_PUBLIC_URL=http://localhost:3000 NEXT_PUBLIC_WS_CHAIN_URL=ws://34.123.153.6:26657/websocket NEXT_PUBLIC_CHAIN_STATUS=testnet -NEXT_PUBLIC_CONTRACTS_URL=http://localhost:3333 +NEXT_PUBLIC_CONTRACTS_URL=http://34.172.163.122:3333 NEXT_PUBLIC_RPC_URL=http://34.123.153.6:26657 # TODO: This can be fetched direclty from hasura NEXT_PUBLIC_CHAIN_ID=cudos-testnet-private-3 diff --git a/src/screens/account_details/components/smart_contract/index.tsx b/src/screens/account_details/components/smart_contract/index.tsx index 9d59232ab7..5d4162647a 100644 --- a/src/screens/account_details/components/smart_contract/index.tsx +++ b/src/screens/account_details/components/smart_contract/index.tsx @@ -42,7 +42,7 @@ const SmartContractInteraction = (props: ISmartContractInteractionProps) => { const newState: any = {}; if (props.querySchema) { - const querySchemaObj = JSON.parse(props.querySchema); + const querySchemaObj = props.querySchema; AddMissingTitles(querySchemaObj, ''); @@ -59,7 +59,7 @@ const SmartContractInteraction = (props: ISmartContractInteractionProps) => { } if (props.executeSchema) { - const executeSchemaObj = JSON.parse(props.executeSchema); + const executeSchemaObj = props.executeSchema; AddMissingTitles(executeSchemaObj, ''); diff --git a/src/screens/account_details/utils.ts b/src/screens/account_details/utils.ts index 339ee68f87..ab32707643 100644 --- a/src/screens/account_details/utils.ts +++ b/src/screens/account_details/utils.ts @@ -149,32 +149,15 @@ export const fetchCosmWasmInstantiation = async (address: string) => { }; export const fetchContractSchemasByAddress = async (address: string) => { - const fetchedSourcesSchemas = []; + const schemasTypes = ['query', 'execute']; + let fetchedSourcesSchemas = []; + try { - const { data } = await axios.get(`${process.env.NEXT_PUBLIC_CONTRACTS_URL}/contract-schemas?address=${address}`); - const sourcesSchemas = data.sources; - - await new Promise((resolve, _) => { - if (sourcesSchemas.length == 0) { - resolve({}); - return; - } - - sourcesSchemas.forEach((_, sourceIdx) => { - sourcesSchemas[sourceIdx].schemas.forEach(async (schema, schemaIdx) => { - const schemaResponse = await axios.get(`${process.env.NEXT_PUBLIC_CONTRACTS_URL}/schema?id=${schema.id}`); - sourcesSchemas[sourceIdx].schemas[schemaIdx].data = JSON.stringify(schemaResponse.data); - - fetchedSourcesSchemas.push(sourcesSchemas[sourceIdx].schemas[schemaIdx]); - - if (fetchedSourcesSchemas.length == sourcesSchemas.length) { - console.log('resolved'); - resolve({}); - } - }); - }); - }); + for (let i = 0; i < schemasTypes.length; i++) { + const { data } = await axios.get(`${process.env.NEXT_PUBLIC_CONTRACTS_URL}/schema?type=${schemasTypes[i]}&address=${address}`); + fetchedSourcesSchemas.push({ funcName: schemasTypes[i], data: data }); + } return fetchedSourcesSchemas; } catch (error) {