Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding support for invalidating cache for a request, and rest handler…
…s for creating and getting tx status
- Loading branch information
1 parent
3cd23d2
commit f0b6afa
Showing
2 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: [], | ||
}; |