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, DISPATCH_REQUEST_EDIT_BILL, DISPATCH_REQUEST_CREATE_MANUAL_BILL_PAY, DISPATCH_REQUEST_OPEN_ARCHIVED_BILLS, DISPATCH_REQUEST_OPEN_VENDORS, DISPATCH_REQUEST_OPEN_PAYMENT_METHODS, DISPATCH_VENDOR_FORM_TRY_SUBMIT, DISPATCH_UNSAVED_CHANGES_ACTION, DISPATCH_BILL_ACTION_RESULT, LISTENERS, } from '../../scripts/html/bodyScript'; import { UNCard } from '../../types/shared'; import { RequestEditBillEvent } from '../../messages/webMessages/billPayMenuMessage'; import { BillActionsMessage } from '../../messages/webMessages/billActionsMessage'; import { UnsavedChangesActionEvent } from '../../messages/webMessages/unsavedChangesMessage'; 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 injectRequestEditBill = (currentWeb: WebView | null, detail: RequestEditBillEvent) => { currentWeb?.injectJavaScript(`dispatchRequestEditBill(${JSON.stringify(JSON.stringify(detail))})`); }; export const injectRequestCreateManualBillPay = (currentWeb: WebView | null) => { currentWeb?.injectJavaScript('dispatchRequestCreateManualBillPay()'); }; export const injectRequestOpenArchivedBills = (currentWeb: WebView | null) => { currentWeb?.injectJavaScript('dispatchRequestOpenArchivedBills()'); }; export const injectRequestOpenVendors = (currentWeb: WebView | null) => { currentWeb?.injectJavaScript('dispatchRequestOpenVendors()'); }; export const injectRequestOpenPaymentMethods = (currentWeb: WebView | null) => { currentWeb?.injectJavaScript('dispatchRequestOpenPaymentMethods()'); }; export const injectVendorFormTrySubmit = (currentWeb: WebView | null) => { currentWeb?.injectJavaScript('dispatchVendorFormTrySubmit()'); }; export const injectUnsavedChangesAction = (currentWeb: WebView | null, detail: UnsavedChangesActionEvent) => { currentWeb?.injectJavaScript(`dispatchUnsavedChangesAction(${JSON.stringify(JSON.stringify(detail))})`); }; export const injectBillActionResult = (currentWeb: WebView | null, eventName: BillActionsMessage, billId: string) => { currentWeb?.injectJavaScript(`dispatchBillActionResult(${JSON.stringify(eventName)}, ${JSON.stringify(billId)})`); }; 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} ${DISPATCH_REQUEST_EDIT_BILL} ${DISPATCH_REQUEST_CREATE_MANUAL_BILL_PAY} ${DISPATCH_REQUEST_OPEN_ARCHIVED_BILLS} ${DISPATCH_REQUEST_OPEN_VENDORS} ${DISPATCH_REQUEST_OPEN_PAYMENT_METHODS} ${DISPATCH_VENDOR_FORM_TRY_SUBMIT} ${DISPATCH_UNSAVED_CHANGES_ACTION} ${DISPATCH_BILL_ACTION_RESULT} ${LISTENERS.unitWhiteLabelAppOnLoad} ${LISTENERS.unitCounterpartyCreated} `; };