Untitled

mail@pastecode.io avatar
unknown
plain_text
6 months ago
677 B
2
Indexable
Never
import { useSelector } from 'react-redux';
import { GlobalType } from '../type/type';

function Header() {
  const { email } = useSelector((state: GlobalType) => state.user);
  const { expenses } = useSelector((state: GlobalType) => state.wallet);
  const somaTotal = () => {
    return expenses
      .reduce((acc, curr) => {
        return acc + Number(curr.value)
          * Number(curr.exchangeRates[curr.currency].ask);
      }, 0).toFixed(2);
  };
  return (
    <header>
      <p data-testid="email-field">{email}</p>
      <p data-testid="total-field">{somaTotal()}</p>
      <p data-testid="header-currency-field">BRL</p>
    </header>
  );
}

export default Header;