mirror of
https://github.com/ecency/ecency-mobile.git
synced 2025-01-05 21:06:21 +03:00
Connected Realm and Redux to pin code screen
This commit is contained in:
parent
596510bfe7
commit
0e3674fadf
@ -62,7 +62,7 @@ export const Login = (username, password) => {
|
|||||||
// Save user data to Realm DB
|
// Save user data to Realm DB
|
||||||
setUserData(userData)
|
setUserData(userData)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
resolve(loginFlag);
|
resolve({ ...account, password });
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
reject(err);
|
reject(err);
|
||||||
@ -98,6 +98,7 @@ export const setUserDataWithPinCode = (pinCode, password) =>
|
|||||||
memoKey: encryptKey(privateKeys.memo.toString(), pinCode),
|
memoKey: encryptKey(privateKeys.memo.toString(), pinCode),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//TODO update user data
|
||||||
setUserData(updatedUserData)
|
setUserData(updatedUserData)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
resolve();
|
resolve();
|
||||||
@ -113,8 +114,12 @@ export const verifyPinCode = (pinCode, password) =>
|
|||||||
new Promise((resolve, reject) => {
|
new Promise((resolve, reject) => {
|
||||||
getUserData().then(result => {
|
getUserData().then(result => {
|
||||||
const userData = Array.from(result)[0];
|
const userData = Array.from(result)[0];
|
||||||
const masterKey = decryptKey(userData.masterKey, pinCode);
|
|
||||||
|
|
||||||
|
console.log("====userData====", Array.from(result));
|
||||||
|
console.log("====userData.masterKey====", userData.masterKey);
|
||||||
|
console.log("====pinCode====", pinCode, password);
|
||||||
|
const masterKey = decryptKey(userData.masterKey, pinCode);
|
||||||
|
console.log("====masterKey====", masterKey);
|
||||||
if (masterKey === password) {
|
if (masterKey === password) {
|
||||||
resolve();
|
resolve();
|
||||||
} else {
|
} else {
|
||||||
|
@ -8,7 +8,10 @@ import {
|
|||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
isFetching: null,
|
isFetching: null,
|
||||||
data: [],
|
data: {
|
||||||
|
accounts: [],
|
||||||
|
currentAccountId: null,
|
||||||
|
},
|
||||||
hasError: false,
|
hasError: false,
|
||||||
errorMessage: null,
|
errorMessage: null,
|
||||||
};
|
};
|
||||||
@ -33,7 +36,10 @@ export default function(state = initialState, action) {
|
|||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
isFetching: false,
|
isFetching: false,
|
||||||
data: [...state.data, action.payload],
|
data: {
|
||||||
|
accounts: [...state.data.accounts, action.payload],
|
||||||
|
currentAccountId: action.payload.id,
|
||||||
|
},
|
||||||
hasError: false,
|
hasError: false,
|
||||||
errorMessage: null,
|
errorMessage: null,
|
||||||
};
|
};
|
||||||
|
@ -3,5 +3,5 @@ import userReducer from "./userReducer";
|
|||||||
import accountReducer from "./accountReducer";
|
import accountReducer from "./accountReducer";
|
||||||
|
|
||||||
export default combineReducers({
|
export default combineReducers({
|
||||||
accounts: accountReducer,
|
account: accountReducer,
|
||||||
});
|
});
|
||||||
|
@ -26,7 +26,7 @@ import { connect } from "react-redux";
|
|||||||
|
|
||||||
import { Login } from "../../providers/steem/auth";
|
import { Login } from "../../providers/steem/auth";
|
||||||
|
|
||||||
import { fetchAccountFromSteem } from "../../redux/actions/accountAction";
|
import { addNewAccount } from "../../redux/actions/accountAction";
|
||||||
|
|
||||||
import { default as INITIAL } from "../../constants/initial";
|
import { default as INITIAL } from "../../constants/initial";
|
||||||
|
|
||||||
@ -52,41 +52,18 @@ class LoginPage extends Component {
|
|||||||
|
|
||||||
Login(username, password)
|
Login(username, password)
|
||||||
.then(result => {
|
.then(result => {
|
||||||
if (result === true) {
|
if (result) {
|
||||||
AsyncStorage.setItem(
|
this.props.dispatch(addNewAccount(result));
|
||||||
INITIAL.IS_EXIST_USER,
|
Navigation.setStackRoot(componentId, {
|
||||||
JSON.stringify(false)
|
component: {
|
||||||
);
|
name: "navigation.eSteem.PinCode",
|
||||||
|
options: {
|
||||||
this.props.dispatch(
|
topBar: {
|
||||||
fetchAccountFromSteem(username, password)
|
visible: false,
|
||||||
);
|
},
|
||||||
AsyncStorage.getItem(
|
},
|
||||||
INITIAL.IS_EXIST_USER,
|
},
|
||||||
(err, value) => {
|
});
|
||||||
if (value === "true") {
|
|
||||||
Navigation.setStackRoot(componentId, {
|
|
||||||
component: {
|
|
||||||
name: "navigation.eSteem.Splash",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
Navigation.setStackRoot(componentId, {
|
|
||||||
component: {
|
|
||||||
name: "navigation.eSteem.PinCode",
|
|
||||||
passProps: {
|
|
||||||
test: "test",
|
|
||||||
},
|
|
||||||
options: {
|
|
||||||
topBar: {
|
|
||||||
visible: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { AsyncStorage } from "react-native";
|
import { AsyncStorage } from "react-native";
|
||||||
|
import { connect } from "react-redux";
|
||||||
|
import { Navigation } from "react-native-navigation";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
setUserDataWithPinCode,
|
setUserDataWithPinCode,
|
||||||
@ -24,6 +26,7 @@ class PinCodeContainer extends React.Component {
|
|||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this._getDataFromStorage().then(() => {
|
this._getDataFromStorage().then(() => {
|
||||||
const { isExistUser } = this.state;
|
const { isExistUser } = this.state;
|
||||||
|
console.log("============isExistUser===========", isExistUser);
|
||||||
if (isExistUser) {
|
if (isExistUser) {
|
||||||
this.setState({
|
this.setState({
|
||||||
informationText: "verify screen",
|
informationText: "verify screen",
|
||||||
@ -34,11 +37,17 @@ class PinCodeContainer extends React.Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
"==============password==========",
|
||||||
|
this.props.currentAccount.password
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
_getDataFromStorage = () =>
|
_getDataFromStorage = () =>
|
||||||
new Promise(resolve => {
|
new Promise(resolve => {
|
||||||
AsyncStorage.getItem(INITIAL.IS_EXIST_USER, (err, result) => {
|
AsyncStorage.getItem(INITIAL.IS_EXIST_USER, (err, result) => {
|
||||||
|
console.log("============IS_EXIST_USER===========", result);
|
||||||
this.setState(
|
this.setState(
|
||||||
{
|
{
|
||||||
isExistUser: JSON.parse(result),
|
isExistUser: JSON.parse(result),
|
||||||
@ -49,12 +58,25 @@ class PinCodeContainer extends React.Component {
|
|||||||
});
|
});
|
||||||
|
|
||||||
_setPinCode = pin => {
|
_setPinCode = pin => {
|
||||||
|
const {
|
||||||
|
currentAccount: { password },
|
||||||
|
componentId,
|
||||||
|
} = this.props;
|
||||||
const { isExistUser, pinCode } = this.state;
|
const { isExistUser, pinCode } = this.state;
|
||||||
|
console.log(password);
|
||||||
if (isExistUser) {
|
if (isExistUser) {
|
||||||
// If the user is exist, we are just checking to pin and navigating to home screen
|
// If the user is exist, we are just checking to pin and navigating to home screen
|
||||||
verifyPinCode(pinCode, "").then(() => {});
|
verifyPinCode(pin, password)
|
||||||
// TODO navigate to home
|
.then(() => {
|
||||||
|
Navigation.setStackRoot(componentId, {
|
||||||
|
component: {
|
||||||
|
name: "navigation.eSteem.Home",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
alert(err);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
// If the user is logging in for the first time, the user should set to pin
|
// If the user is logging in for the first time, the user should set to pin
|
||||||
if (!pinCode) {
|
if (!pinCode) {
|
||||||
@ -64,8 +86,19 @@ class PinCodeContainer extends React.Component {
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
if (pinCode === pin) {
|
if (pinCode === pin) {
|
||||||
setUserDataWithPinCode(pinCode, "").then(() => {});
|
setUserDataWithPinCode(pinCode, password).then(() => {
|
||||||
// TODO navigate to home
|
AsyncStorage.setItem(
|
||||||
|
INITIAL.IS_EXIST_USER,
|
||||||
|
JSON.stringify(true),
|
||||||
|
() => {
|
||||||
|
Navigation.setStackRoot(componentId, {
|
||||||
|
component: {
|
||||||
|
name: "navigation.eSteem.Home",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
this.setState({
|
this.setState({
|
||||||
informationText: "wrongggg!!!",
|
informationText: "wrongggg!!!",
|
||||||
@ -92,4 +125,10 @@ class PinCodeContainer extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default PinCodeContainer;
|
const mapStateToProps = state => ({
|
||||||
|
currentAccount: state.account.data.accounts.find(
|
||||||
|
item => item.id === state.account.data.currentAccountId
|
||||||
|
),
|
||||||
|
});
|
||||||
|
|
||||||
|
export default connect(mapStateToProps)(PinCodeContainer);
|
||||||
|
Loading…
Reference in New Issue
Block a user