call preference get after entering wallet password

This commit is contained in:
Sean Yesmunt 2020-05-29 15:20:01 -04:00
parent 4d3bdda55c
commit d301102af6
4 changed files with 24 additions and 25 deletions

View file

@ -1,7 +1,7 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { doGetSync, selectGetSyncIsPending, selectUserEmail, selectSyncApplyPasswordError } from 'lbryinc'; import { doGetSync, selectGetSyncIsPending, selectUserEmail, selectSyncApplyPasswordError } from 'lbryinc';
import { doSetClientSetting } from 'redux/actions/settings'; import { doSetClientSetting } from 'redux/actions/settings';
import { doSignOut } from 'redux/actions/app'; import { doSignOut, doHandleSyncComplete } from 'redux/actions/app';
import SyncPassword from './view'; import SyncPassword from './view';
const select = state => ({ const select = state => ({
@ -13,10 +13,8 @@ const select = state => ({
const perform = dispatch => ({ const perform = dispatch => ({
getSync: (password, cb) => dispatch(doGetSync(password, cb)), getSync: (password, cb) => dispatch(doGetSync(password, cb)),
setClientSetting: (key, value) => dispatch(doSetClientSetting(key, value)), setClientSetting: (key, value) => dispatch(doSetClientSetting(key, value)),
handleSyncComplete: (error, hasDataChanged) => dispatch(doHandleSyncComplete(error, hasDataChanged)),
signOut: () => dispatch(doSignOut()), signOut: () => dispatch(doSignOut()),
}); });
export default connect( export default connect(select, perform)(SyncPassword);
select,
perform
)(SyncPassword);

View file

@ -8,20 +8,23 @@ import usePersistedState from 'effects/use-persisted-state';
import I18nMessage from 'component/i18nMessage'; import I18nMessage from 'component/i18nMessage';
type Props = { type Props = {
getSync: (?string, (any) => void) => void, getSync: (?string, (any, boolean) => void) => void,
getSyncIsPending: boolean, getSyncIsPending: boolean,
email: string, email: string,
passwordError: boolean, passwordError: boolean,
signOut: () => void, signOut: () => void,
handleSyncComplete: (any, boolean) => void,
}; };
function SyncPassword(props: Props) { function SyncPassword(props: Props) {
const { getSync, getSyncIsPending, email, signOut, passwordError } = props; const { getSync, getSyncIsPending, email, signOut, passwordError, handleSyncComplete } = props;
const [password, setPassword] = React.useState(''); const [password, setPassword] = React.useState('');
const [rememberPassword, setRememberPassword] = usePersistedState(true); const [rememberPassword, setRememberPassword] = usePersistedState(true);
function handleSubmit() { function handleSubmit() {
getSync(password, error => { getSync(password, (error, hasDataChanged) => {
handleSyncComplete(error, hasDataChanged);
if (!error) { if (!error) {
setSavedPassword(password, rememberPassword); setSavedPassword(password, rememberPassword);
} }

View file

@ -31,7 +31,7 @@ import {
doAuthTokenRefresh, doAuthTokenRefresh,
} from 'util/saved-passwords'; } from 'util/saved-passwords';
import { X_LBRY_AUTH_TOKEN } from 'constants/token'; import { X_LBRY_AUTH_TOKEN } from 'constants/token';
import { LBRY_WEB_API } from 'config'; import { LBRY_WEB_API, DEFAULT_LANGUAGE } from 'config';
// Import our app styles // Import our app styles
// If a style is not necessary for the initial page load, it should be removed from `all.scss` // If a style is not necessary for the initial page load, it should be removed from `all.scss`
@ -41,7 +41,6 @@ import 'scss/all.scss';
// @if TARGET='web' // @if TARGET='web'
// These overrides can't live in web/ because they need to use the same instance of `Lbry` // These overrides can't live in web/ because they need to use the same instance of `Lbry`
import apiPublishCallViaWeb from 'web/setup/publish'; import apiPublishCallViaWeb from 'web/setup/publish';
const { DEFAULT_LANGUAGE } = require('../config.js');
// Sentry error logging setup // Sentry error logging setup
// Will only work if you have a SENTRY_AUTH_TOKEN env // Will only work if you have a SENTRY_AUTH_TOKEN env
@ -242,7 +241,7 @@ document.addEventListener('click', event => {
function AppWrapper() { function AppWrapper() {
// Splash screen and sdk setup not needed on web // Splash screen and sdk setup not needed on web
const [readyToLaunch, setReadyToLaunch] = useState(IS_WEB || sessionStorage.getItem('startup')); const [readyToLaunch, setReadyToLaunch] = useState(IS_WEB);
const [persistDone, setPersistDone] = useState(false); const [persistDone, setPersistDone] = useState(false);
useEffect(() => { useEffect(() => {
@ -276,11 +275,8 @@ function AppWrapper() {
useEffect(() => { useEffect(() => {
if (readyToLaunch && persistDone) { if (readyToLaunch && persistDone) {
// @if TARGET='app' if (DEFAULT_LANGUAGE) {
sessionStorage.setItem('startup', true); app.store.dispatch(doFetchLanguage(DEFAULT_LANGUAGE));
// @endif
if (process.env.DEFAULT_LANGUAGE) {
app.store.dispatch(doFetchLanguage(process.env.DEFAULT_LANGUAGE));
} }
app.store.dispatch(doUpdateIsNightAsync()); app.store.dispatch(doUpdateIsNightAsync());
app.store.dispatch(doDaemonReady()); app.store.dispatch(doDaemonReady());

View file

@ -586,9 +586,8 @@ export function doGetAndPopulatePreferences() {
}; };
} }
export function doSyncWithPreferences() { export function doHandleSyncComplete(error, hasNewData) {
return dispatch => { return dispatch => {
function handleSyncComplete(error, hasNewData) {
if (!error) { if (!error) {
dispatch(doGetAndPopulatePreferences()); dispatch(doGetAndPopulatePreferences());
@ -597,12 +596,15 @@ export function doSyncWithPreferences() {
dispatch(doFetchChannelListMine()); dispatch(doFetchChannelListMine());
} }
} }
} };
}
export function doSyncWithPreferences() {
return dispatch => {
return getSavedPassword().then(password => { return getSavedPassword().then(password => {
const passwordArgument = password === null ? '' : password; const passwordArgument = password === null ? '' : password;
dispatch(doGetSync(passwordArgument, handleSyncComplete)); dispatch(doGetSync(passwordArgument, (error, hasNewData) => dispatch(doHandleSyncComplete(error, hasNewData))));
}); });
}; };
} }