UNPKG

react-native-unit-components

Version:

Unit React Native components

47 lines (40 loc) 2.29 kB
import { DISPATCH_REQUEST_REFRESH } from './../../scripts/html/bodyScript'; import type WebView from 'react-native-webview'; import type { UNCardComponentProps } from './UNCardComponent'; import type { RequestRefreshEvent } from '../../messages/webMessages/unitMessages'; import type { UNCardMenuAction } from '../../types/shared'; import { WebComponentType } from '../../types/internal/webComponent.types'; import { UnitSDK } from '../../unitSdkManager/UnitSdkManager'; export const getCardParams = (props: UNCardComponentProps) => { const menuItemsParam = props.menuItems ? `menu-items="${props.menuItems.join()}"` : ''; return ` card-id="${props.cardId}" customer-token="${props.customerToken}" enable-mobile-wallet="${!!(props.pushProvisioningModule || UnitSDK.getPushProvisionModule())}" hide-actions-menu-button="${props.hideActionsMenuButton || false}" hide-card-title="${props.hideCardTitle || false}" hide-sensitive-data-button="${props.hideSensitiveDataButton || false}" learn-more-url="${props.learnMoreUrl || ''}" ${menuItemsParam} `; }; export const getCardScript = () => { return DISPATCH_REQUEST_REFRESH; }; export const injectOpenActionsMenuScript = (currentWeb: WebView | null) => { currentWeb?.injectJavaScript(`dispatchOpenActionsMenu('${WebComponentType.card}')`); }; export const injectRequestCardActionScript = (currentWeb: WebView | null, action: UNCardMenuAction) => { currentWeb?.injectJavaScript(`dispatchRequestCardAction('${action}')`); }; export const injectRequestHideSensitiveDataScript = (currentWeb: WebView | null) => { currentWeb?.injectJavaScript(`dispatchRequestHideSensitiveData('${WebComponentType.card}')`); }; export const injectRequestShowSensitiveDataScript = (currentWeb: WebView | null) => { currentWeb?.injectJavaScript(`dispatchRequestShowSensitiveData('${WebComponentType.card}')`); }; export const injectRefreshEventIfNeeded = (currentWeb: WebView | null, requestRefreshEvent: RequestRefreshEvent | null, cardId: string) => { if (requestRefreshEvent && requestRefreshEvent.dependencies.includes(WebComponentType.card.valueOf()) && requestRefreshEvent.resourceId == cardId) { currentWeb?.injectJavaScript(`dispatchRefreshEvent('${JSON.stringify(requestRefreshEvent)}')`); } };