Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEQ] Ameerul / FEQ-1000 / P2P Order Cancel Hook #12273

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions packages/api/src/hooks/p2p/useOrderCancel.ts
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;