UNPKG

@saberhq/sail

Version:

Account caching and batched loading for React-based Solana applications.

22 lines 1.02 kB
import { useCallback } from "react"; import { SailSignAndConfirmError } from "../errors/errors"; import { useSail } from "../provider"; export const useTXHandlers = () => { const { handleTX, handleTXs } = useSail(); const signAndConfirmTX = useCallback(async (txEnv, msg, options) => { const { pending, success, errors } = await handleTX(txEnv, msg, options); if (!pending || !success) { throw new SailSignAndConfirmError(errors); } return await pending.wait({ useWebsocket: true }); }, [handleTX]); const signAndConfirmTXs = useCallback(async (txEnvs, msg, options) => { const { pending, success, errors } = await handleTXs(txEnvs, msg, options); if (!pending || !success) { throw new SailSignAndConfirmError(errors); } return await Promise.all(pending.map((p) => p.wait({ useWebsocket: true }))); }, [handleTXs]); return { signAndConfirmTX, signAndConfirmTXs }; }; //# sourceMappingURL=useConfirmTXs.js.map