Skip to content

Commit

Permalink
Adding support for invalidating cache for a request, and rest handler…
Browse files Browse the repository at this point in the history
…s for creating and getting tx status
  • Loading branch information
hide-on-bush-x committed Sep 30, 2022
1 parent 3cd23d2 commit f0b6afa
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
63 changes: 63 additions & 0 deletions src/common/rest/createTransaction/index.ts
@@ -0,0 +1,63 @@
import { useQueryClient } from 'react-query';
import { MethodMetadata, Parameter } from '..';
import { useMasaMutation, useRestCall } from '../../helpers/rest-calls';

const path = 'contracts/transaction';

const queryClient = useQueryClient()


export function useMethod({ body }: any) {
const { data, error, loading, getData } = useRestCall({
headers: Headers,
metadata,
body,
});

return { data, error, loading, getData };
}

export function useSimpleMethod({ pathParameters, body, settings }: any) {
const masaQuery = useMasaMutation(
'create-transaction',
{
pathParameters,
headers: Headers,
body,
metadata,
},
{ ...settings, onSuccess: () => {
queryClient.invalidateQueries(['get-transactions'])

}}
);
return masaQuery;
}

const parameters: Parameter[] = [
{
key: 1,
name: 'txId',
description: 'Transaction id',
required: 'yes',
default: '0x',
dataType: 'string',
},
{
key: 2,
name: 'type',
required: 'yes',
description: 'Transaction type',
default: 'Soulname mint',
dataType: 'string',
},
];

export const metadata: MethodMetadata = {
author: 'Hide on bush',
authorPicture: '',
description: 'Creates a transaction for watching its state',
name: path,
method: 'POST',
parameters: parameters,
};
37 changes: 37 additions & 0 deletions src/common/rest/getTransactions/index.ts
@@ -0,0 +1,37 @@
import { MethodMetadata } from '..';
import { Headers } from '../../helpers/axios';
import { useMasaQuery, useRestCall } from '../../helpers/rest-calls';

const path = '/contracts/transactions';

export function useMethod() {
const { data, error, loading, getData } = useRestCall({
headers: Headers,
metadata,
});
return { data, error, loading, getData };
}

export function useSimpleMethod({ pathParameters, body, settings }: any) {
const masaQuery = useMasaQuery(
'get-transactions',
{
pathParameters,
headers: Headers,
body,
metadata,
},
settings
);

return masaQuery;
}

export const metadata: MethodMetadata = {
author: 'Hide on bush',
authorPicture: '',
description: 'Get and refresh transactions',
name: path,
method: 'GET',
parameters: [],
};

0 comments on commit f0b6afa

Please sign in to comment.