From 8b79904d971ea0fa02a5f5eb19388e82650249ab Mon Sep 17 00:00:00 2001 From: shooskie Date: Wed, 12 Apr 2017 19:58:47 -0500 Subject: [PATCH 01/10] new --- package.json | 93 ++++++++++++++++++---------------- src/Router.js | 2 +- src/actions/AuthActions.js | 43 ++++++++++------ src/actions/DepositActions.js | 32 +++++++++--- src/actions/balanceActions.js | 3 +- src/components/DepositPage.js | 61 +++++++++++++++------- src/components/overview.js | 6 ++- src/reducers/BalanceReducer.js | 15 ++++-- 8 files changed, 161 insertions(+), 94 deletions(-) diff --git a/package.json b/package.json index fee032e..fc605db 100644 --- a/package.json +++ b/package.json @@ -1,47 +1,50 @@ { - "name": "Upstart", - "version": "0.0.1", - "private": true, - "scripts": { - "start": "node node_modules/react-native/local-cli/cli.js start", - "test": "jest" - }, - "dependencies": { - "firebase": "^3.6.9", - "react": "~15.4.1", - "react-native": "0.42.0", - "react-native-animatable": "^1.1.0", - "react-native-camera-roll-picker": "^1.1.9", - "react-native-code-push": "1.17.0-beta", - "react-native-elements": "^0.9.7", - "react-native-fetch-blob": "0.10.2-beta.8", - "react-native-gifted-chat": "0.1.1", - "react-native-google-analytics-bridge": "^5.0.0", - "react-native-image-picker": "^0.25.1", - "react-native-keyboard-aware-scroll-view": "^0.2.6", - "react-native-lightbox": "^0.6.0", - "react-native-loading-spinner-overlay": "^0.4.1", - "react-native-material-kit": "^0.4.1", - "react-native-mobx": "^0.3.1", - "react-native-modal-picker": "^0.0.16", - "react-native-onesignal": "^3.0.0", - "react-native-router-flux": "^3.37.0", - "react-native-scrollable-tab-view": "^0.7.2", - "react-native-share": "1.0.19", - "react-native-vector-icons": "^4.0.0", - "react-redux": "^5.0.2", - "redux": "^3.6.0", - "redux-thunk": "^2.2.0" - }, - "devDependencies": { - "babel-jest": "19.0.0", - "babel-preset-es2015": "^6.18.0", - "babel-preset-react-native": "1.9.1", - "eslint-config-rallycoding": "^3.1.0", - "jest": "19.0.2", - "react-test-renderer": "~15.4.1" - }, - "jest": { - "preset": "react-native" - } + "name": "Upstart", + "version": "0.0.1", + "private": true, + "scripts": { + "start": "node node_modules/react-native/local-cli/cli.js start", + "test": "jest" + }, + "dependencies": { + "express": "^4.15.2", + "firebase": "^3.6.9", + "mysql": "^2.13.0", + "react": "~15.4.1", + "react-native": "0.42.0", + "react-native-animatable": "^1.1.0", + "react-native-camera-roll-picker": "^1.1.9", + "react-native-code-push": "1.17.0-beta", + "react-native-drawer": "^2.3.0", + "react-native-elements": "^0.9.7", + "react-native-fetch-blob": "0.10.2-beta.8", + "react-native-gifted-chat": "0.1.1", + "react-native-google-analytics-bridge": "^5.0.0", + "react-native-image-picker": "^0.25.1", + "react-native-keyboard-aware-scroll-view": "^0.2.6", + "react-native-lightbox": "^0.6.0", + "react-native-loading-spinner-overlay": "^0.4.1", + "react-native-material-kit": "^0.4.1", + "react-native-mobx": "^0.3.1", + "react-native-modal-picker": "^0.0.16", + "react-native-onesignal": "^3.0.0", + "react-native-router-flux": "^3.37.0", + "react-native-scrollable-tab-view": "^0.7.2", + "react-native-share": "1.0.19", + "react-native-vector-icons": "^4.0.0", + "react-redux": "^5.0.2", + "redux": "^3.6.0", + "redux-thunk": "^2.2.0" + }, + "devDependencies": { + "babel-jest": "19.0.0", + "babel-preset-es2015": "^6.18.0", + "babel-preset-react-native": "1.9.1", + "eslint-config-rallycoding": "^3.1.0", + "jest": "19.0.2", + "react-test-renderer": "~15.4.1" + }, + "jest": { + "preset": "react-native" + } } diff --git a/src/Router.js b/src/Router.js index 4a3879e..2ba5f17 100644 --- a/src/Router.js +++ b/src/Router.js @@ -16,7 +16,7 @@ const RouterComponent = () => { - + ); diff --git a/src/actions/AuthActions.js b/src/actions/AuthActions.js index 0f962e2..e2bd7d1 100644 --- a/src/actions/AuthActions.js +++ b/src/actions/AuthActions.js @@ -31,13 +31,20 @@ export const nameChanged = (text) => { }; }; - +export const creates = ({ email, password, name, account }) => { + return (dispatch) => { + dispatch({ type: LOGIN_USER }); + firebase.auth().signInWithEmailAndPassword(email, password) + .then(user => loginUserSuccess(dispatch, user)) + .catch(() => loginUserFail(dispatch)); + }; +}; export const loginUser = ({ email, password }) => { return (dispatch) => { + dispatch({ type: LOGIN_USER }); firebase.auth().signInWithEmailAndPassword(email, password) .then(user => loginUserSuccess(dispatch, user)) .catch(() => loginUserFail(dispatch)); - Actions.main(); }; }; @@ -48,13 +55,27 @@ export const signup = () => { }; export const createUser = ({ email, password, name }) => { - const account = 0; + console.log(email, password, name); + const account = { balance: '0' }; return (dispatch) => { dispatch({ type: LOGIN_USER }); - firebase.auth().createUserWithEmailAndPassword(email, password) - .then(user => createUserSuccess(dispatch, user, name, account)) - .catch(() => loginUserFail(dispatch)); - Actions.main(); + firebase.auth().signInWithEmailAndPassword(email, password) + .then(user => loginUserSuccess(dispatch, user)) + .catch(() => { + firebase.auth().createUserWithEmailAndPassword(email, password) + .then(user => loginUserSuccess(dispatch, user)) + .catch(() => loginUserFail(dispatch)); +}); + firebase.auth().onAuthStateChanged(() => { + const { currentUser } = firebase.auth(); + if (email === currentUser.email) { + console.log(email); + console.log(currentUser); + firebase.database().ref(`/users/${currentUser.uid}/`) + .set({ name, email, account }); + Actions.main(); + } +}); }; }; const loginUserFail = (dispatch) => { @@ -64,13 +85,5 @@ const loginUserSuccess = (dispatch, user) => { dispatch({ type: LOGIN_USER_SUCCESS, payload: user }); -}; -const createUserSuccess = (dispatch, user, name, email, account) => { - const { currentUser } = firebase.auth(); - firebase.database().ref(`/users/${currentUser.uid}/`) - .set({ name, email, account }); Actions.main(); - dispatch({ - type: LOGIN_USER_SUCCESS, payload: user - }); }; diff --git a/src/actions/DepositActions.js b/src/actions/DepositActions.js index 8244367..b6673e9 100644 --- a/src/actions/DepositActions.js +++ b/src/actions/DepositActions.js @@ -2,29 +2,45 @@ import firebase from 'firebase'; import { Actions } from 'react-native-router-flux'; import { DEPOSIT, + WITHDRAW, DEPOSIT_CHANGED, DEPOSIT_FAIL, DEPOSIT_SUCCESS, } from './types'; -export const depositChanged = (text) => { +export const depositChanged = ({ prop, value }) => { return { type: DEPOSIT_CHANGED, - payload: text + payload: { prop, value } }; }; -export const deposit = ({ amount }) => { +export const deposit = ({ amount, balance }) => { const { currentUser } = firebase.auth(); - const balance = modify(amount); - + const temp = Number(amount) + Number(balance); + const prop = 'balance'; + balance = temp.toString(); + return (dispatch) => { + firebase.database().ref(`/users/${currentUser.uid}/account`) + .set({ balance }) + .then(() => { + dispatch({ type: DEPOSIT, payload: { prop: balance } }); + Actions.overview(); + }); + }; +}; +export const withdraws = ({ withdraw, balance }) => { + const { currentUser } = firebase.auth(); + const temp = Number(balance) - Number(withdraw); + const prop = 'balance'; + balance = temp.toString(); return (dispatch) => { firebase.database().ref(`/users/${currentUser.uid}/account`) - .push({ balance }) + .set({ balance }) .then(() => { - dispatch({ type: DEPOSIT }); - Actions.balanceList({ type: 'reset' }); + dispatch({ type: DEPOSIT, payload: { prop: balance } }); + Actions.overview(); }); }; }; diff --git a/src/actions/balanceActions.js b/src/actions/balanceActions.js index e86c143..49bab14 100644 --- a/src/actions/balanceActions.js +++ b/src/actions/balanceActions.js @@ -6,9 +6,10 @@ import { export const getBalance = () => { + console.log("here"); const { currentUser } = firebase.auth(); - return (dispatch) => { + console.log('dispatching'); firebase.database().ref(`/users/${currentUser.uid}/account`) .on('value', snapshot => { dispatch({ type: BALANCE_FETCH_SUCCESS, payload: snapshot.val() }); diff --git a/src/components/DepositPage.js b/src/components/DepositPage.js index f9357b2..481f767 100644 --- a/src/components/DepositPage.js +++ b/src/components/DepositPage.js @@ -3,18 +3,23 @@ import { View, ScrollView } from 'react-native'; import { Actions } from 'react-native-router-flux'; import { connect } from 'react-redux'; import { FormLabel, FormInput, Button, PricingCard } from 'react-native-elements'; -import { getBalance, depositChanged, deposit } from '../actions'; +import { getBalance, depositChanged, deposit, withdraws } from '../actions'; class Sliders extends Component { onAmountChange(value) { this.props.depositChanged(value); } - onDepositPress(){ - const { amount } = this.props; - this.props.deposit(amount) + onDepositPress() { + const { amount, balance } = this.props; + this.props.deposit({ amount, balance }); + } + onWithdrawPress() { + const { withdraw, balance } = this.props; + this.props.withdraws({ withdraw, balance }); } render() { - var x = this.props.balance.toString(); + const x = this.props.amount; + const y = this.props.withdraw; return ( - - - Deposit + + + Deposit this.props.depositChanged({ prop: 'amount', value })} />