Merge pull request #597 from esteemapp/bugfix/#562

Bugfix/#562
This commit is contained in:
uğur erdal 2019-02-14 11:24:03 +03:00 committed by GitHub
commit 660086d139
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 23 deletions

View File

@ -29,28 +29,27 @@ class SideMenuContainer extends Component {
}
// Component Life Cycle Functions
componentWillMount() {
const { otherAccounts } = this.props;
this._createUserList(otherAccounts);
}
componentWillReceiveProps(nextProps) {
const { otherAccounts, isLoggedIn } = this.props;
const { isLoggedIn } = this.props;
if (isLoggedIn && otherAccounts !== nextProps.otherAccounts) {
if (isLoggedIn) {
this._createUserList(nextProps.otherAccounts);
}
}
_createUserList = (otherAccounts) => {
const { currentAccount } = this.props;
const accounts = [];
otherAccounts.forEach((element) => {
accounts.push({
name: `@${element.username}`,
username: element.username,
id: element.username,
});
if (element.username !== currentAccount.name) {
accounts.push({
name: `@${element.username}`,
username: element.username,
id: element.username,
});
}
});
accounts.push({
name: 'Add Account',

View File

@ -89,7 +89,7 @@ export const login = async (username, password) => {
await updateCurrentUsername(account.name);
return { ...account, password };
}
return Promise.reject(new Error('auth.invalid_pin'));
return Promise.reject(new Error('auth.invalid_credentials'));
};
export const loginWithSC2 = async (code) => {

View File

@ -282,17 +282,17 @@ class ApplicationContainer extends Component {
});
};
_logout = () => {
_logout = async () => {
const { otherAccounts, currentAccount, dispatch } = this.props;
removeUserData(currentAccount.name)
.then(() => {
await removeUserData(currentAccount.name)
.then(async () => {
const _otherAccounts = otherAccounts.filter(user => user.username !== currentAccount.name);
if (_otherAccounts.length > 0) {
const targetAccountUsername = _otherAccounts[0].username;
this._switchAccount(targetAccountUsername);
await this._switchAccount(targetAccountUsername);
} else {
dispatch(updateCurrentAccount({}));
dispatch(login(false));
@ -310,10 +310,10 @@ class ApplicationContainer extends Component {
.catch(() => {});
};
_switchAccount = (targetAccountUsername) => {
_switchAccount = async (targetAccountUsername) => {
const { dispatch } = this.props;
switchAccount(targetAccountUsername).then((accountData) => {
await switchAccount(targetAccountUsername).then((accountData) => {
const realmData = getUserDataWithUsername(targetAccountUsername);
const _currentAccount = accountData;
_currentAccount.username = accountData.name;
@ -324,7 +324,7 @@ class ApplicationContainer extends Component {
};
render() {
const { selectedLanguage, isConnected, toastNotification} = this.props;
const { selectedLanguage, isConnected, toastNotification } = this.props;
const { isRenderRequire, isReady } = this.state;
// For testing It comented out.
@ -335,7 +335,12 @@ class ApplicationContainer extends Component {
if (isRenderRequire && isReady) {
return (
<ApplicationScreen isConnected={isConnected} locale={selectedLanguage} toastNotification={toastNotification} {...this.props} />
<ApplicationScreen
isConnected={isConnected}
locale={selectedLanguage}
toastNotification={toastNotification}
{...this.props}
/>
);
}
return <Launch />;
@ -360,9 +365,9 @@ export default connect(
pinCode: state.account.pin,
// UI
toastNotification: state.ui.toastNotification
toastNotification: state.ui.toastNotification,
}),
(dispatch, props) => ({
dispatch => ({
dispatch,
actions: {
...bindActionCreators({ fetchGlobalProperties }, dispatch),