mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-28 07:55:08 +03:00
Added to fetch user information functionality to splash screen
This commit is contained in:
parent
cd1ed229ba
commit
9d0f2a1e31
@ -5,6 +5,8 @@ import {
|
||||
REMOVE_ACCOUNT_DATA,
|
||||
FETCH_ACCOUNT_FAIL,
|
||||
FETCHING_ACCOUNT,
|
||||
ADD_OTHER_ACCOUNT,
|
||||
UPDATE_CURRENT_ACCOUNT,
|
||||
} from '../constants/constants';
|
||||
|
||||
export const fetchAccountFromSteem = (username, password) => (dispatch) => {
|
||||
@ -33,6 +35,16 @@ export const updateAccountData = data => ({
|
||||
payload: data,
|
||||
});
|
||||
|
||||
export const updateCurrentAccount = data => ({
|
||||
type: UPDATE_CURRENT_ACCOUNT,
|
||||
payload: data,
|
||||
});
|
||||
|
||||
export const addOtherAccount = data => ({
|
||||
type: ADD_OTHER_ACCOUNT,
|
||||
payload: data,
|
||||
});
|
||||
|
||||
export const removeAccountData = data => ({
|
||||
type: REMOVE_ACCOUNT_DATA,
|
||||
payload: data,
|
||||
|
@ -14,6 +14,9 @@ export const REMOVE_ACCOUNT_DATA = 'REMOVE_ACCOUNT_DATA';
|
||||
export const FETCHING_ACCOUNT = 'FETCHING_ACCOUNT';
|
||||
export const FETCH_ACCOUNT_FAIL = 'FETCH_ACCOUNT_FAIL';
|
||||
|
||||
export const ADD_OTHER_ACCOUNT = 'ADD_OTHER_ACCOUNT';
|
||||
export const UPDATE_CURRENT_ACCOUNT = 'UPDATE_CURRENT_ACCOUNT';
|
||||
|
||||
export const IS_LOGGED_IN = 'IS_LOGGED_IN';
|
||||
export const OPEN_PIN_CODE_MODAL = 'OPEN_PIN_CODE_MODAL';
|
||||
export const CLOSE_PIN_CODE_MODAL = 'CLOSE_PIN_CODE_MODAL';
|
||||
|
@ -4,10 +4,14 @@ import {
|
||||
REMOVE_ACCOUNT_DATA,
|
||||
FETCH_ACCOUNT_FAIL,
|
||||
FETCHING_ACCOUNT,
|
||||
ADD_OTHER_ACCOUNT,
|
||||
UPDATE_CURRENT_ACCOUNT,
|
||||
} from '../constants/constants';
|
||||
|
||||
const initialState = {
|
||||
isFetching: null,
|
||||
otherAccounts: [],
|
||||
currentAccount: {},
|
||||
data: {
|
||||
accounts: [],
|
||||
currentAccountId: null,
|
||||
@ -60,6 +64,23 @@ export default function (state = initialState, action) {
|
||||
errorMessage: null,
|
||||
});
|
||||
|
||||
case ADD_OTHER_ACCOUNT:
|
||||
return {
|
||||
...state,
|
||||
otherAccounts: [...state.otherAccounts, action.payload],
|
||||
isFetching: false,
|
||||
hasError: false,
|
||||
errorMessage: null,
|
||||
};
|
||||
|
||||
case UPDATE_CURRENT_ACCOUNT:
|
||||
return {
|
||||
...state,
|
||||
currentAccount: action.payload,
|
||||
isFetching: false,
|
||||
hasError: false,
|
||||
errorMessage: null,
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
@ -24,8 +24,8 @@ const RootContainer = () => (WrappedComponent) => {
|
||||
}
|
||||
|
||||
componentWillMount() {
|
||||
const { isActive, navigation } = this.props;
|
||||
if (!isActive) {
|
||||
const { isActiveApp, navigation } = this.props;
|
||||
if (!isActiveApp) {
|
||||
navigation.navigate(ROUTES.SCREENS.SPLASH);
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,13 @@
|
||||
import React, { Component } from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
|
||||
import { getUserData, getAuthStatus } from '../../../realm/realm';
|
||||
import { getAccount } from '../../../providers/steem/dsteem';
|
||||
|
||||
// Actions
|
||||
import { addOtherAccount, updateCurrentAccount } from '../../../redux/actions/accountAction';
|
||||
import { activeApplication, login } from '../../../redux/actions/applicationActions';
|
||||
|
||||
// Constants
|
||||
import { default as ROUTES } from '../../../constants/routeNames';
|
||||
|
||||
@ -14,27 +19,22 @@ class SplashContainer extends Component {
|
||||
};
|
||||
|
||||
_getUserData = () => {
|
||||
const { navigation } = this.props;
|
||||
const { navigation, dispatch } = this.props;
|
||||
|
||||
getAuthStatus().then((res) => {
|
||||
console.log('=========res=========', res);
|
||||
if (res) {
|
||||
getUserData().then((response) => {
|
||||
console.log('=========response=========', response);
|
||||
|
||||
if (response.length > 0) {
|
||||
// TODO: Set other users
|
||||
response.forEach((accountData) => {
|
||||
dispatch(addOtherAccount(accountData));
|
||||
});
|
||||
getAccount(response[response.length - 1].username).then((accountData) => {
|
||||
console.log('=========accountData=========', accountData);
|
||||
dispatch(updateCurrentAccount(...accountData));
|
||||
dispatch(activeApplication());
|
||||
dispatch(login());
|
||||
navigation.navigate(ROUTES.DRAWER.MAIN);
|
||||
});
|
||||
}
|
||||
|
||||
// if (response) {
|
||||
// navigation.navigate(ROUTES.SCREENS.PINCODE);
|
||||
// // navigation.navigate(ROUTES.DRAWER.MAIN);
|
||||
// } else {
|
||||
// navigation.navigate(ROUTES.SCREENS.LOGIN);
|
||||
// }
|
||||
});
|
||||
} else {
|
||||
navigation.navigate(ROUTES.DRAWER.MAIN);
|
||||
@ -47,4 +47,4 @@ class SplashContainer extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
export default SplashContainer;
|
||||
export default connect()(SplashContainer);
|
||||
|
Loading…
Reference in New Issue
Block a user