mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-02 11:15:35 +03:00
commit
660086d139
@ -29,28 +29,27 @@ class SideMenuContainer extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Component Life Cycle Functions
|
// Component Life Cycle Functions
|
||||||
componentWillMount() {
|
|
||||||
const { otherAccounts } = this.props;
|
|
||||||
|
|
||||||
this._createUserList(otherAccounts);
|
|
||||||
}
|
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
componentWillReceiveProps(nextProps) {
|
||||||
const { otherAccounts, isLoggedIn } = this.props;
|
const { isLoggedIn } = this.props;
|
||||||
|
|
||||||
if (isLoggedIn && otherAccounts !== nextProps.otherAccounts) {
|
if (isLoggedIn) {
|
||||||
this._createUserList(nextProps.otherAccounts);
|
this._createUserList(nextProps.otherAccounts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_createUserList = (otherAccounts) => {
|
_createUserList = (otherAccounts) => {
|
||||||
|
const { currentAccount } = this.props;
|
||||||
|
|
||||||
const accounts = [];
|
const accounts = [];
|
||||||
otherAccounts.forEach((element) => {
|
otherAccounts.forEach((element) => {
|
||||||
|
if (element.username !== currentAccount.name) {
|
||||||
accounts.push({
|
accounts.push({
|
||||||
name: `@${element.username}`,
|
name: `@${element.username}`,
|
||||||
username: element.username,
|
username: element.username,
|
||||||
id: element.username,
|
id: element.username,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
accounts.push({
|
accounts.push({
|
||||||
name: 'Add Account',
|
name: 'Add Account',
|
||||||
|
@ -89,7 +89,7 @@ export const login = async (username, password) => {
|
|||||||
await updateCurrentUsername(account.name);
|
await updateCurrentUsername(account.name);
|
||||||
return { ...account, password };
|
return { ...account, password };
|
||||||
}
|
}
|
||||||
return Promise.reject(new Error('auth.invalid_pin'));
|
return Promise.reject(new Error('auth.invalid_credentials'));
|
||||||
};
|
};
|
||||||
|
|
||||||
export const loginWithSC2 = async (code) => {
|
export const loginWithSC2 = async (code) => {
|
||||||
|
@ -282,17 +282,17 @@ class ApplicationContainer extends Component {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
_logout = () => {
|
_logout = async () => {
|
||||||
const { otherAccounts, currentAccount, dispatch } = this.props;
|
const { otherAccounts, currentAccount, dispatch } = this.props;
|
||||||
|
|
||||||
removeUserData(currentAccount.name)
|
await removeUserData(currentAccount.name)
|
||||||
.then(() => {
|
.then(async () => {
|
||||||
const _otherAccounts = otherAccounts.filter(user => user.username !== currentAccount.name);
|
const _otherAccounts = otherAccounts.filter(user => user.username !== currentAccount.name);
|
||||||
|
|
||||||
if (_otherAccounts.length > 0) {
|
if (_otherAccounts.length > 0) {
|
||||||
const targetAccountUsername = _otherAccounts[0].username;
|
const targetAccountUsername = _otherAccounts[0].username;
|
||||||
|
|
||||||
this._switchAccount(targetAccountUsername);
|
await this._switchAccount(targetAccountUsername);
|
||||||
} else {
|
} else {
|
||||||
dispatch(updateCurrentAccount({}));
|
dispatch(updateCurrentAccount({}));
|
||||||
dispatch(login(false));
|
dispatch(login(false));
|
||||||
@ -310,10 +310,10 @@ class ApplicationContainer extends Component {
|
|||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
};
|
};
|
||||||
|
|
||||||
_switchAccount = (targetAccountUsername) => {
|
_switchAccount = async (targetAccountUsername) => {
|
||||||
const { dispatch } = this.props;
|
const { dispatch } = this.props;
|
||||||
|
|
||||||
switchAccount(targetAccountUsername).then((accountData) => {
|
await switchAccount(targetAccountUsername).then((accountData) => {
|
||||||
const realmData = getUserDataWithUsername(targetAccountUsername);
|
const realmData = getUserDataWithUsername(targetAccountUsername);
|
||||||
const _currentAccount = accountData;
|
const _currentAccount = accountData;
|
||||||
_currentAccount.username = accountData.name;
|
_currentAccount.username = accountData.name;
|
||||||
@ -324,7 +324,7 @@ class ApplicationContainer extends Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { selectedLanguage, isConnected, toastNotification} = this.props;
|
const { selectedLanguage, isConnected, toastNotification } = this.props;
|
||||||
const { isRenderRequire, isReady } = this.state;
|
const { isRenderRequire, isReady } = this.state;
|
||||||
|
|
||||||
// For testing It comented out.
|
// For testing It comented out.
|
||||||
@ -335,7 +335,12 @@ class ApplicationContainer extends Component {
|
|||||||
|
|
||||||
if (isRenderRequire && isReady) {
|
if (isRenderRequire && isReady) {
|
||||||
return (
|
return (
|
||||||
<ApplicationScreen isConnected={isConnected} locale={selectedLanguage} toastNotification={toastNotification} {...this.props} />
|
<ApplicationScreen
|
||||||
|
isConnected={isConnected}
|
||||||
|
locale={selectedLanguage}
|
||||||
|
toastNotification={toastNotification}
|
||||||
|
{...this.props}
|
||||||
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return <Launch />;
|
return <Launch />;
|
||||||
@ -360,9 +365,9 @@ export default connect(
|
|||||||
pinCode: state.account.pin,
|
pinCode: state.account.pin,
|
||||||
|
|
||||||
// UI
|
// UI
|
||||||
toastNotification: state.ui.toastNotification
|
toastNotification: state.ui.toastNotification,
|
||||||
}),
|
}),
|
||||||
(dispatch, props) => ({
|
dispatch => ({
|
||||||
dispatch,
|
dispatch,
|
||||||
actions: {
|
actions: {
|
||||||
...bindActionCreators({ fetchGlobalProperties }, dispatch),
|
...bindActionCreators({ fetchGlobalProperties }, dispatch),
|
||||||
|
Loading…
Reference in New Issue
Block a user