├── src ├── components │ ├── Forms │ │ ├── Reg.css │ │ ├── Login.css │ │ ├── Login.js │ │ └── Register.js │ ├── Tracker │ │ ├── Transaction │ │ │ └── Transaction.js │ │ ├── Tracker.css │ │ └── Tracker.js │ ├── Main.css │ └── Main.js ├── App.css ├── assets │ └── loader.gif ├── App.js ├── setupTests.js ├── App.test.js ├── index.css ├── reportWebVitals.js ├── config │ └── Fire.js ├── index.js └── logo.svg ├── public ├── favicon.ico ├── logo192.png ├── logo512.png ├── robots.txt ├── manifest.json └── index.html ├── .gitignore ├── package.json └── README.md /src/components/Forms/Reg.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/App.css: -------------------------------------------------------------------------------- 1 | body { 2 | background: #425F9C; 3 | color: #3c4043; 4 | } -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ruvictor/react-expense-app/HEAD/public/favicon.ico -------------------------------------------------------------------------------- /public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ruvictor/react-expense-app/HEAD/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ruvictor/react-expense-app/HEAD/public/logo512.png -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /src/assets/loader.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ruvictor/react-expense-app/HEAD/src/assets/loader.gif -------------------------------------------------------------------------------- /src/App.js: -------------------------------------------------------------------------------- 1 | import './App.css'; 2 | import Main from './components/Main'; 3 | 4 | function App() { 5 | return (
); 6 | } 7 | 8 | export default App; 9 | -------------------------------------------------------------------------------- /src/setupTests.js: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom'; 6 | -------------------------------------------------------------------------------- /src/App.test.js: -------------------------------------------------------------------------------- 1 | import { render, screen } from '@testing-library/react'; 2 | import App from './App'; 3 | 4 | test('renders learn react link', () => { 5 | render(); 6 | const linkElement = screen.getByText(/learn react/i); 7 | expect(linkElement).toBeInTheDocument(); 8 | }); 9 | -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /src/config 5 | /node_modules 6 | /.pnp 7 | .pnp.js 8 | 9 | # testing 10 | /coverage 11 | 12 | # production 13 | /build 14 | 15 | # misc 16 | .DS_Store 17 | .env.local 18 | .env.development.local 19 | .env.test.local 20 | .env.production.local 21 | 22 | npm-debug.log* 23 | yarn-debug.log* 24 | yarn-error.log* 25 | -------------------------------------------------------------------------------- /src/reportWebVitals.js: -------------------------------------------------------------------------------- 1 | const reportWebVitals = onPerfEntry => { 2 | if (onPerfEntry && onPerfEntry instanceof Function) { 3 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 4 | getCLS(onPerfEntry); 5 | getFID(onPerfEntry); 6 | getFCP(onPerfEntry); 7 | getLCP(onPerfEntry); 8 | getTTFB(onPerfEntry); 9 | }); 10 | } 11 | }; 12 | 13 | export default reportWebVitals; 14 | -------------------------------------------------------------------------------- /src/config/Fire.js: -------------------------------------------------------------------------------- 1 | import firebase from 'firebase'; 2 | 3 | const config = { 4 | apiKey: "AIzaSyAaCElud0Ife0vkits2BScONMaX_nw--As", 5 | authDomain: "vicode-media.firebaseapp.com", 6 | projectId: "vicode-media", 7 | storageBucket: "vicode-media.appspot.com", 8 | messagingSenderId: "420658677235", 9 | appId: "1:420658677235:web:eac7e5990ee0ebe38b7e86" 10 | }; 11 | 12 | const fire = firebase.initializeApp(config); 13 | export default fire; -------------------------------------------------------------------------------- /src/components/Tracker/Transaction/Transaction.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | const Transaction = props => { 4 | return ( 5 |
  • 6 |
    {props.name}
    7 |
    {props.type === 'deposit' ? ( 8 | +{props.price} 9 | ) : ( 10 | 11 | -{props.price} 12 | 13 | )}
    14 |
  • 15 | ); 16 | } 17 | 18 | export default Transaction; -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | import reportWebVitals from './reportWebVitals'; 6 | 7 | ReactDOM.render( 8 | 9 | 10 | , 11 | document.getElementById('root') 12 | ); 13 | 14 | // If you want to start measuring performance in your app, pass a function 15 | // to log results (for example: reportWebVitals(console.log)) 16 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 17 | reportWebVitals(); 18 | -------------------------------------------------------------------------------- /public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /src/components/Main.css: -------------------------------------------------------------------------------- 1 | .mainBlock { 2 | border-radius: 5px; 3 | box-sizing: border-box; 4 | text-align: center; 5 | background-color: #fff; 6 | padding: 20px; 7 | width: 100%; 8 | max-width: 350px; 9 | margin: 100px auto; 10 | display: table; 11 | box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19); 12 | } 13 | .Error{ 14 | padding: 10px; 15 | background-color: #feeaea; 16 | border: 1px solid #fadadb; 17 | margin-bottom: 10px; 18 | border-radius: 3px; 19 | } 20 | 21 | .Spinner{ 22 | display: table; 23 | margin: 0 auto; 24 | } 25 | .Spinner > .ImgSpinner { 26 | max-width: 30px; 27 | } -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 14 | Expense Tracker 15 | 16 | 17 | 18 |
    19 | 20 | 21 | -------------------------------------------------------------------------------- /src/components/Forms/Login.css: -------------------------------------------------------------------------------- 1 | .regField { 2 | width: 100%; 3 | background-color: #f7f7f7; 4 | color: #000; 5 | border: 1px solid #ddd; 6 | padding: 15px; 7 | box-sizing: border-box; 8 | font-size: 15px; 9 | } 10 | 11 | .submitBtn { 12 | width: 100%; 13 | background: #425f9c; 14 | border: 0; 15 | color: #fff; 16 | padding: 15px; 17 | margin: 10px 0 0 0; 18 | font-size: 15px; 19 | cursor: pointer; 20 | } 21 | 22 | .underLine { 23 | text-align: center; 24 | margin: 7px 0 0 0; 25 | display: block; 26 | } 27 | 28 | .linkBtn { 29 | border: 0; 30 | background-color: unset; 31 | text-decoration: underline; 32 | color: #3c4043; 33 | padding: 0; 34 | margin: 0; 35 | } 36 | 37 | .linkBtn:hover { 38 | color: blue; 39 | cursor: pointer; 40 | } 41 | 42 | .linkBtn:focus, 43 | .submitBtn:focus{ 44 | outline: none; 45 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-expense-app", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.11.6", 7 | "@testing-library/react": "^11.1.2", 8 | "@testing-library/user-event": "^12.2.2", 9 | "firebase": "^8.1.2", 10 | "react": "^17.0.1", 11 | "react-dom": "^17.0.1", 12 | "react-scripts": "4.0.0", 13 | "web-vitals": "^0.2.4" 14 | }, 15 | "scripts": { 16 | "start": "react-scripts start", 17 | "build": "react-scripts build", 18 | "test": "react-scripts test", 19 | "eject": "react-scripts eject" 20 | }, 21 | "eslintConfig": { 22 | "extends": [ 23 | "react-app", 24 | "react-app/jest" 25 | ] 26 | }, 27 | "browserslist": { 28 | "production": [ 29 | ">0.2%", 30 | "not dead", 31 | "not op_mini all" 32 | ], 33 | "development": [ 34 | "last 1 chrome version", 35 | "last 1 firefox version", 36 | "last 1 safari version" 37 | ] 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/components/Forms/Login.js: -------------------------------------------------------------------------------- 1 | import React, {Component} from 'react'; 2 | import fire from '../../config/Fire'; 3 | import './Login.css'; 4 | 5 | class Login extends Component { 6 | state = { 7 | email: '', 8 | password: '', 9 | fireErrors: '' 10 | } 11 | 12 | login = e => { 13 | e.preventDefault(); 14 | fire.auth().signInWithEmailAndPassword(this.state.email, this.state.password) 15 | .catch((error) => { 16 | this.setState({fireErrors: error.message}) 17 | }); 18 | } 19 | 20 | handleChange = e => { 21 | this.setState({[e.target.name]: e.target.value}); 22 | } 23 | 24 | render() { 25 | 26 | let errorNotification = this.state.fireErrors ? 27 | (
    {this.state.fireErrors}
    ) : null; 28 | 29 | 30 | return ( 31 | <> 32 | {errorNotification} 33 |
    34 | 41 | 49 | 50 |
    51 | 52 | ); 53 | } 54 | } 55 | export default Login; -------------------------------------------------------------------------------- /src/components/Main.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import './Main.css'; 3 | import fire from '../config/Fire'; 4 | import Login from './Forms/Login'; 5 | import Register from './Forms/Register'; 6 | import Spinner from '../assets/loader.gif'; 7 | import Tracker from './Tracker/Tracker'; 8 | 9 | export default class Main extends Component { 10 | state = { 11 | user: 1, 12 | loading: true 13 | } 14 | 15 | componentDidMount(){ 16 | this.authListener(); 17 | } 18 | 19 | authListener(){ 20 | fire.auth().onAuthStateChanged((user) => { 21 | if(user){ 22 | this.setState({user}); 23 | }else{ 24 | this.setState({user:null}); 25 | } 26 | }); 27 | } 28 | 29 | formSwitcher = (action) => { 30 | this.setState({formSwitcher: action === 'register' ? true : false}); 31 | } 32 | 33 | render() { 34 | const form = !this.state.formSwitcher ? : ; 35 | 36 | if (this.state.user === 1){ 37 | return ( 38 |
    39 |
    40 | Spinner 41 |
    42 |
    ); 43 | } 44 | 45 | return ( 46 | <> 47 | {!this.state.user ? ( 48 |
    49 | {form} 50 | { 51 | !this.state.formSwitcher ? 52 | (Not registered? 54 | ) : ( 55 | Have an account already? 57 | 58 | ) 59 | } 60 |
    61 | ) : ()} 62 | 63 | ); 64 | } 65 | } -------------------------------------------------------------------------------- /src/components/Forms/Register.js: -------------------------------------------------------------------------------- 1 | import React, {Component} from 'react'; 2 | import fire from '../../config/Fire'; 3 | import './Reg.css'; 4 | 5 | class Register extends Component { 6 | state = { 7 | email: '', 8 | password: '', 9 | displayName: '', 10 | fireErrors: '' 11 | } 12 | 13 | register = e => { 14 | e.preventDefault(); 15 | fire.auth().createUserWithEmailAndPassword(this.state.email, this.state.password).then((user) => { 16 | var currentUser = fire.auth().currentUser; 17 | currentUser.updateProfile({ 18 | displayName: this.state.displayName 19 | }) 20 | }) 21 | .catch((error) => { 22 | this.setState({fireErrors: error.message}) 23 | }); 24 | } 25 | 26 | handleChange = e => { 27 | this.setState({[e.target.name]: e.target.value}); 28 | } 29 | 30 | render() { 31 | 32 | let errorNotification = this.state.fireErrors ? 33 | (
    {this.state.fireErrors}
    ) : null; 34 | 35 | 36 | return ( 37 | <> 38 | {errorNotification} 39 |
    40 | 47 | 54 | 62 | 63 |
    64 | 65 | ); 66 | } 67 | } 68 | export default Register; -------------------------------------------------------------------------------- /src/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/components/Tracker/Tracker.css: -------------------------------------------------------------------------------- 1 | .trackerBlock { 2 | /* border-radius: 5px; */ 3 | box-sizing: border-box; 4 | /* background-color: #E9E9E9; */ 5 | padding: 20px; 6 | width: 100%; 7 | max-width: 350px; 8 | margin: 100px auto; 9 | display: table; 10 | /* box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19); */ 11 | } 12 | 13 | .welcome { 14 | color: #fff; 15 | display: flex; 16 | justify-content: space-between; 17 | margin: 0; 18 | text-shadow: 0px 5px 3px #292929; 19 | } 20 | .totalMoney { 21 | color: #fff; 22 | font-size: 20px; 23 | margin:0 0 10px; 24 | text-shadow: 0px 5px 3px #292929; 25 | } 26 | 27 | .newTransaction { 28 | box-sizing: border-box; 29 | text-align: center; 30 | color: #425f9c; 31 | display: table; 32 | width: 100%; 33 | border-radius: 5px; 34 | background-color: #fff; 35 | border: 0; 36 | padding: 10px; 37 | margin:0 0 10px; 38 | font-size: 15px; 39 | box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19); 40 | } 41 | 42 | .newTransaction input[type="text"], 43 | .newTransaction select{ 44 | width: 100%; 45 | box-sizing: border-box; 46 | border: 1px solid #ddd; 47 | font-size: 13px; 48 | padding: 7px; 49 | } 50 | 51 | .newTransaction input[type="text"]:focus, 52 | .newTransaction select:focus{ 53 | outline: none; 54 | } 55 | 56 | .inputGroup { 57 | display:flex; 58 | justify-content: center; 59 | } 60 | 61 | .addTransaction { 62 | text-align: center; 63 | color: #ffffff; 64 | border-radius: 3px; 65 | background-color: #425f9c; 66 | border: 0; 67 | margin: 5px 0 0; 68 | padding: 5px 10px; 69 | font-size: 15px; 70 | cursor: pointer; 71 | } 72 | 73 | .addTransaction:hover { 74 | background-color: #274177; 75 | } 76 | 77 | .addTransaction:focus{ 78 | outline: none; 79 | } 80 | 81 | 82 | 83 | .latestTransactions { 84 | margin: 10px 0 0 0; 85 | background-color: #fff; 86 | padding: 10px; 87 | border-radius: 5px; 88 | box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19); 89 | } 90 | 91 | .latestTransactions p{ 92 | font-weight: bold; 93 | padding: 0 0 5px; 94 | margin: 0; 95 | font-size: 13px; 96 | border-bottom: 1px solid #ddd; 97 | } 98 | 99 | ul { 100 | list-style-type: none; 101 | padding: 0; 102 | margin: 0; 103 | } 104 | 105 | ul li { 106 | border-bottom: 1px solid #ddd; 107 | padding: 5px 0; 108 | display: flex; 109 | justify-content: space-between; 110 | } 111 | 112 | ul li:last-child{ 113 | border-bottom: 0; 114 | padding: 5px 0 0; 115 | } 116 | 117 | .expense { 118 | color: red; 119 | } 120 | 121 | .deposit { 122 | color: green; 123 | } 124 | 125 | .exit { 126 | background-color: #fff; 127 | border: 0; 128 | border-radius: 3px; 129 | color: red; 130 | cursor: pointer; 131 | box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19); 132 | } 133 | 134 | .exit:hover { 135 | background-color: #f1f1f1; 136 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Create React App 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `npm start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 13 | 14 | The page will reload if you make edits.\ 15 | You will also see any lint errors in the console. 16 | 17 | ### `npm test` 18 | 19 | Launches the test runner in the interactive watch mode.\ 20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 21 | 22 | ### `npm run build` 23 | 24 | Builds the app for production to the `build` folder.\ 25 | It correctly bundles React in production mode and optimizes the build for the best performance. 26 | 27 | The build is minified and the filenames include the hashes.\ 28 | Your app is ready to be deployed! 29 | 30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 31 | 32 | ### `npm run eject` 33 | 34 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 35 | 36 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 37 | 38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 39 | 40 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 41 | 42 | ## Learn More 43 | 44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 45 | 46 | To learn React, check out the [React documentation](https://reactjs.org/). 47 | 48 | ### Code Splitting 49 | 50 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) 51 | 52 | ### Analyzing the Bundle Size 53 | 54 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) 55 | 56 | ### Making a Progressive Web App 57 | 58 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) 59 | 60 | ### Advanced Configuration 61 | 62 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) 63 | 64 | ### Deployment 65 | 66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) 67 | 68 | ### `npm run build` fails to minify 69 | 70 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) 71 | -------------------------------------------------------------------------------- /src/components/Tracker/Tracker.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import './Tracker.css'; 3 | import fire from '../../config/Fire'; 4 | import Transaction from './Transaction/Transaction'; 5 | 6 | class Tracker extends Component { 7 | 8 | state = { 9 | transactions: [], 10 | money: 0, 11 | 12 | transactionName: '', 13 | transactionType: '', 14 | price: '', 15 | currentUID: fire.auth().currentUser.uid 16 | } 17 | 18 | // logout function 19 | logout = () => { 20 | fire.auth().signOut(); 21 | } 22 | 23 | handleChange = input => e => { 24 | this.setState({ 25 | [input]: e.target.value !=="0" ? e.target.value : "" 26 | }); 27 | } 28 | 29 | // add transaction 30 | addNewTransaction = () => { 31 | const {transactionName, transactionType, price, currentUID, money} = this.state; 32 | 33 | // validation 34 | if(transactionName && transactionType && price){ 35 | 36 | const BackUpState = this.state.transactions; 37 | BackUpState.push({ 38 | id: BackUpState.length + 1, 39 | name: transactionName, 40 | type: transactionType, 41 | price: price, 42 | user_id: currentUID 43 | }); 44 | 45 | fire.database().ref('Transactions/' + currentUID).push({ 46 | id: BackUpState.length, 47 | name: transactionName, 48 | type: transactionType, 49 | price: price, 50 | user_id: currentUID 51 | }).then((data) => { 52 | //success callback 53 | console.log('success callback'); 54 | this.setState({ 55 | transactions: BackUpState, 56 | money: transactionType === 'deposit' ? money + parseFloat(price) : money - parseFloat(price), 57 | transactionName: '', 58 | transactionType: '', 59 | price: '' 60 | }) 61 | }).catch((error)=>{ 62 | //error callback 63 | console.log('error ' , error) 64 | }); 65 | 66 | } 67 | } 68 | 69 | componentWillMount(){ 70 | const {currentUID, money} = this.state; 71 | let totalMoney = money; 72 | const BackUpState = this.state.transactions; 73 | fire.database().ref('Transactions/' + currentUID).once('value', 74 | (snapshot) => { 75 | // console.log(snapshot); 76 | snapshot.forEach((childSnapshot) => { 77 | 78 | totalMoney = 79 | childSnapshot.val().type === 'deposit' ? 80 | parseFloat(childSnapshot.val().price) + totalMoney 81 | : totalMoney - parseFloat(childSnapshot.val().price); 82 | 83 | BackUpState.push({ 84 | id: childSnapshot.val().id, 85 | name: childSnapshot.val().name, 86 | type: childSnapshot.val().type, 87 | price: childSnapshot.val().price, 88 | user_id: childSnapshot.val().user_id 89 | }); 90 | // console.log(childSnapshot.val().name); 91 | }); 92 | this.setState({ 93 | transactions: BackUpState, 94 | money: totalMoney 95 | }); 96 | }); 97 | } 98 | 99 | render(){ 100 | var currentUser = fire.auth().currentUser; 101 | return( 102 |
    103 |
    104 | Hi, {currentUser.displayName}! 105 | 106 |
    107 |
    ${this.state.money}
    108 | 109 |
    110 |
    111 |
    112 | 119 |
    120 | 127 | 134 |
    135 |
    136 | 137 |
    138 |
    139 | 140 |
    141 |

    Latest Transactions

    142 |
      143 | { 144 | Object.keys(this.state.transactions).map((id) => ( 145 | 150 | )) 151 | } 152 |
    153 |
    154 |
    155 | ); 156 | } 157 | } 158 | 159 | export default Tracker; --------------------------------------------------------------------------------