From a7710b013b0c60c84ffb32345db103e4eda8008d Mon Sep 17 00:00:00 2001 From: mistikk Date: Thu, 8 Nov 2018 11:44:26 +0100 Subject: [PATCH 1/2] Fixed pin code bug after first login --- src/providers/steem/auth.js | 25 ++++++++++--------------- src/redux/actions/accountAction.js | 6 +++--- src/redux/actions/userActions.js | 6 +++--- 3 files changed, 16 insertions(+), 21 deletions(-) diff --git a/src/providers/steem/auth.js b/src/providers/steem/auth.js index e74e38539..16d9858de 100644 --- a/src/providers/steem/auth.js +++ b/src/providers/steem/auth.js @@ -1,5 +1,5 @@ import * as dsteem from 'dsteem'; -import { getAccount } from './dsteem'; +import { getUser } from './dsteem'; import { setUserData, setAuthStatus, @@ -26,16 +26,12 @@ export const Login = (username, password) => { return new Promise((resolve, reject) => { // Get user account data from STEEM Blockchain - getAccount(username) - .then((result) => { + getUser(username) + .then((account) => { if (isLoggedInUser(username)) { reject(new Error('You are already logged in, please try to add another account')); - } else if (result.length < 1) { - reject(new Error('Invalid credentails, please check and try again')); } - const account = result[0]; - // Public keys of user publicKeys = { active: account.active.key_auths.map(x => x[0]), @@ -208,14 +204,14 @@ export const verifyPinCode = async (data) => { } } else if (userData.authType === 'masterKey') { const password = decryptKey(userData.masterKey, data.pinCode); - account = await getAccount(data.username); + account = await getUser(data.username); // Public keys of user const publicKeys = { - active: account[0].active.key_auths.map(x => x[0]), - memo: account[0].memo_key, - owner: account[0].owner.key_auths.map(x => x[0]), - posting: account[0].posting.key_auths.map(x => x[0]), + active: account.active.key_auths.map(x => x[0]), + memo: account.memo_key, + owner: account.owner.key_auths.map(x => x[0]), + posting: account.posting.key_auths.map(x => x[0]), }; // Set private keys of user const privateKeys = getPrivateKeys(data.username, password); @@ -267,9 +263,8 @@ export const verifyPinCode = async (data) => { }; export const switchAccount = username => new Promise((resolve, reject) => { - getAccount(username) - .then((result) => { - const account = result[0]; + getUser(username) + .then((account) => { updateCurrentUsername(username).then(() => { resolve(account); }).catch(() => { diff --git a/src/redux/actions/accountAction.js b/src/redux/actions/accountAction.js index 350540f4d..28b83f2f3 100644 --- a/src/redux/actions/accountAction.js +++ b/src/redux/actions/accountAction.js @@ -1,4 +1,4 @@ -import { getAccount } from '../../providers/steem/dsteem'; +import { getUser } from '../../providers/steem/dsteem'; import { FETCH_ACCOUNT_FAIL, FETCHING_ACCOUNT, @@ -9,10 +9,10 @@ import { export const fetchAccountFromSteem = (username, password) => (dispatch) => { dispatch({ type: FETCHING_ACCOUNT }); - return getAccount(username) + return getUser(username) .then(res => dispatch({ type: UPDATE_CURRENT_ACCOUNT, - payload: { ...res[0], password }, + payload: { ...res, password }, })) .catch(err => dispatch({ type: FETCH_ACCOUNT_FAIL, payload: err })); }; diff --git a/src/redux/actions/userActions.js b/src/redux/actions/userActions.js index d49c29f63..3436aec0c 100644 --- a/src/redux/actions/userActions.js +++ b/src/redux/actions/userActions.js @@ -1,4 +1,4 @@ -import { getAccount } from '../../providers/steem/dsteem'; +import { getUser } from '../../providers/steem/dsteem'; import { FETCH_USER, FETCH_USER_SUCCESS, @@ -18,8 +18,8 @@ export function fetchAccount(user) { return (dispatch) => { dispatch({ type: FETCH_USER }); - return getAccount(user) - .then(res => dispatch({ type: FETCH_USER_SUCCESS, payload: res[0] })) + return getUser(user) + .then(res => dispatch({ type: FETCH_USER_SUCCESS, payload: res })) .catch(err => dispatch({ type: FETCH_USER_FAIL, payload: err })); }; } From 200da3eedc6a54dff588e1f2732ba35e2710e6d9 Mon Sep 17 00:00:00 2001 From: mistikk Date: Thu, 8 Nov 2018 14:00:39 +0100 Subject: [PATCH 2/2] Added user avatar to pin code screen --- src/screens/pinCode/container/pinCodeContainer.js | 13 +++++++++++++ src/screens/pinCode/screen/pinCodeScreen.js | 10 ++++++---- src/screens/pinCode/screen/pinCodeStyles.js | 2 ++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/screens/pinCode/container/pinCodeContainer.js b/src/screens/pinCode/container/pinCodeContainer.js index 9585386ba..eb5bc63b2 100644 --- a/src/screens/pinCode/container/pinCodeContainer.js +++ b/src/screens/pinCode/container/pinCodeContainer.js @@ -12,6 +12,8 @@ import { default as INITIAL } from '../../../constants/initial'; import { PinCodeScreen } from '..'; +const DEFAULT_IMAGE = require('../../../assets/esteem.png'); + class PinCodeContainer extends Component { constructor(props) { super(props); @@ -117,6 +119,16 @@ class PinCodeContainer extends Component { } }); + _getUserAvatar = () => { + const { currentAccount } = this.props; + if (Object.keys(currentAccount).length === 0) return DEFAULT_IMAGE; + if (Object.keys(currentAccount.about).length === 0) return DEFAULT_IMAGE; + if (Object.keys(currentAccount.about.profile).length !== 0) { + return { uri: currentAccount.about.profile.profile_image }; + } + return DEFAULT_IMAGE; + }; + render() { const { currentAccount } = this.props; const { informationText, isExistUser } = this.state; @@ -126,6 +138,7 @@ class PinCodeContainer extends Component { setPinCode={this._setPinCode} showForgotButton={isExistUser} username={currentAccount ? currentAccount.name : 'unknow'} + avatar={this._getUserAvatar()} /> ); } diff --git a/src/screens/pinCode/screen/pinCodeScreen.js b/src/screens/pinCode/screen/pinCodeScreen.js index d6a248e95..ad4523a8d 100644 --- a/src/screens/pinCode/screen/pinCodeScreen.js +++ b/src/screens/pinCode/screen/pinCodeScreen.js @@ -1,8 +1,8 @@ import React, { Component } from 'react'; import { Text, TouchableOpacity, View } from 'react-native'; -import { Container } from 'native-base'; +import { Container, Thumbnail } from 'native-base'; -import { Logo, NumericKeyboard, PinAnimatedInput } from '../../../components'; +import { NumericKeyboard, PinAnimatedInput } from '../../../components'; import styles from './pinCodeStyles'; @@ -46,13 +46,15 @@ class PinCodeScreen extends Component { }; render() { - const { informationText, showForgotButton, username } = this.props; + const { + informationText, showForgotButton, username, avatar, + } = this.props; const { pin } = this.state; return ( - + {`@${username}`} diff --git a/src/screens/pinCode/screen/pinCodeStyles.js b/src/screens/pinCode/screen/pinCodeStyles.js index 5370444ba..4548e0b78 100644 --- a/src/screens/pinCode/screen/pinCodeStyles.js +++ b/src/screens/pinCode/screen/pinCodeStyles.js @@ -7,6 +7,8 @@ export default EStyleSheet.create({ }, logoView: { flex: 2, + justifyContent: 'center', + alignItems: 'center', }, logo: { width: '$deviceWidth / 7',