import React, { useCallback, useRef, useState } from 'react'; import { View, Image, Text, TouchableOpacity, LayoutAnimation, } from 'react-native'; import ReusableModal, { ReusableModalRef } from '../ReusableModal'; import Icon from 'react-native-vector-icons/Feather'; import { useNavigation } from '@react-navigation/native'; import AppConstants from '../../../core/AppConstants'; import { strings } from '../../../../locales/i18n'; import ReviewManager from '../../../core/ReviewManager'; import { createStyles } from './styles'; import { useAppThemeFromContext, mockTheme } from '../../../util/theme'; interface HelpOption { label: string; link: string; } const helpOptions: HelpOption[] = [ { label: strings('review_prompt.high_fees'), link: AppConstants.REVIEW_PROMPT.HIGH_GAS_FEES, }, { label: strings('review_prompt.missing_tokens'), link: AppConstants.REVIEW_PROMPT.MISSING_TOKENS, }, { label: strings('review_prompt.swap_issues'), link: AppConstants.REVIEW_PROMPT.SWAP_ISSUES, }, ]; /* eslint-disable-next-line */ const foxImage = require('images/fox.png'); const ReviewModal = () => { const navigation = useNavigation(); const modalRef = useRef(null); const [showHelpOptions, setShowHelpOptions] = useState(false); const { colors } = useAppThemeFromContext() || mockTheme; const styles = createStyles(colors); const dismissModal = (cb?: () => void) => modalRef?.current?.dismissModal(cb); const triggerClose = () => dismissModal(); const triggerShowReviewPrompt = async () => { dismissModal(); ReviewManager.openFallbackStoreReview(); }; const triggerShowHelpOptions = () => { LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut); setShowHelpOptions(true); }; const openUrl = useCallback( async (url: string) => { navigation.navigate('Webview', { screen: 'SimpleWebview', params: { url }, }); }, [navigation], ); const renderReviewContent = () => ( {strings('review_prompt.mobile_sentiment')} {strings('review_prompt.sentiment_good_face')} {strings('review_prompt.sentiment_good')} {strings('review_prompt.sentiment_bad_face')} {strings('review_prompt.sentiment_bad')} ); const renderHelpContent = useCallback( () => ( {strings('review_prompt.help_title')} {strings('review_prompt.help_description_1')} openUrl(AppConstants.REVIEW_PROMPT.SUPPORT)} style={styles.contactLabel} suppressHighlighting > {strings('review_prompt.help_description_2')} {strings('review_prompt.help_description_3')} {helpOptions.map(({ label, link }, index) => { const key = `help-${index}`; const onPress = () => openUrl(link); return ( {label} ); })} ), [openUrl, styles], ); const renderContent = () => { if (showHelpOptions) { return renderHelpContent(); } return renderReviewContent(); }; return ( {renderContent()} ); }; export default ReviewModal;