Skip to content

Commit

Permalink
feat: added p2p_order_cancel hook (#12273)
Browse files Browse the repository at this point in the history
  • Loading branch information
ameerul-deriv authored Dec 15, 2023
1 parent a39f3ae commit e3088ba
Showing 1 changed file with 41 additions and 0 deletions.
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;

1 comment on commit e3088ba

@vercel
Copy link

@vercel vercel bot commented on e3088ba Dec 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

deriv-app – ./

binary.sx
deriv-app.vercel.app
deriv-app-git-master.binary.sx
deriv-app.binary.sx

Please sign in to comment.