-
Notifications
You must be signed in to change notification settings - Fork 303
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f3020d6
commit 79a6d20
Showing
1 changed file
with
41 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,41 @@ | ||
import { useCallback } from 'react'; | ||
import useMutation from '../../useMutation'; | ||
import useInvalidateQuery from '../../useInvalidateQuery'; | ||
|
||
type TOrderCancelPayload = NonNullable< | ||
Parameters<ReturnType<typeof useMutation<'p2p_order_cancel'>>['mutate']> | ||
>[0]['payload']; | ||
|
||
/** A custom hook that cancels a P2P order. | ||
* | ||
* To cancel an order, specify the following payload arguments in the `mutate` call: | ||
* @example | ||
* mutate({ | ||
* id: "1234", | ||
}); | ||
* | ||
*/ | ||
const useOrderCancel = () => { | ||
const invalidate = useInvalidateQuery(); | ||
const { | ||
data, | ||
mutate: _mutate, | ||
...rest | ||
} = useMutation('p2p_order_cancel', { | ||
onSuccess: () => { | ||
invalidate('p2p_order_info'); | ||
}, | ||
}); | ||
|
||
const mutate = useCallback((payload: TOrderCancelPayload) => _mutate({ payload }), [_mutate]); | ||
|
||
return { | ||
/** An object that contains the id and status of the order */ | ||
data: data?.p2p_order_cancel, | ||
/** A function that cancels a specific order */ | ||
mutate, | ||
...rest, | ||
}; | ||
}; | ||
|
||
export default useOrderCancel; |