preference updates. send firebase token.

This commit is contained in:
Akinwale Ariwodola 2019-10-15 10:24:03 +01:00
parent dcbb7f62d6
commit 194e29356f
17 changed files with 117 additions and 100 deletions

8
package-lock.json generated
View file

@ -5640,8 +5640,8 @@
}
},
"lbry-redux": {
"version": "github:lbryio/lbry-redux#dff1ecb195a03c5443526329116058b94d7391f7",
"from": "github:lbryio/lbry-redux#dff1ecb195a03c5443526329116058b94d7391f7",
"version": "github:lbryio/lbry-redux#91848445aa9e1efb76488947a32a7fc52543d52d",
"from": "github:lbryio/lbry-redux#91848445aa9e1efb76488947a32a7fc52543d52d",
"requires": {
"proxy-polyfill": "0.1.6",
"reselect": "^3.0.0",
@ -5649,8 +5649,8 @@
}
},
"lbryinc": {
"version": "github:lbryio/lbryinc#02d8571cd7fafd00d1a60f133d884eb8c5f1a306",
"from": "github:lbryio/lbryinc#02d8571cd7fafd00d1a60f133d884eb8c5f1a306",
"version": "github:lbryio/lbryinc#367d987e1f8344761e9fe9602499c583208d3b6b",
"from": "github:lbryio/lbryinc#367d987e1f8344761e9fe9602499c583208d3b6b",
"requires": {
"reselect": "^3.0.0"
}

View file

@ -13,7 +13,7 @@
"@expo/vector-icons": "^8.1.0",
"gfycat-style-urls": "^1.0.3",
"lbry-redux": "lbryio/lbry-redux#91848445aa9e1efb76488947a32a7fc52543d52d",
"lbryinc": "lbryio/lbryinc#02d8571cd7fafd00d1a60f133d884eb8c5f1a306",
"lbryinc": "lbryio/lbryinc#367d987e1f8344761e9fe9602499c583208d3b6b",
"lodash": ">=4.17.11",
"merge": ">=1.2.1",
"moment": "^2.22.1",

View file

@ -303,7 +303,7 @@ class AppWithNavigationState extends React.Component {
// call /sync/get with interval
setInterval(() => {
this.setState({ syncHashChanged: false }); // reset local state
NativeModules.UtilityModule.getSecureValue(Constants.KEY_FIRST_RUN_PASSWORD).then(walletPassword => {
NativeModules.UtilityModule.getSecureValue(Constants.KEY_WALLET_PASSWORD).then(walletPassword => {
dispatch(doGetSync(walletPassword));
});
}, SYNC_GET_INTERVAL);
@ -321,9 +321,15 @@ class AppWithNavigationState extends React.Component {
getUserSettings = () => {
const { dispatch } = this.props;
doPreferenceGet('shared', null, null, preference => {
dispatch(doPopulateSharedUserState(preference));
});
doPreferenceGet(
'shared',
preference => {
dispatch(doPopulateSharedUserState(preference));
},
error => {
/* failed */
}
);
};
componentWillUnmount() {

View file

@ -155,7 +155,7 @@ export default class ChannelSelector extends React.PureComponent {
}
// sync wallet
NativeModules.UtilityModule.getSecureValue(Constants.KEY_FIRST_RUN_PASSWORD).then(password => getSync(password));
NativeModules.UtilityModule.getSecureValue(Constants.KEY_WALLET_PASSWORD).then(password => getSync(password));
};
const failure = () => {

View file

@ -34,7 +34,7 @@ class FloatingWalletBalance extends React.PureComponent<Props> {
<Icon name="coins" size={12} style={floatingButtonStyle.balanceIcon} />
{isNaN(balance) && <ActivityIndicator size="small" color={Colors.White} />}
{(!isNaN(balance) || balance === 0) && (
<Text style={floatingButtonStyle.text}>{formatCredits(parseFloat(balance), 0, true)}</Text>
<Text style={floatingButtonStyle.text}>{formatCredits(parseFloat(balance), 1, true)}</Text>
)}
</TouchableOpacity>
</View>

View file

@ -32,7 +32,7 @@ const Constants = {
ABOUT_TAB: 'about',
KEY_FIRST_RUN_EMAIL: 'firstRunEmail',
KEY_FIRST_RUN_PASSWORD: 'firstRunPassword',
KEY_WALLET_PASSWORD: 'firstRunPassword',
KEY_FIRST_USER_AUTH: 'firstUserAuth',
KEY_SHOULD_VERIFY_EMAIL: 'shouldVerifyEmail',
KEY_EMAIL_VERIFY_PENDING: 'emailVerifyPending',

View file

@ -4,6 +4,7 @@ import { Provider, connect } from 'react-redux';
import { AppRegistry, Text, View, NativeModules } from 'react-native';
import {
Lbry,
buildSharedStateMiddleware,
claimsReducer,
contentReducer,
fileReducer,
@ -13,20 +14,24 @@ import {
searchReducer,
tagsReducer,
walletReducer,
sharedStateSubscriber,
ACTIONS as LBRY_REDUX_ACTIONS,
} from 'lbry-redux';
import {
Lbryio,
authReducer,
blacklistReducer,
costInfoReducer,
doGetSync,
filteredReducer,
homepageReducer,
rewardsReducer,
selectUserVerifiedEmail,
subscriptionsReducer,
syncReducer,
userReducer,
LBRYINC_ACTIONS,
} from 'lbryinc';
import { makeSelectClientSetting } from 'redux/selectors/settings';
import { createStore, applyMiddleware, compose } from 'redux';
import AppWithNavigationState, {
AppNavigator,
@ -34,6 +39,7 @@ import AppWithNavigationState, {
reactNavigationMiddleware,
} from 'component/AppNavigator';
import { REHYDRATE, PURGE, persistCombineReducers, persistStore } from 'redux-persist';
import Constants from 'constants'; // eslint-disable-line node/no-deprecated-api
import getStoredStateMigrateV4 from 'redux-persist/lib/integration/getStoredStateMigrateV4';
import FilesystemStorage from 'redux-persist-filesystem-storage';
import createCompressor from 'redux-persist-transform-compress';
@ -43,7 +49,6 @@ import formReducer from 'redux/reducers/form';
import drawerReducer from 'redux/reducers/drawer';
import settingsReducer from 'redux/reducers/settings';
import thunk from 'redux-thunk';
import isEqual from 'utils/deep-equal';
const globalExceptionHandler = (error, isFatal) => {
if (error && NativeModules.Firebase) {
@ -128,8 +133,43 @@ const reducers = persistCombineReducers(persistOptions, {
wallet: walletReducer,
});
/**
* source: the reducer name
* property: the property in the reducer-specific state
* transform: optional method to modify the value to be stored
*/
const sharedStateActions = [
LBRYINC_ACTIONS.CHANNEL_SUBSCRIBE,
LBRYINC_ACTIONS.CHANNEL_UNSUBSCRIBE,
LBRY_REDUX_ACTIONS.TOGGLE_TAG_FOLLOW,
LBRY_REDUX_ACTIONS.TOGGLE_BLOCK_CHANNEL,
];
const sharedStateFilters = {
tags: { source: 'tags', property: 'followedTags' },
subscriptions: {
source: 'subscriptions',
property: 'subscriptions',
transform: function(value) {
return value.map(({ uri }) => uri);
},
},
};
const sharedStateCallback = ({ dispatch, getState }) => {
const state = getState();
const syncEnabled = makeSelectClientSetting(Constants.SETTING_DEVICE_WALLET_SYNCED)(state);
const emailVerified = selectUserVerifiedEmail(state);
if (syncEnabled && emailVerified) {
NativeModules.UtilityModule.getSecureValue(Constants.KEY_WALLET_PASSWORD).then(password =>
dispatch(doGetSync(password))
);
}
};
const sharedStateMiddleware = buildSharedStateMiddleware(sharedStateActions, sharedStateFilters, sharedStateCallback);
const bulkThunk = createBulkThunkMiddleware();
const middleware = [thunk, bulkThunk, reactNavigationMiddleware];
const middleware = [sharedStateMiddleware, thunk, bulkThunk, reactNavigationMiddleware];
// eslint-disable-next-line no-underscore-dangle
const composeEnhancers = compose;
@ -148,31 +188,6 @@ const persistor = persistStore(store, persistOptions, err => {
});
window.persistor = persistor;
/**
* source: the reducer name
* property: the property in the reducer-specific state
* transform: optional method to modify the value to be stored
*/
const sharedStateFilters = {
tags: { source: 'tags', property: 'followedTags' },
subscriptions: {
source: 'subscriptions',
property: 'subscriptions',
transform: function(value) {
return value.map(({ uri }) => uri);
},
},
};
store.subscribe(() => {
try {
const state = store.getState();
sharedStateSubscriber(state, sharedStateFilters, '0.1');
} catch (e) {
// handle gracefully?
}
});
// TODO: Find i18n module that is compatible with react-native
global.__ = str => str;

View file

@ -449,7 +449,7 @@ export default class ChannelCreator extends React.PureComponent {
this.showChannelList();
// sync wallet
NativeModules.UtilityModule.getSecureValue(Constants.KEY_FIRST_RUN_PASSWORD).then(password => getSync(password));
NativeModules.UtilityModule.getSecureValue(Constants.KEY_WALLET_PASSWORD).then(password => getSync(password));
};
const failure = () => {

View file

@ -4,7 +4,6 @@ import {
doAuthenticate,
doCheckSync,
doGetSync,
doSetDefaultAccount,
doSyncApply,
doUserEmailNew,
doUserResendVerificationEmail,
@ -41,12 +40,11 @@ const select = state => ({
const perform = dispatch => ({
addUserEmail: email => dispatch(doUserEmailNew(email)),
authenticate: (appVersion, os) => dispatch(doAuthenticate(appVersion, os)),
authenticate: (appVersion, os, firebaseToken) => dispatch(doAuthenticate(appVersion, os, firebaseToken)),
setClientSetting: (key, value) => dispatch(doSetClientSetting(key, value)),
syncApply: (hash, data, password) => dispatch(doSyncApply(hash, data, password)),
getSync: password => dispatch(doGetSync(password)),
checkSync: () => dispatch(doCheckSync()),
setDefaultAccount: (success, failure) => dispatch(doSetDefaultAccount(success, failure)),
notify: data => dispatch(doToast(data)),
resendVerificationEmail: email => dispatch(doUserResendVerificationEmail(email)),
});

View file

@ -3,7 +3,7 @@ import { Lbry } from 'lbry-redux';
import { ActivityIndicator, NativeModules, Platform, Text, View } from 'react-native';
import AsyncStorage from '@react-native-community/async-storage';
import Colors from 'styles/colors';
import Constants from 'constants';
import Constants from 'constants'; // eslint-disable-line node/no-deprecated-api
import firstRunStyle from 'styles/firstRun';
class WelcomePage extends React.PureComponent {
@ -25,7 +25,7 @@ class WelcomePage extends React.PureComponent {
} else {
// first_user_auth because it's the first time
AsyncStorage.getItem(Constants.KEY_FIRST_USER_AUTH).then(firstUserAuth => {
if ('true' !== firstUserAuth) {
if (firstUserAuth !== 'true') {
// first_user_auth
NativeModules.Firebase.track('first_user_auth', null);
AsyncStorage.setItem(Constants.KEY_FIRST_USER_AUTH, 'true');
@ -47,25 +47,27 @@ class WelcomePage extends React.PureComponent {
const { authenticate } = this.props;
this.setState({ authenticationStarted: true, authenticationFailed: false });
NativeModules.VersionInfo.getAppVersion().then(appVersion => {
Lbry.status()
.then(info => {
this.setState({ sdkStarted: true });
NativeModules.Firebase.getMessagingToken().then(firebaseToken => {
Lbry.status()
.then(info => {
this.setState({ sdkStarted: true });
authenticate(appVersion, Platform.OS);
})
.catch(error => {
if (this.state.statusTries >= WelcomePage.MAX_STATUS_TRIES) {
this.setState({ authenticationFailed: true });
authenticate(appVersion, Platform.OS, firebaseToken);
})
.catch(error => {
if (this.state.statusTries >= WelcomePage.MAX_STATUS_TRIES) {
this.setState({ authenticationFailed: true });
// sdk_start_failed
NativeModules.Firebase.track('sdk_start_failed', null);
} else {
setTimeout(() => {
this.startAuthenticating();
this.setState({ statusTries: this.state.statusTries + 1 });
}, 1000); // Retry every second for a maximum of MAX_STATUS_TRIES tries (60 seconds)
}
});
// sdk_start_failed
NativeModules.Firebase.track('sdk_start_failed', null);
} else {
setTimeout(() => {
this.startAuthenticating();
this.setState({ statusTries: this.state.statusTries + 1 });
}, 1000); // Retry every second for a maximum of MAX_STATUS_TRIES tries (60 seconds)
}
});
});
});
};

View file

@ -66,7 +66,7 @@ class FirstRunScreen extends React.PureComponent {
componentWillReceiveProps(nextProps) {
const { emailNewErrorMessage, emailNewPending, syncApplyErrorMessage, syncApplyIsPending, user } = nextProps;
const { notify, isApplyingSync, setClientSetting, setDefaultAccount } = this.props;
const { notify, isApplyingSync, setClientSetting } = this.props;
if (this.state.emailSubmitted && !emailNewPending) {
this.setState({ emailSubmitted: false });
@ -86,27 +86,24 @@ class FirstRunScreen extends React.PureComponent {
} else {
// password successfully verified
NativeModules.UtilityModule.setSecureValue(
Constants.KEY_FIRST_RUN_PASSWORD,
Constants.KEY_WALLET_PASSWORD,
this.state.walletPassword ? this.state.walletPassword : ''
);
setDefaultAccount(
() => {
setClientSetting(Constants.SETTING_DEVICE_WALLET_SYNCED, true);
// unlock the wallet
setClientSetting(Constants.SETTING_DEVICE_WALLET_SYNCED, true);
Lbry.status().then(status => {
// unlock the wallet
if (status.wallet.is_locked) {
Lbry.account_unlock({ password: this.state.walletPassword ? this.state.walletPassword : '' })
.then(() => this.closeFinalPage())
.catch(err =>
notify({ message: 'The wallet could not be unlocked at this time. Please restart the app.' })
);
},
err => {
notify({
message:
'The account restore operation could not be completed successfully. Please restart the app and try again.',
});
} else {
// wallet not locked. close final page
this.closeFinalPage();
}
);
});
}
}
@ -298,7 +295,7 @@ class FirstRunScreen extends React.PureComponent {
const { getSync, setClientSetting } = this.props;
if (NativeModules.UtilityModule) {
const newPassword = this.state.walletPassword ? this.state.walletPassword : '';
NativeModules.UtilityModule.setSecureValue(Constants.KEY_FIRST_RUN_PASSWORD, newPassword);
NativeModules.UtilityModule.setSecureValue(Constants.KEY_WALLET_PASSWORD, newPassword);
Lbry.account_encrypt({ new_password: newPassword }).then(() => {
// fresh account, new password set
getSync(newPassword);

View file

@ -23,7 +23,7 @@ const select = state => ({
});
const perform = dispatch => ({
authenticate: (appVersion, os) => dispatch(doAuthenticate(appVersion, os)),
authenticate: (appVersion, os, firebaseToken) => dispatch(doAuthenticate(appVersion, os, firebaseToken)),
balanceSubscribe: () => dispatch(doBalanceSubscribe()),
blacklistedOutpointsSubscribe: () => dispatch(doBlackListedOutpointsSubscribe()),
filteredOutpointsSubscribe: () => dispatch(doFilteredOutpointsSubscribe()),

View file

@ -90,7 +90,7 @@ class SplashScreen extends React.PureComponent {
this.setState({ shouldAuthenticate: false }, () => {
// user is authenticated, navigate to the main view
if (user.has_verified_email) {
NativeModules.UtilityModule.getSecureValue(Constants.KEY_FIRST_RUN_PASSWORD).then(walletPassword => {
NativeModules.UtilityModule.getSecureValue(Constants.KEY_WALLET_PASSWORD).then(walletPassword => {
getSync(walletPassword);
this.navigateToMain();
});
@ -105,9 +105,15 @@ class SplashScreen extends React.PureComponent {
getUserSettings = () => {
const { populateSharedUserState } = this.props;
doPreferenceGet('shared', null, null, preference => {
populateSharedUserState(preference);
});
doPreferenceGet(
'shared',
preference => {
populateSharedUserState(preference);
},
error => {
/* failed */
}
);
};
finishSplashScreen = () => {
@ -134,14 +140,16 @@ class SplashScreen extends React.PureComponent {
if (user && user.id && user.has_verified_email) {
// user already authenticated
NativeModules.UtilityModule.getSecureValue(Constants.KEY_FIRST_RUN_PASSWORD).then(walletPassword => {
NativeModules.UtilityModule.getSecureValue(Constants.KEY_WALLET_PASSWORD).then(walletPassword => {
getSync(walletPassword);
this.navigateToMain();
});
} else {
NativeModules.VersionInfo.getAppVersion().then(appVersion => {
this.setState({ shouldAuthenticate: true });
authenticate(appVersion, Platform.OS);
NativeModules.Firebase.getMessagingToken().then(firebaseToken => {
this.setState({ shouldAuthenticate: true });
authenticate(appVersion, Platform.OS, firebaseToken);
});
});
}
});
@ -171,7 +179,7 @@ class SplashScreen extends React.PureComponent {
});
// For now, automatically unlock the wallet if a password is set so that downloads work
NativeModules.UtilityModule.getSecureValue(Constants.KEY_FIRST_RUN_PASSWORD).then(password => {
NativeModules.UtilityModule.getSecureValue(Constants.KEY_WALLET_PASSWORD).then(password => {
if (walletStatus.is_locked) {
this.setState({
message: 'Unlocking account',

View file

@ -3,7 +3,6 @@ import { doToast } from 'lbry-redux';
import {
doCheckSync,
doGetSync,
doSetDefaultAccount,
doSyncApply,
doUserEmailNew,
doUserEmailToVerify,
@ -60,7 +59,6 @@ const perform = dispatch => ({
verifyPhone: verificationCode => dispatch(doUserPhoneVerify(verificationCode)),
notify: data => dispatch(doToast(data)),
setClientSetting: (key, value) => dispatch(doSetClientSetting(key, value)),
setDefaultAccount: (success, failure) => dispatch(doSetDefaultAccount(success, failure)),
setEmailToVerify: email => dispatch(doUserEmailToVerify(email)),
syncApply: (hash, data, password) => dispatch(doSyncApply(hash, data, password)),
resendVerificationEmail: email => dispatch(doUserResendVerificationEmail(email)),

View file

@ -50,7 +50,7 @@ class SyncVerifyPage extends React.PureComponent {
componentWillReceiveProps(nextProps) {
const { getSyncIsPending, syncApplyIsPending, syncApplyErrorMessage } = nextProps;
const { getSync, hasSyncedWallet, navigation, notify, setClientSetting, setDefaultAccount } = this.props;
const { getSync, hasSyncedWallet, navigation, notify, setClientSetting } = this.props;
if (this.state.checkSyncStarted && !getSyncIsPending) {
this.setState({ syncChecked: true });
}
@ -63,17 +63,12 @@ class SyncVerifyPage extends React.PureComponent {
// password successfully verified
if (NativeModules.UtilityModule) {
NativeModules.UtilityModule.setSecureValue(
Constants.KEY_FIRST_RUN_PASSWORD,
Constants.KEY_WALLET_PASSWORD,
this.state.password ? this.state.password : ''
);
}
setDefaultAccount(
() => this.finishSync(true),
err => {
// fail silently and still finish
this.finishSync();
}
);
this.finishSync(true);
}
}
}

View file

@ -101,7 +101,6 @@ class VerificationScreen extends React.PureComponent {
notify,
addUserPhone,
getSyncIsPending,
setDefaultAccount,
hasSyncedWallet,
setSyncIsPending,
syncApplyIsPending,
@ -162,7 +161,6 @@ class VerificationScreen extends React.PureComponent {
notify={notify}
setEmailVerificationPhase={this.setEmailVerificationPhase}
setClientSetting={setClientSetting}
setDefaultAccount={setDefaultAccount}
setSyncIsPending={setSyncIsPending}
syncApplyIsPending={syncApplyIsPending}
syncApplyErrorMessage={syncApplyErrorMessage}

View file

@ -46,7 +46,7 @@ class WalletPage extends React.PureComponent {
const { deviceWalletSynced, getSync, user } = this.props;
if (deviceWalletSynced && user && user.has_verified_email) {
NativeModules.UtilityModule.getSecureValue(Constants.KEY_FIRST_RUN_PASSWORD).then(walletPassword => {
NativeModules.UtilityModule.getSecureValue(Constants.KEY_WALLET_PASSWORD).then(walletPassword => {
getSync(walletPassword);
});
}