import React, { useState } from 'react' import { useTranslation } from 'react-i18next' import { StyleSheet, Text, View } from 'react-native' import CurrencyDisplay from 'src/components/CurrencyDisplay' import Dialog from 'src/components/Dialog' import Touchable from 'src/components/Touchable' import InfoIcon from 'src/icons/InfoIcon' import { LocalCurrencyCode } from 'src/localCurrency/consts' import colors from 'src/styles/colors' import { typeScale } from 'src/styles/fonts' import variables from 'src/styles/variables' import { useTokenInfo } from 'src/tokens/hooks' import { navigateToURI } from 'src/utils/linking' interface Props { provider: string tokenIdToBuy: string localCurrency: LocalCurrencyCode crypto: { amount: number } fiat: { subTotal: number total: number } feeWaived: boolean feeUrl: string } export default function ReviewFees({ provider, crypto, fiat, localCurrency, tokenIdToBuy, feeWaived, feeUrl, }: Props) { const [showFeeExplanation, setShowFeeExplanation] = useState(false) const [showFeeDiscountExplanation, setShowFeeDiscountExplanation] = useState(false) const { t } = useTranslation() const openFeeExplanation = () => setShowFeeExplanation(true) const closeFeeExplanation = () => setShowFeeExplanation(false) const openFeeDiscountExplanation = () => setShowFeeDiscountExplanation(true) const closeFeeDiscountExplanation = () => setShowFeeDiscountExplanation(false) const openProviderFeeUrl = () => navigateToURI(feeUrl) const tokenInfo = useTokenInfo(tokenIdToBuy) if (!tokenInfo) { throw new Error(`Token info not found for token ID ${tokenIdToBuy}`) } const tokenSymbol = tokenInfo.symbol const showAmount = (value: number, isCelo: boolean = false, textStyle: any[] = []) => ( ) return ( {t('providerFeesDialog.title')} {'\n\n'} {t('providerFeesDialog.body1')} {t('providerFeesDialog.body2', { providerName: provider })} {t('providerFeeDiscountDialog.title')} {'\n\n'} {t('providerFeeDiscountDialog.body')} {t('amount')} ({tokenSymbol}) {showAmount(crypto.amount, true)} {t('pricePer', { coin: tokenSymbol })} {showAmount(fiat.subTotal / crypto.amount, false, [styles.reviewLineTextAlt])} {t('subtotal')} {showAmount(fiat.subTotal)} {!feeWaived ? ( {provider} {t('fee')} {showAmount(fiat.total - fiat.subTotal, false, [styles.reviewLineText])} ) : ( {t('feeDiscount')} {t('free')} )} {t('Total')} {showAmount(fiat.total, false, [styles.reviewLineTextTotal])} ) } const styles = StyleSheet.create({ review: { paddingVertical: 16, paddingHorizontal: 16, }, reviewLine: { ...typeScale.bodyMedium, paddingVertical: 4, display: 'flex', flexDirection: 'row', justifyContent: 'space-between', }, reviewLineInfo: { display: 'flex', flexDirection: 'row', }, reviewLineText: { ...typeScale.bodyMedium, }, feeWaivedText: { ...typeScale.bodyMedium, color: colors.accent, }, reviewLineTextAlt: { color: colors.contentSecondary, }, reviewLineTextTotal: { ...typeScale.labelSemiBoldMedium, }, line: { marginVertical: 16, height: 1, width: '100%', backgroundColor: colors.borderPrimary, }, icon: { position: 'relative', top: 5, marginLeft: 6, }, })