Return

All tests / CryptoPrice index.tsx

100% Statements 12/12
50% Branches 1/2
100% Functions 1/1
100% Lines 11/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 511x 1x 1x 1x 1x 1x 1x             1x 1x 1x                                                                   1x  
import React from 'react';
import { TbCurrencyRipple } from 'react-icons/tb';
import useXRP from '@/hooks/useXRP';
import RenderManager from '@/components/RenderManager';
import styles from './crypto.module.css';
import { useIntl } from 'react-intl';
import Tooltip from '@/components/Tooltip';
 
/**
 * @description Show the current price of XRP in EUR
 * @returns {JSX.Element}
 * @example <CryptoPrice />
 */
const CryptoPrice = () => {
    const { data, error, loading } = useXRP();
    const { formatMessage: f, formatNumber } = useIntl();
 
    return (
        <Tooltip>
            <Tooltip.Trigger>
                <div className={styles.container} data-testid="crypto-price">
                    <TbCurrencyRipple className={styles.xrp} />
                    <RenderManager
                        loading={loading}
                        error={error}
                        errorTitle={f({ id: 'cryptoPrice.error' })}
                        loadingTitle={f({ id: 'cryptoPrice.loading' })}
                    >
                        {formatNumber(!isNaN(data.price) ? data.price : 0, {
                            style: 'currency',
                            currency: 'EUR',
                            minimumFractionDigits: 2,
                            maximumFractionDigits: 2,
                        })}
                    </RenderManager>
                </div>
            </Tooltip.Trigger>
            <Tooltip.Content>
                {f(
                    { id: 'cryptoPrice.tooltip' },
                    {
                        todayPorcentage: data.todayPorcentage,
                    }
                )}
            </Tooltip.Content>
        </Tooltip>
    );
};
 
export default CryptoPrice;