UNPKG

@habit.analytics/habit-smartlink-reactcomponent

Version:

A React component for Habit SmartLink integration.

30 lines (29 loc) 1.95 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var jsx_runtime_1 = require("react/jsx-runtime"); var react_1 = require("react"); var helpers_1 = require("./helpers"); var useSmartlinkComponent_1 = __importDefault(require("./useSmartlinkComponent")); var SmartlinkComponent = function (_a) { var hash = _a.hash, pin = _a.pin, prePaymentMethod = _a.prePaymentMethod, _b = _a.onPaymentSuccess, onPaymentSuccess = _b === void 0 ? function (successPaymentData) { } : _b, env = _a.env, customStyle = _a.customStyle; var _c = (0, useSmartlinkComponent_1.default)(prePaymentMethod, onPaymentSuccess, env), iframeRef = _c.iframeRef, sendMessageToIframe = _c.sendMessageToIframe, enviroment = _c.enviroment, rectangle = _c.rectangle; var iframeBaseUrl = helpers_1.SMARTLINK_BASE_URL[enviroment]; var iframeSrc = (0, helpers_1.assembleURLWithOriginHashAndPin)(iframeBaseUrl, hash, pin); var _d = rectangle !== null && rectangle !== void 0 ? rectangle : {}, width = _d.width, height = _d.height; (0, react_1.useEffect)(function () { var timer = setTimeout(function () { sendMessageToIframe("ping"); }, 1000); return function () { return clearTimeout(timer); }; }, [sendMessageToIframe]); return ((0, jsx_runtime_1.jsx)("div", { style: { position: "relative" }, children: (0, jsx_runtime_1.jsx)("iframe", { id: "paymentIframe", ref: iframeRef, src: iframeSrc, title: "smart component", style: customStyle ? customStyle : { width: "".concat((width !== null && width !== void 0 ? width : 328) + 16, "px"), height: "".concat((height !== null && height !== void 0 ? height : 650) + 8, "px"), } }) })); }; exports.default = SmartlinkComponent;