mirror of
https://github.com/LBRYFoundation/lbry-desktop.git
synced 2025-09-01 01:35:11 +00:00
fix race condition
This commit is contained in:
parent
3b23f09bed
commit
5f54469971
2 changed files with 21 additions and 22 deletions
|
@ -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--"
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,30 +115,29 @@ 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()
|
||||||
if (e) {
|
.then(pw => {
|
||||||
|
getSync(pw, (e, hasChanged) => {
|
||||||
|
if (e) {
|
||||||
|
setStep(ERROR);
|
||||||
|
setError(e && e.message ? e.message : e);
|
||||||
|
} else {
|
||||||
|
Lbry.preference_get().then(result => {
|
||||||
|
const prefs = {};
|
||||||
|
if (result[SHARED_KEY]) prefs[SHARED_KEY] = result[SHARED_KEY];
|
||||||
|
if (result[LOCAL_KEY]) prefs[LOCAL_KEY] = result[LOCAL_KEY];
|
||||||
|
setPrefDict(prefs);
|
||||||
|
setStep(CONFIRM);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(e => {
|
||||||
setStep(ERROR);
|
setStep(ERROR);
|
||||||
setError(e && e.message ? e.message : e);
|
setError(e && e.message ? e.message : e);
|
||||||
} else {
|
});
|
||||||
Lbry.preference_get().then(result => {
|
|
||||||
const prefs = {};
|
|
||||||
if (result[SHARED_KEY]) prefs[SHARED_KEY] = result[SHARED_KEY];
|
|
||||||
if (result[LOCAL_KEY]) prefs[LOCAL_KEY] = result[LOCAL_KEY];
|
|
||||||
setPrefDict(prefs);
|
|
||||||
setStep(CONFIRM);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
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 (
|
||||||
|
|
Loading…
Add table
Reference in a new issue