From f5bb373edf77f03385f50f891d3462bb71400cf3 Mon Sep 17 00:00:00 2001 From: Yehor Hryhortsev Date: Sat, 13 Jan 2024 21:17:31 +0200 Subject: [PATCH] fix balance --- src/components/Currency/Currency.jsx | 1 - .../TransactionsItem/TransactionsItem.jsx | 10 +++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/components/Currency/Currency.jsx b/src/components/Currency/Currency.jsx index aee247b..48e1925 100644 --- a/src/components/Currency/Currency.jsx +++ b/src/components/Currency/Currency.jsx @@ -30,7 +30,6 @@ const Currency = () => { const [currency, setCurrency] = useState([]); const dispatch = useDispatch(); const selectedCurrency = useSelector(currencySelector); - console.log('here', selectedCurrency, currency); // const isLoading = useSelector(isLoadingSelector); const token = useSelector(state => state.auth.token); diff --git a/src/components/TransactionsList/TransactionsItem/TransactionsItem.jsx b/src/components/TransactionsList/TransactionsItem/TransactionsItem.jsx index 2ac0aa1..1d00239 100644 --- a/src/components/TransactionsList/TransactionsItem/TransactionsItem.jsx +++ b/src/components/TransactionsList/TransactionsItem/TransactionsItem.jsx @@ -30,6 +30,14 @@ const TransactionsItem = ({ transaction }) => { const transType = transaction.type === 'EXPENSE' ? '-' : '+'; + function correctBalance(amount) { + if (amount < 0) { + return Math.abs(amount); + } else { + return (amount = -amount); + } + } + return ( {formattedDateStr} @@ -65,7 +73,7 @@ const TransactionsItem = ({ transaction }) => { dispatch(deleteTransactionThunk(transaction.id)) .unwrap() .then(() => { - dispatch(changeBalance(transaction.amount)); + dispatch(changeBalance(correctBalance(transaction.amount))); dispatch(deleteTransaction(transaction.id)); toast.success('Transaction is deleted!'); })