import { skipToken } from "@reduxjs/toolkit/dist/query"; import { Row, Col, notification } from "antd"; import React, { useState, FC, Fragment } from "react"; import { Link, Navigate, useNavigate, useParams, useSearchParams } from "react-router-dom"; import AddButton from "../components/Button/AddButton"; import CustomInput from "../components/Input/CustomInput"; import LoadingDots from "../components/Loading/LoadingDots"; import { isErrorWithMessage, isFetchBaseQueryError } from "../components/types"; import { useRefundWalletMutation, useRequestRefundQuery, } from "../services/checkout-service"; import { PublicKey } from "@solana/web3.js"; const RefundForm: FC = () => { const [walletAddress, setWalletAddress] = useState(""); const { id } = useParams<{ id: string }>(); const [loading, setLoading] = useState(false); const { data, error, isFetching, isLoading, isSuccess } = useRequestRefundQuery(id ?? skipToken); const [refundWallet] = useRefundWalletMutation(); const navigate = useNavigate(); const [searchParams] = useSearchParams(); const refundType = searchParams.get("type"); console.log(refundType) function validateWalletAddress(e: any) { try { const value = e.target.value; const isValid: boolean = PublicKey.isOnCurve(value); isValid ? setWalletAddress(value) : setWalletAddress(null); } catch (err) { console.log(err); setWalletAddress(null); } } async function onConfirm() { if (!walletAddress || walletAddress.length < 1) return notification.error({ message: "Please ensure you insert your Solana wallet address", }); setLoading(true); let data = { address: walletAddress, }; try { await refundWallet({ data: data, ref: id, }).unwrap(); navigate("/payment-status", { replace: true, state: { refund: true, status: true, }, }); //setShowSuccess(true); } catch (err) { console.log(err); if (isFetchBaseQueryError(err)) { const errMsg = //@ts-ignore "error" in err ? err.error : JSON.stringify(err.data?.message); notification.error({ message: errMsg, }); } else if (isErrorWithMessage(err)) { console.log(err); } } setLoading(false); } const customer = data?.data?.customer; const transaction = data?.data?.transaction; return ( {isLoading || isFetching ? ( ) : data ? (

Refund form

Amount paid: {transaction?.receivedAmountInCrypto}{" "} {transaction.crypto}


{walletAddress === null && ( Enter a valid Solana address )}
0 ? transaction?.excessAmountReceivedInCrypto : transaction?.receivedAmountInCrypto } ${transaction.crypto}`} /> Please note that you would not be refunded the transaction fee for the initial transaction.
Submit
{" "}
Powered by Ivorypay

For questions and enquiries, please contact:

support@ivorypay.io
) : ( )}
); }; export default RefundForm;