mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-11-30 06:12:37 +03:00
Db fixed for multiple account feature
This commit is contained in:
parent
49906d813d
commit
2b05630ee7
@ -30,18 +30,13 @@ class SideMenuContainer extends Component {
|
|||||||
|
|
||||||
componentWillMount() {
|
componentWillMount() {
|
||||||
const accounts = [];
|
const accounts = [];
|
||||||
const { currentAccount } = this.props;
|
|
||||||
|
|
||||||
getUserData().then((userData) => {
|
getUserData().then((userData) => {
|
||||||
userData.forEach((element) => {
|
userData.forEach((element) => {
|
||||||
let image = DEFAULT_IMAGE;
|
accounts.push({
|
||||||
if (Object.keys(currentAccount).length !== 0) {
|
name: `@${element.username}`,
|
||||||
const jsonMetadata = JSON.parse(currentAccount.json_metadata);
|
image: element.avatar ? { uri: element.avatar } : DEFAULT_IMAGE,
|
||||||
if (Object.keys(jsonMetadata).length !== 0) {
|
});
|
||||||
image = jsonMetadata.profile.cover_image;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
accounts.push({ name: `@${element.username}`, image });
|
|
||||||
});
|
});
|
||||||
accounts.push({
|
accounts.push({
|
||||||
name: 'Add Account',
|
name: 'Add Account',
|
||||||
|
@ -42,7 +42,7 @@ const noAuthMenuItems = [
|
|||||||
{
|
{
|
||||||
name: 'Add Account',
|
name: 'Add Account',
|
||||||
route: ROUTES.SCREENS.LOGIN,
|
route: ROUTES.SCREENS.LOGIN,
|
||||||
icon: 'add-circle-outline',
|
icon: 'plus-square-o',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Settings',
|
name: 'Settings',
|
||||||
|
@ -21,6 +21,7 @@ export const Login = (username, password) => {
|
|||||||
posting: null,
|
posting: null,
|
||||||
};
|
};
|
||||||
let loginFlag = false;
|
let loginFlag = false;
|
||||||
|
let avatar = '';
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// Get user account data from STEEM Blockchain
|
// Get user account data from STEEM Blockchain
|
||||||
@ -53,9 +54,14 @@ export const Login = (username, password) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const jsonMetadata = JSON.parse(account.json_metadata);
|
||||||
|
if (Object.keys(jsonMetadata).length !== 0) {
|
||||||
|
avatar = jsonMetadata.profile.cover_image;
|
||||||
|
}
|
||||||
if (loginFlag) {
|
if (loginFlag) {
|
||||||
const userData = {
|
const userData = {
|
||||||
username,
|
username,
|
||||||
|
avatar,
|
||||||
authType: 'masterKey',
|
authType: 'masterKey',
|
||||||
masterKey: '',
|
masterKey: '',
|
||||||
postingKey: '',
|
postingKey: '',
|
||||||
@ -85,10 +91,18 @@ export const Login = (username, password) => {
|
|||||||
export const loginWithSC2 = async (accessToken) => {
|
export const loginWithSC2 = async (accessToken) => {
|
||||||
await steemConnect.setAccessToken(accessToken);
|
await steemConnect.setAccessToken(accessToken);
|
||||||
const account = await steemConnect.me();
|
const account = await steemConnect.me();
|
||||||
|
let avatar = '';
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
|
||||||
|
const jsonMetadata = JSON.parse(account.json_metadata);
|
||||||
|
if (Object.keys(jsonMetadata).length !== 0) {
|
||||||
|
avatar = jsonMetadata.profile.cover_image;
|
||||||
|
}
|
||||||
|
|
||||||
const userData = {
|
const userData = {
|
||||||
username: account.account.name,
|
username: account.account.name,
|
||||||
|
avatar,
|
||||||
authType: 'steemConnect',
|
authType: 'steemConnect',
|
||||||
masterKey: '',
|
masterKey: '',
|
||||||
postingKey: '',
|
postingKey: '',
|
||||||
@ -99,6 +113,7 @@ export const loginWithSC2 = async (accessToken) => {
|
|||||||
|
|
||||||
const authData = {
|
const authData = {
|
||||||
isLoggedIn: true,
|
isLoggedIn: true,
|
||||||
|
currentUsername: account.account.name,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (isLoggedInUser(account.account.name)) {
|
if (isLoggedInUser(account.account.name)) {
|
||||||
@ -154,6 +169,7 @@ export const setUserDataWithPinCode = data => new Promise((resolve, reject) => {
|
|||||||
.then(() => {
|
.then(() => {
|
||||||
const authData = {
|
const authData = {
|
||||||
isLoggedIn: true,
|
isLoggedIn: true,
|
||||||
|
currentUsername: userData.username,
|
||||||
};
|
};
|
||||||
|
|
||||||
setAuthStatus(authData)
|
setAuthStatus(authData)
|
||||||
@ -227,6 +243,7 @@ export const verifyPinCode = async (data) => {
|
|||||||
if (loginFlag) {
|
if (loginFlag) {
|
||||||
const authData = {
|
const authData = {
|
||||||
isLoggedIn: true,
|
isLoggedIn: true,
|
||||||
|
currentUsername: data.username,
|
||||||
};
|
};
|
||||||
const response = {
|
const response = {
|
||||||
accessToken: decryptKey(userData.accessToken, data.pinCode),
|
accessToken: decryptKey(userData.accessToken, data.pinCode),
|
||||||
|
@ -8,6 +8,7 @@ const userSchema = {
|
|||||||
name: USER_SCHEMA,
|
name: USER_SCHEMA,
|
||||||
properties: {
|
properties: {
|
||||||
username: { type: 'string' },
|
username: { type: 'string' },
|
||||||
|
avatar: { type: 'string' },
|
||||||
authType: { type: 'string' },
|
authType: { type: 'string' },
|
||||||
postingKey: { type: 'string' },
|
postingKey: { type: 'string' },
|
||||||
activeKey: { type: 'string' },
|
activeKey: { type: 'string' },
|
||||||
@ -22,6 +23,7 @@ const authSchema = {
|
|||||||
properties: {
|
properties: {
|
||||||
isLoggedIn: { type: 'bool', default: false },
|
isLoggedIn: { type: 'bool', default: false },
|
||||||
pinCode: { type: 'string' },
|
pinCode: { type: 'string' },
|
||||||
|
currentUsername: { type: 'string' },
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -104,7 +106,7 @@ export const getAuthStatus = () => new Promise((resolve, reject) => {
|
|||||||
try {
|
try {
|
||||||
const auth = realm.objects(AUTH_SCHEMA);
|
const auth = realm.objects(AUTH_SCHEMA);
|
||||||
if (auth['0']) {
|
if (auth['0']) {
|
||||||
resolve(auth['0'].isLoggedIn);
|
resolve(auth['0']);
|
||||||
} else {
|
} else {
|
||||||
resolve(false);
|
resolve(false);
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,7 @@ class AuthorScreen extends Component {
|
|||||||
let user;
|
let user;
|
||||||
|
|
||||||
await getAuthStatus().then((res) => {
|
await getAuthStatus().then((res) => {
|
||||||
isLoggedIn = res;
|
isLoggedIn = res.isLoggedIn;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (isLoggedIn) {
|
if (isLoggedIn) {
|
||||||
|
@ -52,7 +52,7 @@ export default class HomeScreen extends PureComponent {
|
|||||||
let isLoggedIn;
|
let isLoggedIn;
|
||||||
|
|
||||||
await getAuthStatus().then((res) => {
|
await getAuthStatus().then((res) => {
|
||||||
isLoggedIn = res;
|
isLoggedIn = res.isLoggedIn;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (isLoggedIn) {
|
if (isLoggedIn) {
|
||||||
|
@ -60,7 +60,7 @@ class PostContainer extends Component {
|
|||||||
let isLoggedIn;
|
let isLoggedIn;
|
||||||
|
|
||||||
await getAuthStatus().then((res) => {
|
await getAuthStatus().then((res) => {
|
||||||
isLoggedIn = res;
|
isLoggedIn = res.isLoggedIn;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (isLoggedIn) {
|
if (isLoggedIn) {
|
||||||
|
@ -75,7 +75,7 @@ class ProfilePage extends React.Component {
|
|||||||
let about;
|
let about;
|
||||||
|
|
||||||
await getAuthStatus().then((res) => {
|
await getAuthStatus().then((res) => {
|
||||||
isLoggedIn = res;
|
isLoggedIn = res.isLoggedIn;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (isLoggedIn) {
|
if (isLoggedIn) {
|
||||||
|
@ -147,7 +147,7 @@ class ProfileContainer extends Component {
|
|||||||
let username;
|
let username;
|
||||||
|
|
||||||
await getAuthStatus().then((res) => {
|
await getAuthStatus().then((res) => {
|
||||||
isLoggedIn = res;
|
isLoggedIn = res.isLoggedIn;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (selectedUser) {
|
if (selectedUser) {
|
||||||
|
@ -6,7 +6,11 @@ import { getAccount } from '../../../providers/steem/dsteem';
|
|||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
import { addOtherAccount, updateCurrentAccount } from '../../../redux/actions/accountAction';
|
import { addOtherAccount, updateCurrentAccount } from '../../../redux/actions/accountAction';
|
||||||
import { activeApplication, login, openPinCodeModal } from '../../../redux/actions/applicationActions';
|
import {
|
||||||
|
activeApplication,
|
||||||
|
login,
|
||||||
|
openPinCodeModal,
|
||||||
|
} from '../../../redux/actions/applicationActions';
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
import { default as ROUTES } from '../../../constants/routeNames';
|
import { default as ROUTES } from '../../../constants/routeNames';
|
||||||
@ -22,13 +26,15 @@ class SplashContainer extends Component {
|
|||||||
const { navigation, dispatch } = this.props;
|
const { navigation, dispatch } = this.props;
|
||||||
|
|
||||||
getAuthStatus().then((res) => {
|
getAuthStatus().then((res) => {
|
||||||
if (res) {
|
if (res.isLoggedIn) {
|
||||||
getUserData().then((response) => {
|
getUserData().then((response) => {
|
||||||
if (response.length > 0) {
|
if (response.length > 0) {
|
||||||
response.forEach((accountData) => {
|
response.forEach((accountData) => {
|
||||||
dispatch(addOtherAccount({ username: accountData.username }));
|
dispatch(
|
||||||
|
addOtherAccount({ username: accountData.username, avatar: accountData.avatar }),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
getAccount(response[response.length - 1].username).then((accountData) => {
|
getAccount(res.currentUsername).then((accountData) => {
|
||||||
dispatch(updateCurrentAccount(...accountData));
|
dispatch(updateCurrentAccount(...accountData));
|
||||||
dispatch(activeApplication());
|
dispatch(activeApplication());
|
||||||
dispatch(login());
|
dispatch(login());
|
||||||
|
@ -42,7 +42,7 @@ class WalletPage extends Component {
|
|||||||
let globalProperties;
|
let globalProperties;
|
||||||
|
|
||||||
await getAuthStatus().then((res) => {
|
await getAuthStatus().then((res) => {
|
||||||
isLoggedIn = res;
|
isLoggedIn = res.isLoggedIn;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (isLoggedIn) {
|
if (isLoggedIn) {
|
||||||
|
@ -2,7 +2,7 @@ import { getUserData, getAuthStatus } from '../realm/realm';
|
|||||||
|
|
||||||
export const getUserIsLoggedIn = () => {
|
export const getUserIsLoggedIn = () => {
|
||||||
getAuthStatus()
|
getAuthStatus()
|
||||||
.then(res => res)
|
.then(res => res.isLoggedIn)
|
||||||
.catch(() => null);
|
.catch(() => null);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user