import { NativeStackScreenProps } from '@react-navigation/native-stack' import BigNumber from 'bignumber.js' import React, { useEffect } from 'react' import { useTranslation } from 'react-i18next' import { StyleSheet, Text, View } from 'react-native' import { ScrollView } from 'react-native-gesture-handler' import { SafeAreaView } from 'react-native-safe-area-context' import { useDispatch } from 'react-redux' import AppAnalytics from 'src/analytics/AppAnalytics' import { JumpstartEvents } from 'src/analytics/Events' import Button, { BtnSizes } from 'src/components/Button' import InLineNotification, { NotificationVariant } from 'src/components/InLineNotification' import Toast from 'src/components/Toast' import TokenDisplay from 'src/components/TokenDisplay' import TokenIcon, { IconSize } from 'src/components/TokenIcon' import { jumpstartSendStatusSelector } from 'src/jumpstart/selectors' import { depositErrorDismissed, depositTransactionStarted } from 'src/jumpstart/slice' import { getLocalCurrencyCode, usdToLocalCurrencyRateSelector } from 'src/localCurrency/selectors' import { navigate } from 'src/navigator/NavigationService' import { Screens } from 'src/navigator/Screens' import { StackParamList } from 'src/navigator/types' import { useSelector } from 'src/redux/hooks' import Colors from 'src/styles/colors' import { typeScale } from 'src/styles/fonts' import { Spacing } from 'src/styles/styles' import { useTokenInfo } from 'src/tokens/hooks' import Logger from 'src/utils/Logger' type Props = NativeStackScreenProps const TAG = 'JumpstartSendConfirmation' function JumpstartSendConfirmation({ route }: Props) { const { tokenId, sendAmount, serializablePreparedTransactions, link, beneficiaryAddress } = route.params const parsedAmount = new BigNumber(sendAmount) const { t } = useTranslation() const dispatch = useDispatch() const token = useTokenInfo(tokenId) const usdToLocalRate = useSelector(usdToLocalCurrencyRateSelector) const localCurrencyCode = useSelector(getLocalCurrencyCode) const jumpstartSendStatus = useSelector(jumpstartSendStatusSelector) useEffect(() => { if (jumpstartSendStatus === 'success') { navigate(Screens.JumpstartShareLink, { tokenId, sendAmount, link }) } }, [jumpstartSendStatus]) useEffect(() => { // dismiss any errors when entering the screen because errors should only be // created from sending a failed transaction in this screen. if the user // navigates back after encountering an error, they should not see the error // again when coming to this screen again. if (jumpstartSendStatus === 'error') { dispatch(depositErrorDismissed()) } }, []) const handleSendTransaction = () => { if (token) { dispatch( depositTransactionStarted({ sendToken: token, sendAmount, serializablePreparedTransactions, beneficiaryAddress, }) ) AppAnalytics.track(JumpstartEvents.jumpstart_send_confirm, { localCurrency: localCurrencyCode, localCurrencyExchangeRate: usdToLocalRate, tokenSymbol: token.symbol, tokenAmount: sendAmount, amountInUsd: parsedAmount.multipliedBy(token.priceUsd ?? 0).toFixed(2), tokenId: token.tokenId, networkId: token.networkId, }) } } const handleDismissError = () => { dispatch(depositErrorDismissed()) } if (!token) { // should never happen Logger.error(TAG, 'Token is undefined') return null } return ( <> {t('jumpstartSendConfirmationScreen.title')} {t('jumpstartSendConfirmationScreen.sendAmountLabel')}