Working on pin code

This commit is contained in:
mistikk 2018-10-29 18:18:34 +03:00
parent 2f6e6fb515
commit b200444174
5 changed files with 47 additions and 19 deletions

View File

@ -199,9 +199,16 @@ export const verifyPinCode = async (data) => {
const authData = {
isLoggedIn: true,
};
const response = {
accessToken: decryptKey(userData.accessToken, data.pinCode),
postingKey: decryptKey(userData.postingKey, data.pinCode),
masterKey: decryptKey(userData.masterKey, data.pinCode),
activeKey: decryptKey(userData.activeKey, data.pinCode),
memoKey: decryptKey(userData.memoKey, data.pinCode),
};
setAuthStatus(authData)
.then(() => {
resolve();
resolve(response);
})
.catch((error) => {
// TODO: create function for throw error

View File

@ -43,7 +43,7 @@ class LoginScreen extends Component {
}
_handleOnPressLogin = () => {
const { dispatch, navigation } = this.props;
const { dispatch, setPinCodeState } = this.props;
const { password, username } = this.state;
this.setState({ isLoading: true });
@ -53,8 +53,8 @@ class LoginScreen extends Component {
if (result) {
dispatch(addPassiveAccount(result));
dispatch(loginAction());
navigation.navigate(ROUTES.DRAWER.MAIN);
dispatch(openPinCodeModal());
setPinCodeState({ navigateTo: ROUTES.DRAWER.MAIN });
}
})
.catch((err) => {

View File

@ -9,7 +9,6 @@ import { closePinCodeModal } from '../../../redux/actions/applicationActions';
// Constants
import { default as INITIAL } from '../../../constants/initial';
import { default as ROUTES } from '../../../constants/routeNames';
import { PinCodeScreen } from '..';
@ -53,8 +52,11 @@ class PinCodeContainer extends Component {
_setPinCode = pin => new Promise((resolve, reject) => {
const {
currentAccount: { password, name },
navigation,
dispatch,
accessToken,
setWrappedComponentState,
navigateTo,
navigation,
} = this.props;
const { isExistUser, pinCode } = this.state;
if (isExistUser) {
@ -63,13 +65,16 @@ class PinCodeContainer extends Component {
pinCode: pin,
password,
username: name,
accessToken: navigation.getParam('accessToken', ''),
accessToken,
};
verifyPinCode(pinData)
.then(() => {
.then((res) => {
// TODO: make global route
// navigation.navigate(ROUTES.DRAWER.MAIN);
setWrappedComponentState(res);
dispatch(closePinCodeModal());
if (navigateTo) {
navigation.navigate(navigateTo);
}
})
.catch((err) => {
alert(err);

View File

@ -7,16 +7,23 @@ const RootContainer = () => (WrappedComponent) => {
class RootComponent extends Component {
constructor(props) {
super(props);
this.state = {};
this.state = {
pinCodeStates: null,
wrappedComponentStates: null,
};
}
componentWillMount() {
console.log('============111111============', this.props);
}
_setPinCodeState = (data) => {
this.setState({ pinCodeStates: { ...data } });
};
_setWrappedComponentState = (data) => {
this.setState({ wrappedComponentStates: { ...data } });
};
render() {
const { isPinCodeReqiure } = this.props;
const { isPinCodeReqiure, navigation } = this.props;
const { pinCodeStates, wrappedComponentStates } = this.state;
return (
<Fragment>
<Modal
@ -25,9 +32,17 @@ const RootContainer = () => (WrappedComponent) => {
swipeToClose={false}
backButtonClose={false}
>
<PinCode />
<PinCode
{...pinCodeStates}
setWrappedComponentState={this._setWrappedComponentState}
navigation={navigation}
/>
</Modal>
<WrappedComponent {...this.props} />
<WrappedComponent
{...this.props}
{...wrappedComponentStates}
setPinCodeState={this._setPinCodeState}
/>
</Fragment>
);
}

View File

@ -7,7 +7,7 @@ import { steemConnectOptions } from './config';
// Actions
import { addPassiveAccount } from '../../redux/actions/accountAction';
import { login as loginAction } from '../../redux/actions/applicationActions';
import { login as loginAction, openPinCodeModal } from '../../redux/actions/applicationActions';
// Constants
import { default as ROUTES } from '../../constants/routeNames';
@ -22,7 +22,7 @@ class SteemConnect extends Component {
onNavigationStateChange(event) {
let accessToken;
const { navigation, dispatch } = this.props;
const { dispatch, setPinCodeState } = this.props;
const { isLoading } = this.state;
if (event.url.indexOf('?access_token=') > -1) {
@ -39,7 +39,8 @@ class SteemConnect extends Component {
if (result) {
dispatch(addPassiveAccount(result));
dispatch(loginAction());
navigation.navigate(ROUTES.SCREENS.PINCODE, { accessToken });
dispatch(openPinCodeModal());
setPinCodeState({ accessToken, navigateTo: ROUTES.DRAWER.MAIN });
} else {
// TODO: Error alert (Toast Message)
}