mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-11-22 23:28:56 +03:00
Saved pin code to redux
This commit is contained in:
parent
f31a0f2607
commit
659cf61444
@ -6,6 +6,7 @@ import {
|
||||
UPDATE_CURRENT_ACCOUNT,
|
||||
UPDATE_UNREAD_ACTIVITY_COUNT,
|
||||
REMOVE_OTHER_ACCOUNT,
|
||||
SET_PIN_CODE,
|
||||
} from '../constants/constants';
|
||||
|
||||
export const fetchAccountFromSteem = (username, password) => (dispatch) => {
|
||||
@ -43,3 +44,8 @@ export const removeOtherAccount = data => ({
|
||||
type: REMOVE_OTHER_ACCOUNT,
|
||||
payload: data,
|
||||
});
|
||||
|
||||
export const setPinCode = data => ({
|
||||
type: SET_PIN_CODE,
|
||||
payload: data,
|
||||
});
|
||||
|
@ -28,6 +28,7 @@ export const FETCHING_ACCOUNT = 'FETCHING_ACCOUNT';
|
||||
export const REMOVE_OTHER_ACCOUNT = 'REMOVE_OTHER_ACCOUNT';
|
||||
export const UPDATE_CURRENT_ACCOUNT = 'UPDATE_CURRENT_ACCOUNT';
|
||||
export const UPDATE_UNREAD_ACTIVITY_COUNT = 'UPDATE_UNREAD_ACTIVITY_COUNT';
|
||||
export const SET_PIN_CODE = 'SET_PIN_CODE';
|
||||
|
||||
// UI
|
||||
export const IS_COLLAPSE_POST_BUTTON = 'IS_COLLAPSE_POST_BUTTON';
|
||||
|
@ -4,9 +4,9 @@ import {
|
||||
ADD_OTHER_ACCOUNT,
|
||||
UPDATE_CURRENT_ACCOUNT,
|
||||
UPDATE_UNREAD_ACTIVITY_COUNT,
|
||||
LOGOUT,
|
||||
REMOVE_OTHER_ACCOUNT,
|
||||
LOGOUT_FAIL,
|
||||
SET_PIN_CODE,
|
||||
} from '../constants/constants';
|
||||
|
||||
const initialState = {
|
||||
@ -16,6 +16,7 @@ const initialState = {
|
||||
hasError: false,
|
||||
errorMessage: null,
|
||||
isLogingOut: false,
|
||||
pin: null,
|
||||
};
|
||||
|
||||
export default function (state = initialState, action) {
|
||||
@ -77,11 +78,12 @@ export default function (state = initialState, action) {
|
||||
...state,
|
||||
isLogingOut: true,
|
||||
};
|
||||
// case LOGOUT_SUCCESS:
|
||||
// return {
|
||||
// ...state,
|
||||
// initialState,
|
||||
// };
|
||||
|
||||
case SET_PIN_CODE:
|
||||
return {
|
||||
...state,
|
||||
pin: action.payload,
|
||||
};
|
||||
|
||||
default:
|
||||
return state;
|
||||
|
@ -112,16 +112,18 @@ class ApplicationContainer extends Component {
|
||||
|
||||
if (realmData) {
|
||||
await getUser(currentUsername)
|
||||
.then((accountData) => {
|
||||
.then(async (accountData) => {
|
||||
dispatch(login(true));
|
||||
|
||||
const isExistUser = await getExistUser();
|
||||
|
||||
const realmObject = realmData.filter(data => data.username === currentUsername);
|
||||
[accountData.local] = realmObject;
|
||||
|
||||
dispatch(updateCurrentAccount(accountData));
|
||||
// If in dev mode pin code does not show
|
||||
// eslint-disable-next-line
|
||||
if (__DEV__ === false) {
|
||||
if (__DEV__ === false && !isExistUser) {
|
||||
dispatch(openPinCodeModal());
|
||||
}
|
||||
this._connectNotificationServer(accountData.name);
|
||||
|
@ -2,6 +2,7 @@ import React, { Component } from 'react';
|
||||
import { Alert } from 'react-native';
|
||||
import { connect } from 'react-redux';
|
||||
import { injectIntl } from 'react-intl';
|
||||
import Config from 'react-native-config';
|
||||
|
||||
import {
|
||||
setUserDataWithPinCode,
|
||||
@ -12,7 +13,10 @@ import {
|
||||
// Actions & Services
|
||||
import { closePinCodeModal } from '../../../redux/actions/applicationActions';
|
||||
import { getExistUser, setExistUser, getUserDataWithUsername } from '../../../realm/realm';
|
||||
import { updateCurrentAccount } from '../../../redux/actions/accountAction';
|
||||
import { updateCurrentAccount, setPinCode as savePinCode } from '../../../redux/actions/accountAction';
|
||||
|
||||
// Utils
|
||||
import { encryptKey } from '../../../utils/crypto';
|
||||
|
||||
// Component
|
||||
import PinCodeScreen from '../screen/pinCodeScreen';
|
||||
@ -88,6 +92,7 @@ class PinCodeContainer extends Component {
|
||||
_currentAccount.local = response;
|
||||
|
||||
dispatch(updateCurrentAccount({ ..._currentAccount }));
|
||||
this._savePinCode(pin);
|
||||
|
||||
dispatch(closePinCodeModal());
|
||||
if (navigateTo) {
|
||||
@ -137,6 +142,7 @@ class PinCodeContainer extends Component {
|
||||
dispatch(updateCurrentAccount({ ..._currentAccount }));
|
||||
|
||||
setExistUser(true).then(() => {
|
||||
this._savePinCode(pin);
|
||||
dispatch(closePinCodeModal());
|
||||
if (navigateTo) {
|
||||
navigation.navigate(navigateTo);
|
||||
@ -166,6 +172,7 @@ class PinCodeContainer extends Component {
|
||||
verifyPinCode(pinData)
|
||||
.then((res) => {
|
||||
setWrappedComponentState(res);
|
||||
this._savePinCode(pin);
|
||||
dispatch(closePinCodeModal());
|
||||
|
||||
const realmData = getUserDataWithUsername(currentAccount.name);
|
||||
@ -184,6 +191,12 @@ class PinCodeContainer extends Component {
|
||||
});
|
||||
});
|
||||
|
||||
_savePinCode = (pin) => {
|
||||
const { dispatch } = this.props;
|
||||
const encryptedPin = encryptKey(pin, Config.PIN_KEY);
|
||||
dispatch(savePinCode(encryptedPin));
|
||||
}
|
||||
|
||||
_setPinCode = async (pin, isReset) => {
|
||||
const {
|
||||
intl,
|
||||
|
Loading…
Reference in New Issue
Block a user