import { CheckMessage } from '../../messages/webMessages/checkMessage'; import type { UNCheckDepositComponentProps } from './UNCheckDepositComponent'; import { DISPATCH_VERYFI_RESPONSE, LISTENERS } from '../../scripts/html/bodyScript'; import { isVeryfiAvailable, type UNVeryfiImage } from '../../services/veryfiService'; import type WebView from 'react-native-webview'; import type { UNVeryfiCredentials } from '../../types/shared/veryfi.types'; export const getCheckDepositParams = (props: UNCheckDepositComponentProps, veryfiCredentials?: UNVeryfiCredentials | null) => { const accountIdParam = props.accountId ? `account-id="${props.accountId}"` : ''; const feeParam = props.fee ? `fee="${props.fee}"` : ''; const useVeryfi = veryfiCredentials && isVeryfiAvailable(); const versionParam = useVeryfi ? 'version="veryfi"' : ''; return ` ${accountIdParam} ${feeParam} ${versionParam} initial-stage-back-button="${props.initialStageBackButton ?? false}" final-stage-done-button="${props.finalStageDoneButton ?? false}" `; }; const CHECK_DEPOSIT_LISTENERS = { paymentCreated: ` window.addEventListener("${CheckMessage.CHECK_DEPOSIT_CREATED}", (e) => { const response = e.detail response.then((data) => { postMessageToSDK({ type: "${CheckMessage.CHECK_DEPOSIT_CREATED}", details: data.data }) }).catch((e) => { console.log(e) }) }); `, restartRequest: ` window.addEventListener("${CheckMessage.CHECK_DEPOSIT_RESTART_REQUEST}", (e) => { const response = e.detail response.then((data) => { postMessageToSDK({ type: "${CheckMessage.CHECK_DEPOSIT_RESTART_REQUEST}", details: data.data }) }).catch((e) => { console.log(e) }) }); `, }; export const getCheckDepositScript = () => { return ` ${CHECK_DEPOSIT_LISTENERS.paymentCreated} ${LISTENERS.unitPaymentInitialStageBackButtonClicked} ${LISTENERS.unitPaymentFinalStageDoneButtonClicked} ${CHECK_DEPOSIT_LISTENERS.restartRequest} ${DISPATCH_VERYFI_RESPONSE} `; }; export const injectUnitVeryfiResponse = (currentWeb: WebView | null, images: UNVeryfiImage[]) => { const payload = { images }; currentWeb?.injectJavaScript(`dispatchVeryfiEvent(${JSON.stringify(payload)})`); };