mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-22 12:51:42 +03:00
Added default pin code feature
This commit is contained in:
parent
d5d08008a0
commit
50a179d4d3
@ -156,6 +156,7 @@ export const setUserDataWithPinCode = async data => {
|
||||
|
||||
export const updatePinCode = async data => {
|
||||
try {
|
||||
let currentUser = null;
|
||||
await setPinCode(data.pinCode);
|
||||
const users = await getUserData();
|
||||
if (users && users.length > 0) {
|
||||
@ -167,8 +168,11 @@ export const updatePinCode = async data => {
|
||||
}
|
||||
const updatedUserData = getUpdatedUserData(userData, data);
|
||||
await updateUserData(updatedUserData);
|
||||
if (userData.username === data.username) {
|
||||
currentUser = updatedUserData;
|
||||
}
|
||||
});
|
||||
return true;
|
||||
return currentUser;
|
||||
}
|
||||
return false;
|
||||
} catch (error) {
|
||||
|
@ -71,8 +71,11 @@ import {
|
||||
setNsfw,
|
||||
isDefaultFooter,
|
||||
isPinCodeOpen,
|
||||
setPinCode as savePinCode,
|
||||
} from '../../../redux/actions/applicationActions';
|
||||
|
||||
import { encryptKey } from '../../../utils/crypto';
|
||||
|
||||
import darkTheme from '../../../themes/darkTheme';
|
||||
import lightTheme from '../../../themes/lightTheme';
|
||||
|
||||
@ -258,11 +261,13 @@ class ApplicationContainer extends Component {
|
||||
};
|
||||
|
||||
_startPinCodeTimer = () => {
|
||||
const { dispatch } = this.props;
|
||||
const { dispatch, isPinCodeOpen: _isPinCodeOpen } = this.props;
|
||||
|
||||
this._pinCodeTimer = setTimeout(() => {
|
||||
dispatch(openPinCodeModal());
|
||||
}, 1 * 60 * 1000);
|
||||
if (_isPinCodeOpen) {
|
||||
this._pinCodeTimer = setTimeout(() => {
|
||||
dispatch(openPinCodeModal());
|
||||
}, 1 * 60 * 1000);
|
||||
}
|
||||
};
|
||||
|
||||
_fetchApp = async () => {
|
||||
@ -357,7 +362,7 @@ class ApplicationContainer extends Component {
|
||||
};
|
||||
|
||||
_getUserDataFromRealm = async () => {
|
||||
const { dispatch, pinCode } = this.props;
|
||||
const { dispatch, pinCode, isPinCodeOpen: _isPinCodeOpen } = this.props;
|
||||
let realmData = [];
|
||||
let currentUsername;
|
||||
|
||||
@ -416,8 +421,11 @@ class ApplicationContainer extends Component {
|
||||
}),
|
||||
);
|
||||
// If in dev mode pin code does not show
|
||||
if (!isExistUser || !pinCode) {
|
||||
if ((!isExistUser || !pinCode) && _isPinCodeOpen) {
|
||||
dispatch(openPinCodeModal());
|
||||
} else if (!_isPinCodeOpen) {
|
||||
const encryptedPin = encryptKey(Config.DEFAULT_PIN, Config.PIN_KEY);
|
||||
dispatch(savePinCode(encryptedPin));
|
||||
}
|
||||
|
||||
dispatch(activeApplication());
|
||||
|
@ -86,7 +86,7 @@ class PinCodeContainer extends Component {
|
||||
const {
|
||||
currentAccount,
|
||||
dispatch,
|
||||
pinCodeParams: { navigateTo, navigateParams, accessToken },
|
||||
pinCodeParams: { navigateTo, navigateParams, accessToken, callback },
|
||||
intl,
|
||||
} = this.props;
|
||||
const { isOldPinVerified, oldPinCode } = this.state;
|
||||
@ -107,6 +107,7 @@ class PinCodeContainer extends Component {
|
||||
dispatch(updateCurrentAccount({ ..._currentAccount }));
|
||||
this._savePinCode(pin);
|
||||
|
||||
if (callback) callback(pin, oldPinCode);
|
||||
dispatch(closePinCodeModal());
|
||||
if (navigateTo) {
|
||||
const navigateAction = NavigationActions.navigate({
|
||||
@ -150,8 +151,9 @@ class PinCodeContainer extends Component {
|
||||
const {
|
||||
currentAccount,
|
||||
dispatch,
|
||||
pinCodeParams: { navigateTo, navigateParams, accessToken },
|
||||
pinCodeParams: { navigateTo, navigateParams, accessToken, callback },
|
||||
} = this.props;
|
||||
const { oldPinCode } = this.state;
|
||||
|
||||
const pinData = {
|
||||
pinCode: pin,
|
||||
@ -168,6 +170,7 @@ class PinCodeContainer extends Component {
|
||||
|
||||
setExistUser(true).then(() => {
|
||||
this._savePinCode(pin);
|
||||
if (callback) callback(pin, oldPinCode);
|
||||
dispatch(closePinCodeModal());
|
||||
if (navigateTo) {
|
||||
const navigateAction = NavigationActions.navigate({
|
||||
@ -188,9 +191,10 @@ class PinCodeContainer extends Component {
|
||||
const {
|
||||
currentAccount,
|
||||
dispatch,
|
||||
pinCodeParams: { navigateTo, navigateParams, accessToken },
|
||||
pinCodeParams: { navigateTo, navigateParams, accessToken, callback },
|
||||
intl,
|
||||
} = this.props;
|
||||
const { oldPinCode } = this.state;
|
||||
|
||||
// If the user is exist, we are just checking to pin and navigating to home screen
|
||||
const pinData = {
|
||||
@ -208,6 +212,7 @@ class PinCodeContainer extends Component {
|
||||
[_currentAccount.local] = realmData;
|
||||
dispatch(updateCurrentAccount({ ..._currentAccount }));
|
||||
dispatch(closePinCodeModal());
|
||||
if (callback) callback(pin, oldPinCode);
|
||||
if (navigateTo) {
|
||||
const navigateAction = NavigationActions.navigate({
|
||||
routeName: navigateTo,
|
||||
|
@ -5,6 +5,7 @@ import AppCenter from 'appcenter';
|
||||
import Push from 'appcenter-push';
|
||||
import { Client } from 'dsteem';
|
||||
import VersionNumber from 'react-native-version-number';
|
||||
import Config from 'react-native-config';
|
||||
|
||||
// Realm
|
||||
import {
|
||||
@ -29,10 +30,13 @@ import {
|
||||
openPinCodeModal,
|
||||
setNsfw,
|
||||
isPinCodeOpen,
|
||||
setPinCode as savePinCode,
|
||||
} from '../../../redux/actions/applicationActions';
|
||||
import { toastNotification } from '../../../redux/actions/uiAction';
|
||||
import { setPushToken, getNodes } from '../../../providers/esteem/esteem';
|
||||
import { checkClient } from '../../../providers/steem/dsteem';
|
||||
import { updatePinCode } from '../../../providers/steem/auth';
|
||||
import { updateCurrentAccount } from '../../../redux/actions/accountAction';
|
||||
// Middleware
|
||||
|
||||
// Constants
|
||||
@ -41,6 +45,7 @@ import { VALUE as LANGUAGE_VALUE } from '../../../constants/options/language';
|
||||
|
||||
// Utilities
|
||||
import { sendEmail } from '../../../utils/sendEmail';
|
||||
import { encryptKey } from '../../../utils/crypto';
|
||||
|
||||
// Component
|
||||
import SettingsScreen from '../screen/settingsScreen';
|
||||
@ -169,8 +174,11 @@ class SettingsContainer extends Component {
|
||||
break;
|
||||
|
||||
case 'pincode':
|
||||
setPinCodeOpen(action);
|
||||
dispatch(isPinCodeOpen(action));
|
||||
dispatch(
|
||||
openPinCodeModal({
|
||||
callback: (pinCode, oldPincode) => this._setDefaultPinCode(action, oldPincode),
|
||||
}),
|
||||
);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -292,6 +300,30 @@ class SettingsContainer extends Component {
|
||||
}
|
||||
};
|
||||
|
||||
_setDefaultPinCode = (action, oldPinCode) => {
|
||||
const { dispatch, username, currentAccount } = this.props;
|
||||
|
||||
if (!action) {
|
||||
const pinData = {
|
||||
pinCode: Config.DEFAULT_PIN,
|
||||
username,
|
||||
oldPinCode,
|
||||
};
|
||||
updatePinCode(pinData).then(response => {
|
||||
const _currentAccount = currentAccount;
|
||||
_currentAccount.local = response;
|
||||
|
||||
dispatch(updateCurrentAccount({ ..._currentAccount }));
|
||||
|
||||
const encryptedPin = encryptKey(Config.DEFAULT_PIN, Config.PIN_KEY);
|
||||
dispatch(savePinCode(encryptedPin));
|
||||
|
||||
setPinCodeOpen(action);
|
||||
dispatch(isPinCodeOpen(action));
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
render() {
|
||||
const { serverList, isNotificationMenuOpen } = this.state;
|
||||
|
||||
@ -325,6 +357,7 @@ const mapStateToProps = state => ({
|
||||
selectedCurrency: state.application.currency,
|
||||
selectedLanguage: state.application.language,
|
||||
username: state.account.currentAccount && state.account.currentAccount.name,
|
||||
currentAccount: state.account.currentAccount,
|
||||
});
|
||||
|
||||
export default connect(mapStateToProps)(SettingsContainer);
|
||||
|
Loading…
Reference in New Issue
Block a user