side menu bug fixed && current user switch fixed

This commit is contained in:
ue 2018-12-10 17:06:20 +03:00
parent 98d2351aff
commit b6825a4416
4 changed files with 22 additions and 13 deletions

View File

@ -36,7 +36,7 @@ class SideMenuContainer extends Component {
userData.forEach((element) => {
accounts.push({
name: `@${element.username}`,
username: element.username
username: element.username,
});
});
accounts.push({
@ -58,14 +58,15 @@ class SideMenuContainer extends Component {
}
};
_switchAccount = (username = null) => {
const { dispatch } = this.props;
username = username.slice(1);
switchAccount(username).then((accountData) => {
dispatch(updateCurrentAccount(accountData));
dispatch(openPinCodeModal());
});
_switchAccount = (anchor = null) => {
const { dispatch, currentAccount } = this.props;
const username = anchor.slice(1);
if (username !== currentAccount.name) {
switchAccount(username).then((accountData) => {
dispatch(updateCurrentAccount(accountData));
dispatch(openPinCodeModal());
});
}
};
render() {

View File

@ -67,6 +67,8 @@ export const Login = (username, password) => {
accessToken: '',
};
account.local = userData;
// Save user data to Realm DB
setUserData(userData)
.then(() => {

View File

@ -112,11 +112,10 @@ class ApplicationContainer extends Component {
};
_getSettings = () => {
const { dispatch, isLoggedIn } = this.props;
const { dispatch } = this.props;
getSettings().then((response) => {
if (response) {
console.log(response);
response.isDarkTheme && dispatch(isDarkTheme(response.isDarkTheme));
response.language && dispatch(setLanguage(response.language));
response.currency && dispatch(setCurrency(response.currency));

View File

@ -7,9 +7,9 @@ import { setUserDataWithPinCode, verifyPinCode } from '../../../providers/steem/
// Actions & Services
import { closePinCodeModal } from '../../../redux/actions/applicationActions';
import { getExistUser, setExistUser, getUserData } from '../../../realm/realm';
import { getExistUser, setExistUser, getUserData, getUserDataWithUsername } from '../../../realm/realm';
import { updateCurrentAccount } from '../../../redux/actions/accountAction';
import {formatAccount } from "../../../utils/user";
import { formatAccount } from '../../../utils/user';
import { PinCodeScreen } from '..';
class PinCodeContainer extends Component {
@ -78,6 +78,13 @@ class PinCodeContainer extends Component {
.then((res) => {
setWrappedComponentState(res);
dispatch(closePinCodeModal());
const realmData = getUserDataWithUsername(currentAccount.name);
const _currentAccount = currentAccount;
_currentAccount.username = _currentAccount.name;
_currentAccount.local = realmData[0];
dispatch(updateCurrentAccount({ ..._currentAccount }));
if (navigateTo) {
navigation.navigate(navigateTo);
}