import WebView from 'react-native-webview'; import { RequestRefreshEvent } from '../../messages/webMessages/unitComponentsMessages'; import { UNWhiteLabelAppComponentProps } from './UNWhiteLabelAppComponent'; import { DISPATCH_ACCOUNT_CREATION_ACTIONS_OPEN_PLAID_FOR_LINK_EXTERNAL_ACCOUNT, DISPATCH_OPEN_PLAID, DISPATCH_PLAID_EXIT, DISPATCH_PLAID_RESPONSE, DISPATCH_REQUEST_REFRESH, LISTENERS } from '../../scripts/html/bodyScript'; import { UNCard } from '../../types/shared'; export const getWhiteLabelAppParams = (props: UNWhiteLabelAppComponentProps) => { // customer token is the preferred way to authenticate if (props.customerToken) { return ` customer-token="${props.customerToken}" `; } if (props.jwtToken) { return ` jwt-token="${props.jwtToken}" `; } return ''; }; export const injectRefreshEventIfNeeded = (currentWeb: WebView | null, requestRefreshEvent: RequestRefreshEvent | null) => { if (requestRefreshEvent) { currentWeb?.injectJavaScript(`dispatchRefreshEvent('${JSON.stringify(requestRefreshEvent)}')`); } }; export const injectAccountCreationActionsOpenPlaidForLinkExternalAccount = (currentWeb: WebView | null) => { currentWeb?.injectJavaScript('dispatchAccountCreationActionsOpenPlaidForLinkExternalAccount()'); }; export const injectCardCreated = (currentWeb: WebView | null, card: UNCard) => { currentWeb?.injectJavaScript(`dispatchCardCreatedEvent(${JSON.stringify(card)})`); }; export const getWhiteLabelAppScript = () => { return ` ${DISPATCH_REQUEST_REFRESH} ${DISPATCH_OPEN_PLAID} ${DISPATCH_PLAID_RESPONSE} ${DISPATCH_PLAID_EXIT} ${DISPATCH_ACCOUNT_CREATION_ACTIONS_OPEN_PLAID_FOR_LINK_EXTERNAL_ACCOUNT} ${LISTENERS.unitWhiteLabelAppOnLoad} ${LISTENERS.unitCounterpartyCreated} `; };