import { useContracts } from "../../useContracts/useContracts"; import { useState } from "react"; import { doTransaction } from "../../../utils/transactions/transactions"; import { useWeb3Provider } from "../../useWeb3Provider/useWeb3Provider"; /** * A hook to transfer from an existing position (transfer) */ export const useTransfer = (positionId: number) => { const [recipient, setRecipient] = useState(""); const { account } = useWeb3Provider(); const { reliquary } = useContracts(); const transfer = async () => { try { if (!account || !recipient) { throw new Error("Account or recipient not set"); } const receipt = await doTransaction(() => reliquary.transferFrom(account, recipient, positionId) ); setRecipient(""); return receipt; } catch (e: any) { setRecipient(""); throw e; } }; return { recipient, setRecipient, transfer, }; };