2019-09-26 18:28:08 +02:00
|
|
|
// @flow
|
|
|
|
import React from 'react';
|
|
|
|
import { Form, FormField } from 'component/common/form';
|
|
|
|
import Button from 'component/button';
|
|
|
|
import Card from 'component/common/card';
|
2019-10-16 07:01:18 +02:00
|
|
|
import { setSavedPassword } from 'util/saved-passwords';
|
|
|
|
import usePersistedState from 'effects/use-persisted-state';
|
2019-10-28 15:04:37 +01:00
|
|
|
import I18nMessage from 'component/i18nMessage';
|
2020-09-18 17:16:49 +02:00
|
|
|
import { useHistory } from 'react-router';
|
2021-04-28 03:16:28 +02:00
|
|
|
import { SITE_HELP_EMAIL } from 'config';
|
2019-09-26 18:28:08 +02:00
|
|
|
|
|
|
|
type Props = {
|
2020-09-04 17:02:30 +02:00
|
|
|
getSync: ((any, boolean) => void, ?string) => void,
|
2019-09-26 18:28:08 +02:00
|
|
|
getSyncIsPending: boolean,
|
2019-10-24 17:48:58 +02:00
|
|
|
email: string,
|
2019-10-29 20:26:03 +01:00
|
|
|
passwordError: boolean,
|
2019-10-28 15:04:37 +01:00
|
|
|
signOut: () => void,
|
2020-05-29 21:20:01 +02:00
|
|
|
handleSyncComplete: (any, boolean) => void,
|
2019-09-26 18:28:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
function SyncPassword(props: Props) {
|
2020-05-29 21:20:01 +02:00
|
|
|
const { getSync, getSyncIsPending, email, signOut, passwordError, handleSyncComplete } = props;
|
2020-09-18 17:16:49 +02:00
|
|
|
const {
|
|
|
|
push,
|
|
|
|
location: { search },
|
|
|
|
} = useHistory();
|
|
|
|
const urlParams = new URLSearchParams(search);
|
|
|
|
const redirect = urlParams.get('redirect');
|
2019-09-26 18:28:08 +02:00
|
|
|
const [password, setPassword] = React.useState('');
|
2019-10-16 07:01:18 +02:00
|
|
|
const [rememberPassword, setRememberPassword] = usePersistedState(true);
|
2019-09-26 18:28:08 +02:00
|
|
|
|
|
|
|
function handleSubmit() {
|
2020-09-04 17:02:30 +02:00
|
|
|
getSync((error, hasDataChanged) => {
|
2020-05-29 21:20:01 +02:00
|
|
|
handleSyncComplete(error, hasDataChanged);
|
|
|
|
|
2020-01-03 21:43:49 +01:00
|
|
|
if (!error) {
|
2020-09-18 17:16:49 +02:00
|
|
|
push(redirect || '/');
|
2020-01-03 21:43:49 +01:00
|
|
|
setSavedPassword(password, rememberPassword);
|
|
|
|
}
|
2020-09-04 17:02:30 +02:00
|
|
|
}, password);
|
2019-09-26 18:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Form onSubmit={handleSubmit}>
|
|
|
|
<Card
|
2020-08-26 22:28:33 +02:00
|
|
|
title={__('Enter your wallet password')}
|
2019-10-24 17:48:58 +02:00
|
|
|
subtitle={__(
|
|
|
|
'You set your wallet password when you previously installed LBRY. This may have been on different device.'
|
|
|
|
)}
|
2019-09-26 18:28:08 +02:00
|
|
|
actions={
|
|
|
|
<div>
|
|
|
|
<FormField
|
|
|
|
type="password"
|
2019-10-29 20:26:03 +01:00
|
|
|
error={passwordError && __('Wrong password for %email%', { email })}
|
2019-10-24 17:48:58 +02:00
|
|
|
label={__('Password for %email%', { email })}
|
2019-09-26 18:28:08 +02:00
|
|
|
value={password}
|
2021-04-28 03:16:28 +02:00
|
|
|
onChange={(e) => setPassword(e.target.value)}
|
2019-09-26 18:28:08 +02:00
|
|
|
/>
|
|
|
|
<FormField
|
2019-10-16 07:01:18 +02:00
|
|
|
name="remember-password"
|
2019-09-26 18:28:08 +02:00
|
|
|
type="checkbox"
|
|
|
|
label={__('Remember My Password')}
|
|
|
|
checked={rememberPassword}
|
|
|
|
onChange={() => setRememberPassword(!rememberPassword)}
|
|
|
|
/>
|
|
|
|
<div className="card__actions">
|
2020-09-18 17:16:49 +02:00
|
|
|
<Button
|
|
|
|
type="submit"
|
|
|
|
button="primary"
|
|
|
|
label={getSyncIsPending ? __('Continue...') : __('Continue')}
|
|
|
|
disabled={getSyncIsPending}
|
|
|
|
/>
|
2019-10-28 15:04:37 +01:00
|
|
|
<Button button="link" label={__('Cancel')} onClick={signOut} />
|
2019-09-26 18:28:08 +02:00
|
|
|
</div>
|
2019-10-28 15:04:37 +01:00
|
|
|
<p className="help">
|
|
|
|
<I18nMessage
|
|
|
|
tokens={{
|
2022-01-31 17:38:57 +01:00
|
|
|
help: (
|
|
|
|
<Button
|
|
|
|
button="link"
|
|
|
|
label={__('help guide')}
|
|
|
|
href="https://odysee.com/@OdyseeHelp:b/OdyseeBasics:c"
|
|
|
|
/>
|
|
|
|
),
|
2021-04-28 03:16:28 +02:00
|
|
|
email: <Button button="link" href={`mailto:${SITE_HELP_EMAIL}`} label={`${SITE_HELP_EMAIL}`} />,
|
2019-10-28 15:04:37 +01:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
If you are having issues, checkout our %help% or email us at %email%.
|
|
|
|
</I18nMessage>
|
|
|
|
</p>
|
2019-09-26 18:28:08 +02:00
|
|
|
</div>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</Form>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default SyncPassword;
|