@saberhq/sail
Version:
Account caching and batched loading for React-based Solana applications.
26 lines • 1.21 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.useTXHandlers = void 0;
const react_1 = require("react");
const errors_1 = require("../errors/errors");
const provider_1 = require("../provider");
const useTXHandlers = () => {
const { handleTX, handleTXs } = (0, provider_1.useSail)();
const signAndConfirmTX = (0, react_1.useCallback)(async (txEnv, msg, options) => {
const { pending, success, errors } = await handleTX(txEnv, msg, options);
if (!pending || !success) {
throw new errors_1.SailSignAndConfirmError(errors);
}
return await pending.wait({ useWebsocket: true });
}, [handleTX]);
const signAndConfirmTXs = (0, react_1.useCallback)(async (txEnvs, msg, options) => {
const { pending, success, errors } = await handleTXs(txEnvs, msg, options);
if (!pending || !success) {
throw new errors_1.SailSignAndConfirmError(errors);
}
return await Promise.all(pending.map((p) => p.wait({ useWebsocket: true })));
}, [handleTXs]);
return { signAndConfirmTX, signAndConfirmTXs };
};
exports.useTXHandlers = useTXHandlers;
//# sourceMappingURL=useConfirmTXs.js.map
;