UNPKG

react-native-unit-components

Version:

Unit React Native components

51 lines (44 loc) 2.5 kB
import { UNAccountAction, UNAccountComponentProps } from './UNAccountComponent'; import { RequestRefreshEvent, RequestRenderingEvent } from '../../messages/webMessages/unitComponentsMessages'; import type WebView from 'react-native-webview'; import type { UNAccountMenuAction } from '../../types/shared'; import { WebComponentType } from '../../types/internal/webComponent.types'; import { LISTENERS } from '../../scripts/html/bodyScript'; import { DISPATCH_REQUEST_REFRESH } from '../../scripts/html/bodyScript'; export const getAccountParams = (props: UNAccountComponentProps) => { const accountIdParam = props.accountId ? `account-id="${props.accountId}"` : ''; const menuItemsParam = props.menuItems ? `menu-items="${props.menuItems.join()}"` : ''; return ` ${accountIdParam} hide-actions-menu-button="${props.hideActionsMenuButton || false}" hide-selection-menu-button="${props.hideSelectionMenuButton || false}" hide-account-status="${props.hideAccountStatus || false}" hide-account-details="${props.hideAccountDetails || false}" hide-account-buttons="${props.hideAccountButtons || false}" hide-account-cta-banner="${props.hideAccountCtaBanner || false}" show-left-to-spend="${props.showLeftToSpend || false}" enable-fund-account-button="${props.enableFundAccountButton || false}" enable-pay-someone-account-button="${props.enablePaySomeoneAccountButton || false}" ${menuItemsParam} `; }; export const getAccountScript = () => { return ` ${DISPATCH_REQUEST_REFRESH} ${LISTENERS.unitRequestLeftToSpendDetails} `; }; export const injectOpenActionsMenuScript = (currentWeb: WebView | null) => { currentWeb?.injectJavaScript(`dispatchOpenActionsMenu('${WebComponentType.account}')`); }; export const injectRequestAccountActionScript = (currentWeb: WebView | null, action: UNAccountMenuAction) => { currentWeb?.injectJavaScript(`dispatchRequestAccountAction('${action}')`); }; export const injectRefreshEventIfNeeded = (currentWeb: WebView | null, requestRefreshEvent: RequestRefreshEvent | null) => { if (requestRefreshEvent && requestRefreshEvent.dependencies.includes(WebComponentType.account.valueOf())) { currentWeb?.injectJavaScript(`dispatchRefreshEvent('${JSON.stringify(requestRefreshEvent)}')`); } }; export const getAccountActionType = (requestRendering: RequestRenderingEvent) => { return requestRendering.data.nativeComponent.includes(UNAccountAction.List) ? UNAccountAction.List : UNAccountAction.Menu; };