UNPKG

@circle-apps/sdk

Version:

Official SDK for Celia Mini Apps integration

51 lines (50 loc) 3.37 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.useCeliaSDK = useCeliaSDK; const react_1 = require("react"); const CeliaSDKContext_1 = require("../contexts/CeliaSDKContext"); function useCeliaSDK() { const context = (0, react_1.useContext)(CeliaSDKContext_1.CeliaSDKContext); // Memoized convenience methods for banner ads const showBannerAd = (0, react_1.useCallback)((options) => __awaiter(this, void 0, void 0, function* () { if (!(context === null || context === void 0 ? void 0 : context.sdk)) { throw new Error('CeliaSDK is not initialized'); } return context.sdk.showBannerAd(options); }), [context === null || context === void 0 ? void 0 : context.sdk]); const hideBannerAd = (0, react_1.useCallback)((containerId) => __awaiter(this, void 0, void 0, function* () { if (!(context === null || context === void 0 ? void 0 : context.sdk)) { throw new Error('CeliaSDK is not initialized'); } return context.sdk.hideBannerAd({ containerId }); }), [context === null || context === void 0 ? void 0 : context.sdk]); const showAd = (0, react_1.useCallback)((options) => __awaiter(this, void 0, void 0, function* () { if (!(context === null || context === void 0 ? void 0 : context.sdk)) { throw new Error('CeliaSDK is not initialized'); } return context.sdk.showAd(options); }), [context === null || context === void 0 ? void 0 : context.sdk]); return (0, react_1.useMemo)(() => { var _a, _b; return ({ sdk: (context === null || context === void 0 ? void 0 : context.sdk) || null, isLoading: !((_a = context === null || context === void 0 ? void 0 : context.sdk) === null || _a === void 0 ? void 0 : _a.isInitialized), isReady: ((_b = context === null || context === void 0 ? void 0 : context.sdk) === null || _b === void 0 ? void 0 : _b.isInitialized) || false, error: (context === null || context === void 0 ? void 0 : context.error) || null, isWebView: (context === null || context === void 0 ? void 0 : context.isWebView) || false, language: (context === null || context === void 0 ? void 0 : context.language) || null, showBannerAd, hideBannerAd, showAd, }); }, [context === null || context === void 0 ? void 0 : context.sdk, context === null || context === void 0 ? void 0 : context.error, context === null || context === void 0 ? void 0 : context.isWebView, context === null || context === void 0 ? void 0 : context.language, showBannerAd, hideBannerAd, showAd]); }