Moved auth errors to language files

This commit is contained in:
Mustafa Buyukcelebi 2019-01-09 12:42:59 +03:00
parent ce9cdfcdd3
commit 20eb753d23
5 changed files with 37 additions and 16 deletions

View File

@ -137,5 +137,12 @@
"post": {
"reblog_alert": "Are you sure you want to reblog?",
"reblog_cancel": "Cancel"
},
"auth": {
"invalid_pin": "Invalid pin code, please check and try again",
"invalid_username": "Invalid username, please check and try again",
"already_logged": "You are already logged in, please try to add another account",
"invalid_credentials": "Invalid credentials, please check and try again",
"unknow_error": "Unknown error, please contact to eSteem."
}
}

View File

@ -138,6 +138,13 @@
"post": {
"reblog_alert": "Reblog yapma istediginize emin misiniz?",
"reblog_cancel": "Vazgeç"
},
"auth": {
"invalid_pin": "Geçersiz pin kod, lütfen kontrol ediniz ve tekrar deneyin.",
"invalid_username": "Geçersiz kullanıcı adı, lütfen kontrol ediniz ve tekrar deneyin.",
"already_logged": "Bu kullanıcı ile giriş yaptınız, lütfen farklı bir kullanıcı bilgileri ile giriş yapınız.",
"invalid_credentials": "Geçersiz pin kod, lütfen kontrol ediniz ve tekrar deneyin.",
"unknow_error": "Bilinmeyen hata, lütfen eSteem ile iletişime geçiniz"
}
}

View File

@ -25,11 +25,11 @@ export const login = async (username, password) => {
// Get user account data from STEEM Blockchain
const account = await getUser(username);
if (!account) {
return Promise.reject(new Error('Invalid pin code, please check and try again'));
return Promise.reject(new Error('auth.invalid_username'));
}
if (isLoggedInUser(username)) {
return Promise.reject(
new Error('You are already logged in, please try to add another account'),
new Error('auth.already_logged'),
);
}
// Public keys of user
@ -86,7 +86,7 @@ export const login = async (username, password) => {
await updateCurrentUsername(account.name);
return { ...account, password };
}
return Promise.reject(new Error('Invalid pin code, please check and try again'));
return Promise.reject(new Error('auth.invalid_pin'));
};
export const loginWithSC2 = async (code) => {
@ -102,7 +102,7 @@ export const loginWithSC2 = async (code) => {
avatar = jsonMetadata.profile.profile_image || '';
}
} catch (error) {
reject(new Error('Invalid credentials, please check and try again'));
reject(new Error('auth.invalid_credentials'));
}
const userData = {
username: account.account.name,
@ -116,7 +116,7 @@ export const loginWithSC2 = async (code) => {
};
if (isLoggedInUser(account.account.name)) {
reject(new Error('You are already logged in, please try to add another account'));
reject(new Error('auth.already_logged'));
}
setUserData(userData)
@ -149,7 +149,7 @@ export const setUserDataWithPinCode = async (data) => {
return updatedUserData;
} catch (error) {
return Promise.reject(new Error('Unknown error, please contact to eSteem.'));
return Promise.reject(new Error('auth.unknow_error'));
}
};
@ -171,7 +171,7 @@ export const updatePinCode = async (data) => {
}
return false;
} catch (error) {
return Promise.reject(new Error('Unknown error, please contact to eSteem.'));
return Promise.reject(new Error('auth.unknow_error'));
}
};
@ -179,7 +179,7 @@ export const verifyPinCode = async (data) => {
const pinHash = await getPinCode();
if (sha256(data.pinCode).toString() !== pinHash) {
return Promise.reject(new Error('Invalid pin code, please check and try again'));
return Promise.reject(new Error('auth.invalid_pin'));
}
const result = getUserDataWithUsername(data.username);
@ -212,11 +212,11 @@ export const switchAccount = username => new Promise((resolve, reject) => {
resolve(account);
})
.catch(() => {
reject(new Error('Unknown error, please contact to eSteem.'));
reject(new Error('auth.unknow_error'));
});
})
.catch(() => {
reject(new Error('Unknown error, please contact to eSteem.'));
reject(new Error('auth.unknow_error'));
});
});

View File

@ -1,6 +1,7 @@
import React, { PureComponent } from 'react';
import { Alert, Linking } from 'react-native';
import { connect } from 'react-redux';
import { injectIntl } from 'react-intl';
// Services and Actions
import { login } from '../../../providers/steem/auth';
@ -42,7 +43,7 @@ class LoginContainer extends PureComponent {
// Component Functions
_handleOnPressLogin = (username, password) => {
const { dispatch, setPinCodeState } = this.props;
const { dispatch, setPinCodeState, intl } = this.props;
this.setState({ isLoading: true });
@ -57,8 +58,10 @@ class LoginContainer extends PureComponent {
}
})
.catch((err) => {
// TODO: Change with global error handling
Alert.alert('Error', err.message);
Alert.alert('Error',
intl.formatMessage({
id: err.message,
}));
dispatch(failedAccount(err.message));
this.setState({ isLoading: false });
});
@ -93,4 +96,4 @@ const mapStateToProps = state => ({
account: state.accounts,
});
export default connect(mapStateToProps)(LoginContainer);
export default injectIntl(connect(mapStateToProps)(LoginContainer));

View File

@ -114,7 +114,9 @@ class PinCodeContainer extends Component {
.catch((err) => {
Alert.alert(intl.formatMessage({
id: 'alert.warning',
}), err.message);
}), intl.formatMessage({
id: err.message,
}));
reject(err);
});
}
@ -183,7 +185,9 @@ class PinCodeContainer extends Component {
.catch((err) => {
Alert.alert(intl.formatMessage({
id: 'alert.warning',
}), err.message);
}), intl.formatMessage({
id: err.message,
}));
reject(err);
});
});