mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-11-24 08:55:14 +03:00
Changed async storage with real
This commit is contained in:
parent
d54e8aaee2
commit
205bf14ecf
@ -1,4 +0,0 @@
|
||||
export default {
|
||||
IS_EXIST_USER: 'IS_EXIST_USER',
|
||||
PUSH_TOKEN_SAVED: 'PUSH_TOKEN_SAVED',
|
||||
};
|
@ -2,7 +2,6 @@ import { Client, PrivateKey } from 'dsteem';
|
||||
import { AsyncStorage } from 'react-native';
|
||||
|
||||
import { getUnreadActivityCount } from '../esteem/esteem';
|
||||
import sc2 from './steemConnectAPI';
|
||||
|
||||
// Utils
|
||||
import { decryptKey } from '../../utils/crypto';
|
||||
|
@ -46,6 +46,7 @@ const applicationSchema = {
|
||||
name: APPLICATION_SCHEMA,
|
||||
properties: {
|
||||
isPushTokenSaved: { type: 'bool', default: false },
|
||||
isExistUser: { type: 'bool', default: false },
|
||||
},
|
||||
};
|
||||
|
||||
@ -404,3 +405,40 @@ export const setPushTokenSaved = pushTokenSaved => new Promise((resolve, reject)
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
|
||||
export const getExistUser = () => new Promise((resolve, reject) => {
|
||||
try {
|
||||
const application = realm.objects(APPLICATION_SCHEMA);
|
||||
if (!application[0]) {
|
||||
setExistUser(false);
|
||||
resolve(false);
|
||||
}
|
||||
if (application[0].isExistUser) {
|
||||
resolve((application[0].isExistUser));
|
||||
} else {
|
||||
resolve(false);
|
||||
}
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
|
||||
export const setExistUser = existUser => new Promise((resolve, reject) => {
|
||||
try {
|
||||
const application = realm.objects(APPLICATION_SCHEMA);
|
||||
realm.write(() => {
|
||||
if (Array.from(application).length > 0) {
|
||||
application[0].isExistUser = existUser;
|
||||
resolve(application[0]);
|
||||
} else {
|
||||
const applicationData = {
|
||||
existUser: false,
|
||||
};
|
||||
realm.create(APPLICATION_SCHEMA, { ...applicationData });
|
||||
resolve(applicationData);
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
|
@ -1,5 +1,5 @@
|
||||
import React, { Component } from 'react';
|
||||
import { AsyncStorage, Platform } from 'react-native';
|
||||
import { Platform } from 'react-native';
|
||||
import { connect } from 'react-redux';
|
||||
import { addLocaleData } from 'react-intl';
|
||||
import Config from 'react-native-config';
|
||||
@ -8,7 +8,6 @@ import AppCenter from 'appcenter';
|
||||
// Constants
|
||||
import en from 'react-intl/locale-data/en';
|
||||
import tr from 'react-intl/locale-data/tr';
|
||||
import INITIAL from '../../../constants/initial';
|
||||
|
||||
// Services
|
||||
import {
|
||||
@ -17,6 +16,7 @@ import {
|
||||
getSettings,
|
||||
getPushTokenSaved,
|
||||
setPushTokenSaved,
|
||||
getExistUser,
|
||||
} from '../../../realm/realm';
|
||||
import { getUser } from '../../../providers/steem/dsteem';
|
||||
import { setPushToken } from '../../../providers/esteem/esteem';
|
||||
@ -141,8 +141,8 @@ class ApplicationContainer extends Component {
|
||||
const { notificationSettings } = this.props;
|
||||
const token = await AppCenter.getInstallId();
|
||||
|
||||
AsyncStorage.getItem(INITIAL.IS_EXIST_USER, (err, result) => {
|
||||
if (JSON.parse(result)) {
|
||||
getExistUser().then((isExistUser) => {
|
||||
if (isExistUser) {
|
||||
getPushTokenSaved().then((isPushTokenSaved) => {
|
||||
if (!isPushTokenSaved) {
|
||||
const data = {
|
||||
|
@ -1,20 +1,15 @@
|
||||
import React, { Component } from 'react';
|
||||
import { AsyncStorage } from 'react-native';
|
||||
import { connect } from 'react-redux';
|
||||
import { injectIntl } from 'react-intl';
|
||||
|
||||
import { setUserDataWithPinCode, verifyPinCode } from '../../../providers/steem/auth';
|
||||
|
||||
// Actions
|
||||
// Actions & Services
|
||||
import { closePinCodeModal } from '../../../redux/actions/applicationActions';
|
||||
|
||||
// Constants
|
||||
import { default as INITIAL } from '../../../constants/initial';
|
||||
import { getExistUser, setExistUser } from '../../../realm/realm';
|
||||
|
||||
import { PinCodeScreen } from '..';
|
||||
|
||||
const DEFAULT_IMAGE = require('../../../assets/esteem.png');
|
||||
|
||||
class PinCodeContainer extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
@ -48,10 +43,10 @@ class PinCodeContainer extends Component {
|
||||
}
|
||||
|
||||
_getDataFromStorage = () => new Promise((resolve) => {
|
||||
AsyncStorage.getItem(INITIAL.IS_EXIST_USER, (err, result) => {
|
||||
getExistUser().then((isExistUser) => {
|
||||
this.setState(
|
||||
{
|
||||
isExistUser: JSON.parse(result),
|
||||
isExistUser,
|
||||
},
|
||||
resolve,
|
||||
);
|
||||
@ -106,7 +101,7 @@ class PinCodeContainer extends Component {
|
||||
accessToken,
|
||||
};
|
||||
setUserDataWithPinCode(pinData).then(() => {
|
||||
AsyncStorage.setItem(INITIAL.IS_EXIST_USER, JSON.stringify(true), () => {
|
||||
setExistUser(true).then(() => {
|
||||
dispatch(closePinCodeModal());
|
||||
if (navigateTo) {
|
||||
navigation.navigate(navigateTo);
|
||||
|
@ -1,10 +1,11 @@
|
||||
import React, { Component, Fragment } from 'react';
|
||||
import { AppState, AsyncStorage } from 'react-native';
|
||||
import { AppState } from 'react-native';
|
||||
import { connect } from 'react-redux';
|
||||
import Push from 'appcenter-push';
|
||||
|
||||
// Actions
|
||||
// Actions & Services
|
||||
import { openPinCodeModal } from '../../../redux/actions/applicationActions';
|
||||
import { getExistUser } from '../../../realm/realm';
|
||||
|
||||
// Components
|
||||
import { Modal } from '../../../components';
|
||||
@ -12,7 +13,6 @@ import { PinCode } from '../..';
|
||||
|
||||
// Constants
|
||||
import ROUTES from '../../../constants/routeNames';
|
||||
import INITIAL from '../../../constants/initial';
|
||||
|
||||
const RootContainer = () => (WrappedComponent) => {
|
||||
class RootComponent extends Component {
|
||||
@ -45,9 +45,9 @@ const RootContainer = () => (WrappedComponent) => {
|
||||
const { appState } = this.state;
|
||||
const { dispatch } = this.props;
|
||||
|
||||
AsyncStorage.getItem(INITIAL.IS_EXIST_USER, (err, result) => {
|
||||
getExistUser().then((isExistUser) => {
|
||||
if (
|
||||
JSON.parse(result)
|
||||
isExistUser
|
||||
&& appState.match(/inactive|background/)
|
||||
&& nextAppState === 'active'
|
||||
&& __DEV__ === false
|
||||
@ -55,7 +55,6 @@ const RootContainer = () => (WrappedComponent) => {
|
||||
dispatch(openPinCodeModal());
|
||||
}
|
||||
});
|
||||
|
||||
this.setState({ appState: nextAppState });
|
||||
};
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import React, { Component } from 'react';
|
||||
import { AsyncStorage, Platform } from 'react-native';
|
||||
import { Platform } from 'react-native';
|
||||
import { connect } from 'react-redux';
|
||||
import AppCenter from 'appcenter';
|
||||
|
||||
@ -10,6 +10,7 @@ import {
|
||||
setCurrency as setCurrency2DB,
|
||||
setServer,
|
||||
setNotificationIsOpen,
|
||||
getExistUser,
|
||||
} from '../../../realm/realm';
|
||||
|
||||
// Services and Actions
|
||||
@ -28,7 +29,6 @@ import { setPushToken } from '../../../providers/esteem/esteem';
|
||||
import { VALUE as CURRENCY_VALUE } from '../../../constants/options/currency';
|
||||
import { VALUE as LANGUAGE_VALUE } from '../../../constants/options/language';
|
||||
import API_VALUE from '../../../constants/options/api';
|
||||
import INITIAL from '../../../constants/initial';
|
||||
|
||||
// Utilities
|
||||
|
||||
@ -36,10 +36,10 @@ import INITIAL from '../../../constants/initial';
|
||||
import { SettingsScreen } from '..';
|
||||
|
||||
/*
|
||||
* Props Name Description Value
|
||||
*@props --> props name here description here Value Type Here
|
||||
*
|
||||
*/
|
||||
* Props Name Description Value
|
||||
*@props --> props name here description here Value Type Here
|
||||
*
|
||||
*/
|
||||
|
||||
class SettingsContainer extends Component {
|
||||
constructor(props) {
|
||||
@ -116,8 +116,9 @@ class SettingsContainer extends Component {
|
||||
const { notificationSettings, isLoggedIn, username } = this.props;
|
||||
if (isLoggedIn) {
|
||||
const token = await AppCenter.getInstallId();
|
||||
AsyncStorage.getItem(INITIAL.IS_EXIST_USER, (err, result) => {
|
||||
if (JSON.parse(result)) {
|
||||
|
||||
getExistUser().then((isExistUser) => {
|
||||
if (isExistUser) {
|
||||
const data = {
|
||||
username,
|
||||
token,
|
||||
|
Loading…
Reference in New Issue
Block a user