From 20eb753d231ac9ee39d9c3423964a560131dd423 Mon Sep 17 00:00:00 2001 From: Mustafa Buyukcelebi Date: Wed, 9 Jan 2019 12:42:59 +0300 Subject: [PATCH] Moved auth errors to language files --- src/config/locales/en-US.json | 7 +++++++ src/config/locales/tr-TR.json | 7 +++++++ src/providers/steem/auth.js | 20 +++++++++---------- src/screens/login/container/loginContainer.js | 11 ++++++---- .../pinCode/container/pinCodeContainer.js | 8 ++++++-- 5 files changed, 37 insertions(+), 16 deletions(-) diff --git a/src/config/locales/en-US.json b/src/config/locales/en-US.json index 9290dbfd2..00a5ea5d4 100644 --- a/src/config/locales/en-US.json +++ b/src/config/locales/en-US.json @@ -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." } } diff --git a/src/config/locales/tr-TR.json b/src/config/locales/tr-TR.json index d0d6f2c46..ceecd43df 100644 --- a/src/config/locales/tr-TR.json +++ b/src/config/locales/tr-TR.json @@ -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" } } diff --git a/src/providers/steem/auth.js b/src/providers/steem/auth.js index a08080a4b..24089b566 100644 --- a/src/providers/steem/auth.js +++ b/src/providers/steem/auth.js @@ -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')); }); }); diff --git a/src/screens/login/container/loginContainer.js b/src/screens/login/container/loginContainer.js index f5fc9dc1e..45e8bd236 100644 --- a/src/screens/login/container/loginContainer.js +++ b/src/screens/login/container/loginContainer.js @@ -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)); diff --git a/src/screens/pinCode/container/pinCodeContainer.js b/src/screens/pinCode/container/pinCodeContainer.js index 624880456..a23912a6b 100644 --- a/src/screens/pinCode/container/pinCodeContainer.js +++ b/src/screens/pinCode/container/pinCodeContainer.js @@ -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); }); });