UNPKG

react-native-unit-components

Version:

Unit React Native components

173 lines (172 loc) 6.93 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.resetHtml = exports.renderingBottomSheetRequest = exports.injectHtmlFullScreenHeight = exports.getNativeComponentDataFromEvent = exports.getBottomSheetScript = void 0; var _bodyScript = require("./../../scripts/html/bodyScript"); var _bodyHtml = require("../../scripts/html/bodyHtml"); var _bottomSheet = require("../../types/internal/bottomSheet.types"); var _webComponent = require("../../types/internal/webComponent.types"); const getBottomSheetScript = () => { return _bodyScript.LISTENERS.requestRefresh; }; exports.getBottomSheetScript = getBottomSheetScript; const renderingBottomSheetRequest = (currentWebView, renderingRequest) => { currentWebView?.injectJavaScript(` document.activeElement && document.activeElement.blur(); dispatchRenderingEvent('${JSON.stringify(renderingRequest.data)}'); `); }; exports.renderingBottomSheetRequest = renderingBottomSheetRequest; const resetHtml = currentWebView => { currentWebView?.injectJavaScript(` document.activeElement && document.activeElement.blur(); document.getElementById('${_bodyHtml.webViewId}').style.height = null; `); }; exports.resetHtml = resetHtml; const injectHtmlFullScreenHeight = (currentWebView, bottomSheetHeight) => { currentWebView && currentWebView?.injectJavaScript(` document.getElementById('${_bodyHtml.webViewId}').style.height = '${bottomSheetHeight}px'; `); }; exports.injectHtmlFullScreenHeight = injectHtmlFullScreenHeight; const getParamsFromRequestRenderingEvent = event => { const eventString = event.data.nativeComponent; const componentName = event.data.nativeComponentName; const regexStringParams = `(<${componentName})(.*?)(><\\/${componentName}>)`; const regexParams = new RegExp(regexStringParams); const matchParams = eventString?.match(regexParams); if (matchParams && matchParams[2]) { return matchParams[2]; } return null; }; const extractValueFromRequestRenderingEvent = (event, key) => { const paramsString = getParamsFromRequestRenderingEvent(event); const regexString = `${key}=([^\\ \\s]+)`; const regex = new RegExp(regexString); const match = paramsString?.match(regex); if (match && match[1]) { return match[1]; } else { return undefined; } }; const getAddToWalletComponentDataFromEvent = (event, customerToken) => { const cardId = event.componentResourceId ?? extractValueFromRequestRenderingEvent(event.requestRenderingEvent, 'card-id'); if (!cardId) { console.error('componentResourceId is missing in getAddToWalletComponentDataFromEvent and no cardId in requestRenderingEvent'); return null; } return { type: _bottomSheet.BottomSheetNativeComponentType.AddToWalletComponent, props: { cardId: cardId, customerToken: customerToken } }; }; const getACHCreditComponentDataFromEvent = (event, customerToken) => { const accountId = extractValueFromRequestRenderingEvent(event.requestRenderingEvent, 'account-id'); if (!accountId) { console.error('accountId is missing in getACHCreditComponentDataFromEvent'); return null; } return { type: _bottomSheet.BottomSheetNativeComponentType.ACHCreditComponent, props: { accountId: accountId, customerToken: customerToken } }; }; const getACHDebitComponentDataFromEvent = (event, customerToken) => { const accountId = extractValueFromRequestRenderingEvent(event.requestRenderingEvent, 'account-id'); if (!accountId) { console.error('accountId is missing in getACHDebitComponentDataFromEvent'); return null; } return { type: _bottomSheet.BottomSheetNativeComponentType.ACHDebitComponent, props: { accountId: accountId, customerToken: customerToken } }; }; const getCheckDepositComponentDataFromEvent = (event, customerToken) => { const accountId = extractValueFromRequestRenderingEvent(event.requestRenderingEvent, 'account-id'); const fee = extractValueFromRequestRenderingEvent(event.requestRenderingEvent, 'fee'); if (!accountId || !fee) { console.error('accountId or fee is missing in getCheckDepositComponentDataFromEvent'); return null; } return { type: _bottomSheet.BottomSheetNativeComponentType.CheckDepositComponent, props: { accountId: accountId, fee: parseInt(fee), customerToken: customerToken } }; }; const getBookPaymentComponentDataFromEvent = (event, customerToken) => { const accountId = extractValueFromRequestRenderingEvent(event.requestRenderingEvent, 'account-id'); const counterPartyAccountId = extractValueFromRequestRenderingEvent(event.requestRenderingEvent, 'counterparty-account-id'); const counterPartyName = extractValueFromRequestRenderingEvent(event.requestRenderingEvent, 'counterparty-name'); if (!accountId) { console.error('accountId is missing in getBookPaymentComponentDataFromEvent'); return null; } return { type: _bottomSheet.BottomSheetNativeComponentType.BookPaymentComponent, props: { accountId: accountId, counterPartyAccountId: counterPartyAccountId, counterPartyName: counterPartyName, customerToken: customerToken } }; }; const getNativeComponentDataFromEvent = event => { let componentData = null; let nativePlace = _bottomSheet.BottomSheetNativePlaceType.modal; const requestRenderingEventData = event.requestRenderingEvent.data; const customerToken = extractValueFromRequestRenderingEvent(event.requestRenderingEvent, 'customer-token'); if (!customerToken) { console.error('customerToken is missing in getNativeComponentDataFromEvent'); return null; } switch (requestRenderingEventData.nativeComponentName) { case _webComponent.WebComponentType.cardAction: if (requestRenderingEventData.nativeComponent?.includes('action=AddToWallet')) { nativePlace = _bottomSheet.BottomSheetNativePlaceType.overFullScreen; componentData = getAddToWalletComponentDataFromEvent(event, customerToken); } break; case _webComponent.WebComponentType.achCreditPayment: componentData = getACHCreditComponentDataFromEvent(event, customerToken); break; case _webComponent.WebComponentType.achDebitPayment: componentData = getACHDebitComponentDataFromEvent(event, customerToken); break; case _webComponent.WebComponentType.checkDeposit: componentData = getCheckDepositComponentDataFromEvent(event, customerToken); break; case _webComponent.WebComponentType.bookPayment: componentData = getBookPaymentComponentDataFromEvent(event, customerToken); break; default: break; } if (!componentData) { return null; } return { component: componentData, nativePlace: nativePlace }; }; exports.getNativeComponentDataFromEvent = getNativeComponentDataFromEvent; //# sourceMappingURL=UNBottomSheetComponent.utils.js.map