Skip to content

Commit

Permalink
Integrate simplified schema fetching API
Browse files Browse the repository at this point in the history
  • Loading branch information
avalkov committed Aug 16, 2022
1 parent 7ee335f commit 5bfe2fc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .env-dev
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, '');

Expand All @@ -59,7 +59,7 @@ const SmartContractInteraction = (props: ISmartContractInteractionProps) => {
}

if (props.executeSchema) {
const executeSchemaObj = JSON.parse(props.executeSchema);
const executeSchemaObj = props.executeSchema;

AddMissingTitles(executeSchemaObj, '');

Expand Down
31 changes: 7 additions & 24 deletions src/screens/account_details/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 5bfe2fc

Please sign in to comment.