fix race condition

This commit is contained in:
jessop 2020-09-18 00:10:20 -04:00 committed by Sean Yesmunt
parent 3b23f09bed
commit 5f54469971
2 changed files with 21 additions and 22 deletions

View file

@ -1307,5 +1307,6 @@
"Getting your profiles...": "Getting your profiles...", "Getting your profiles...": "Getting your profiles...",
"Enabling sync will switch to your cloud profile.": "Enabling sync will switch to your cloud profile.", "Enabling sync will switch to your cloud profile.": "Enabling sync will switch to your cloud profile.",
"Disabling sync will switch to your local profile.": "Disabling sync will switch to your local profile.", "Disabling sync will switch to your local profile.": "Disabling sync will switch to your local profile.",
"Something went wrong...": "Something went wrong...",
"--end--": "--end--" "--end--": "--end--"
} }

View file

@ -46,7 +46,6 @@ function SyncEnableFlow(props: Props) {
const [step, setStep] = React.useState(INITIAL); const [step, setStep] = React.useState(INITIAL);
const [prefDict, setPrefDict]: [any, (any) => void] = React.useState(); const [prefDict, setPrefDict]: [any, (any) => void] = React.useState();
const [password, setPassword] = React.useState('');
const [error, setError] = React.useState(); const [error, setError] = React.useState();
const handleSyncToggle = async () => { const handleSyncToggle = async () => {
@ -116,17 +115,11 @@ function SyncEnableFlow(props: Props) {
} }
}, [mode]); }, [mode]);
React.useEffect(() => {
getSavedPassword()
.then(pw => setPassword(pw || ''))
.catch(e => {
setError(e && e.message ? e.message : e);
});
}, []);
React.useEffect(() => { React.useEffect(() => {
if (step === FETCH_FOR_ENABLE) { if (step === FETCH_FOR_ENABLE) {
getSync(password, (e, hasChanged) => { getSavedPassword()
.then(pw => {
getSync(pw, (e, hasChanged) => {
if (e) { if (e) {
setStep(ERROR); setStep(ERROR);
setError(e && e.message ? e.message : e); setError(e && e.message ? e.message : e);
@ -140,6 +133,11 @@ function SyncEnableFlow(props: Props) {
}); });
} }
}); });
})
.catch(e => {
setStep(ERROR);
setError(e && e.message ? e.message : e);
});
} }
if (step === FETCH_FOR_DISABLE) { if (step === FETCH_FOR_DISABLE) {
Lbry.preference_get().then(result => { Lbry.preference_get().then(result => {
@ -150,7 +148,7 @@ function SyncEnableFlow(props: Props) {
setStep(CONFIRM); setStep(CONFIRM);
}); });
} }
}, [step, setPrefDict, setStep, password]); }, [step, setPrefDict, setStep]);
if (getSyncPending) { if (getSyncPending) {
return ( return (