diff --git a/src/components/wallet/wallet-address.tsx b/src/components/wallet/wallet-address.tsx index 12cf5a9..51b1d13 100644 --- a/src/components/wallet/wallet-address.tsx +++ b/src/components/wallet/wallet-address.tsx @@ -6,7 +6,7 @@ import { Controller, SubmitHandler, useForm } from "react-hook-form" import { CardBank, SendWithdraw } from "../../types" import { ErrorComponent } from "../common/error" import { useMutation, useQueryClient } from "@tanstack/react-query" -import { sendwithdraw } from "../../services/api/wallet" +import { cancelWithdraw, sendwithdraw } from "../../services/api/wallet" import toast from "react-hot-toast" import { handleError } from "../../utility/error-handle" import { Input } from "../common/input" @@ -25,6 +25,11 @@ export const WalletAddress: FC = ({ pending, walletBalance }) => { mutationKey: ["withdraw"] }) + const { mutate: cancelWithdrawMutation, isPending: isCancelPending } = useMutation({ + mutationFn: cancelWithdraw, + mutationKey: ["cancel-withdraw"] + }) + const [price, setPrice] = useState('') const { handleSubmit, formState: { errors }, control, watch } = useForm({ }) @@ -86,8 +91,20 @@ export const WalletAddress: FC = ({ pending, walletBalance }) => { } } } + + const handleCancelWithdraw = async () => { + await cancelWithdrawMutation(undefined, { + onSuccess: () => { + toast.success("درخواست برداشت با موفقیت لغو شد") + queryClient.invalidateQueries({ queryKey: ["wallet"] }) + setPrice('') + }, + onError: (err: any) => handleError(err) + }) + } + return ( -
+
wallet
diff --git a/src/services/api/wallet.ts b/src/services/api/wallet.ts index 8ceefc6..4f88466 100644 --- a/src/services/api/wallet.ts +++ b/src/services/api/wallet.ts @@ -1,6 +1,10 @@ - import axiosInstance from "../axios"; import { OverviewResponse } from "./overview"; -export const getWalletDetails = () => axiosInstance.get("/gps/overview/wallet") -export const sendwithdraw = (payload: any) => axiosInstance.post("/gps/withdraw", payload) +export const getWalletDetails = () => + axiosInstance.get( + "/gps/overview/wallet" + ); +export const sendwithdraw = (payload: any) => + axiosInstance.post("/gps/withdraw", payload); +export const cancelWithdraw = () => axiosInstance.delete("/gps/withdraw");