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": { "post": {
"reblog_alert": "Are you sure you want to reblog?", "reblog_alert": "Are you sure you want to reblog?",
"reblog_cancel": "Cancel" "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": { "post": {
"reblog_alert": "Reblog yapma istediginize emin misiniz?", "reblog_alert": "Reblog yapma istediginize emin misiniz?",
"reblog_cancel": "Vazgeç" "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 // Get user account data from STEEM Blockchain
const account = await getUser(username); const account = await getUser(username);
if (!account) { 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)) { if (isLoggedInUser(username)) {
return Promise.reject( 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 // Public keys of user
@ -86,7 +86,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('Invalid pin code, please check and try again')); return Promise.reject(new Error('auth.invalid_pin'));
}; };
export const loginWithSC2 = async (code) => { export const loginWithSC2 = async (code) => {
@ -102,7 +102,7 @@ export const loginWithSC2 = async (code) => {
avatar = jsonMetadata.profile.profile_image || ''; avatar = jsonMetadata.profile.profile_image || '';
} }
} catch (error) { } catch (error) {
reject(new Error('Invalid credentials, please check and try again')); reject(new Error('auth.invalid_credentials'));
} }
const userData = { const userData = {
username: account.account.name, username: account.account.name,
@ -116,7 +116,7 @@ export const loginWithSC2 = async (code) => {
}; };
if (isLoggedInUser(account.account.name)) { 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) setUserData(userData)
@ -149,7 +149,7 @@ export const setUserDataWithPinCode = async (data) => {
return updatedUserData; return updatedUserData;
} catch (error) { } 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; return false;
} catch (error) { } 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(); const pinHash = await getPinCode();
if (sha256(data.pinCode).toString() !== pinHash) { 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); const result = getUserDataWithUsername(data.username);
@ -212,11 +212,11 @@ export const switchAccount = username => new Promise((resolve, reject) => {
resolve(account); resolve(account);
}) })
.catch(() => { .catch(() => {
reject(new Error('Unknown error, please contact to eSteem.')); reject(new Error('auth.unknow_error'));
}); });
}) })
.catch(() => { .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 React, { PureComponent } from 'react';
import { Alert, Linking } from 'react-native'; import { Alert, Linking } from 'react-native';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { injectIntl } from 'react-intl';
// Services and Actions // Services and Actions
import { login } from '../../../providers/steem/auth'; import { login } from '../../../providers/steem/auth';
@ -42,7 +43,7 @@ class LoginContainer extends PureComponent {
// Component Functions // Component Functions
_handleOnPressLogin = (username, password) => { _handleOnPressLogin = (username, password) => {
const { dispatch, setPinCodeState } = this.props; const { dispatch, setPinCodeState, intl } = this.props;
this.setState({ isLoading: true }); this.setState({ isLoading: true });
@ -57,8 +58,10 @@ class LoginContainer extends PureComponent {
} }
}) })
.catch((err) => { .catch((err) => {
// TODO: Change with global error handling Alert.alert('Error',
Alert.alert('Error', err.message); intl.formatMessage({
id: err.message,
}));
dispatch(failedAccount(err.message)); dispatch(failedAccount(err.message));
this.setState({ isLoading: false }); this.setState({ isLoading: false });
}); });
@ -93,4 +96,4 @@ const mapStateToProps = state => ({
account: state.accounts, 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) => { .catch((err) => {
Alert.alert(intl.formatMessage({ Alert.alert(intl.formatMessage({
id: 'alert.warning', id: 'alert.warning',
}), err.message); }), intl.formatMessage({
id: err.message,
}));
reject(err); reject(err);
}); });
} }
@ -183,7 +185,9 @@ class PinCodeContainer extends Component {
.catch((err) => { .catch((err) => {
Alert.alert(intl.formatMessage({ Alert.alert(intl.formatMessage({
id: 'alert.warning', id: 'alert.warning',
}), err.message); }), intl.formatMessage({
id: err.message,
}));
reject(err); reject(err);
}); });
}); });