UNPKG

react-native-unit-components

Version:

Unit React Native components

48 lines (43 loc) 2.39 kB
import type { UNACHCreditComponentProps } from './UNACHCreditComponent'; import type WebView from 'react-native-webview'; import type { LinkSuccess } from 'react-native-plaid-link-sdk'; import { DISPATCH_COUNTERPARTY_DELETED, DISPATCH_PLAID_RESPONSE, LISTENERS } from '../../scripts/html/bodyScript'; import { UNCounterparty } from '../../types/shared'; export const getACHCreditParams = (props: UNACHCreditComponentProps) => { const plaidAccountFiltersParam = props.plaidAccountFilters ? `plaid-account-filters="${props.plaidAccountFilters.join()}"` : ''; const plaidLinkCustomizationNameParam = props.plaidLinkCustomizationName ? `plaid-link-customization-name="${props.plaidLinkCustomizationName}"` : ''; const accountIdParam = props.accountId ? `account-id="${props.accountId}"` : ''; return ` ${accountIdParam} with-plaid="${props.withPlaid ?? false}" is-auto-focus="${props.isAutoFocus ?? false}" style="height: 100%" same-day="${props.sameDay ?? false}" show-same-day-selection="${props.showSameDaySelection ?? false}" ${plaidAccountFiltersParam} ${plaidLinkCustomizationNameParam} initial-stage-back-button="${props.initialStageBackButton ?? false}" final-stage-done-button="${props.finalStageDoneButton ?? false}" allow-counterparty-delete="${props.allowCounterpartyDelete ?? false}" show-account-type-selector="${props.showAccountTypeSelector ?? false}" `; }; export const getACHCreditScript = (appPackageName?: string) => { return ` ${LISTENERS.unitPlaidTokenCreated} ${appPackageName && `window.UnitMobileSDKConfig.androidPackageName='${appPackageName}'`} ${LISTENERS.unitPaymentCreated} ${LISTENERS.unitPaymentInitialStageBackButtonClicked} ${LISTENERS.unitPaymentFinalStageDoneButtonClicked} ${DISPATCH_PLAID_RESPONSE} ${DISPATCH_COUNTERPARTY_DELETED} ${LISTENERS.requestRefresh} `; }; export const injectUnitPlaidResponse = (currentWeb: WebView | null, success: LinkSuccess) => { const successObj = { data: { publicToken: success.publicToken, metadata: success.metadata } }; currentWeb?.injectJavaScript(`dispatchPlaidEvent(${JSON.stringify(successObj)})`); }; export const injectRequestCounterpartyDeletedScript = (currentWeb: WebView | null, counterparty: UNCounterparty) => { currentWeb?.injectJavaScript(`dispatchCounterpartyDeletedEvent('${counterparty}')`); };