mirror of
https://github.com/RoboSats/robosats.git
synced 2025-01-11 00:31:34 +00:00
Add robot profile component
This commit is contained in:
parent
cf299a5c20
commit
8644432ab2
@ -182,7 +182,10 @@ const Onboarding = ({
|
|||||||
{robot.avatarLoaded && robot.nickname ? (
|
{robot.avatarLoaded && robot.nickname ? (
|
||||||
t('This is your trading avatar')
|
t('This is your trading avatar')
|
||||||
) : (
|
) : (
|
||||||
|
<>
|
||||||
<b>{t('Building your robot!')}</b>
|
<b>{t('Building your robot!')}</b>
|
||||||
|
<LinearProgress />
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
</Typography>
|
</Typography>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
@ -25,6 +25,7 @@ const Recovery = ({
|
|||||||
robot,
|
robot,
|
||||||
setRobot,
|
setRobot,
|
||||||
inputToken,
|
inputToken,
|
||||||
|
setView,
|
||||||
setInputToken,
|
setInputToken,
|
||||||
getGenerateRobot,
|
getGenerateRobot,
|
||||||
setPage,
|
setPage,
|
||||||
@ -40,6 +41,8 @@ const Recovery = ({
|
|||||||
if (recoveryDisabled()) {
|
if (recoveryDisabled()) {
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
|
getGenerateRobot(inputToken);
|
||||||
|
setView('profile');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -58,13 +61,19 @@ const Recovery = ({
|
|||||||
inputToken={inputToken}
|
inputToken={inputToken}
|
||||||
setInputToken={setInputToken}
|
setInputToken={setInputToken}
|
||||||
setRobot={setRobot}
|
setRobot={setRobot}
|
||||||
|
label={t('Paste token here')}
|
||||||
robot={robot}
|
robot={robot}
|
||||||
onPressEnter={onClickRecover}
|
onPressEnter={onClickRecover}
|
||||||
badRequest={''}
|
badRequest={''}
|
||||||
/>
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item>
|
<Grid item>
|
||||||
<Button variant='contained' size='large' disabled={recoveryDisabled()}>
|
<Button
|
||||||
|
variant='contained'
|
||||||
|
size='large'
|
||||||
|
disabled={recoveryDisabled()}
|
||||||
|
onClick={onClickRecover}
|
||||||
|
>
|
||||||
<Key /> <div style={{ width: '0.5em' }} />
|
<Key /> <div style={{ width: '0.5em' }} />
|
||||||
{t('Recover')}
|
{t('Recover')}
|
||||||
</Button>
|
</Button>
|
||||||
|
@ -1,22 +1,125 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { Box, Button, Grid, Typography, useTheme } from '@mui/material';
|
import { Box, Button, Grid, LinearProgress, Typography, useTheme } from '@mui/material';
|
||||||
import { RoboSatsTextIcon } from '../../components/Icons';
|
|
||||||
import { FastForward, RocketLaunch } from '@mui/icons-material';
|
import { FastForward, RocketLaunch } from '@mui/icons-material';
|
||||||
import SmartToy from '@mui/icons-material/SmartToy';
|
import SmartToy from '@mui/icons-material/SmartToy';
|
||||||
|
import RobotAvatar from '../../components/RobotAvatar';
|
||||||
|
import Bolt from '@mui/icons-material/Bolt';
|
||||||
|
import TokenInput from './TokenInput';
|
||||||
|
import { Page } from '../NavBar';
|
||||||
|
import { Robot } from '../../models';
|
||||||
|
|
||||||
interface RobotProfileProps {
|
interface RobotProfileProps {
|
||||||
|
robot: Robot;
|
||||||
|
setRobot: (state: Robot) => void;
|
||||||
setView: (state: 'welcome' | 'onboarding' | 'recovery' | 'profile') => void;
|
setView: (state: 'welcome' | 'onboarding' | 'recovery' | 'profile') => void;
|
||||||
|
inputToken: string;
|
||||||
|
setInputToken: (state: string) => void;
|
||||||
|
getGenerateRobot: (token: string) => void;
|
||||||
|
setPage: (state: Page) => void;
|
||||||
|
baseUrl: string;
|
||||||
|
badRequest: string;
|
||||||
|
robotFound: boolean;
|
||||||
width: number;
|
width: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
const RobotProfile = ({ setView, width }: RobotProfileProps): JSX.Element => {
|
const RobotProfile = ({
|
||||||
|
robot,
|
||||||
|
setRobot,
|
||||||
|
inputToken,
|
||||||
|
setInputToken,
|
||||||
|
getGenerateRobot,
|
||||||
|
setPage,
|
||||||
|
badRequest,
|
||||||
|
baseUrl,
|
||||||
|
robotFound,
|
||||||
|
width,
|
||||||
|
}: RobotProfileProps): JSX.Element => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Grid container direction='column' alignItems='center' spacing={1} padding={1}>
|
<Grid container direction='column' alignItems='center' spacing={2} padding={2}>
|
||||||
<Grid item></Grid>
|
<Grid item sx={{ height: '2.3em', position: 'relative' }}>
|
||||||
|
{robot.avatarLoaded && robot.nickname ? (
|
||||||
|
<Typography align='center' component='h5' variant='h5'>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
flexWrap: 'wrap',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{width < 19 ? null : (
|
||||||
|
<Bolt
|
||||||
|
sx={{
|
||||||
|
color: '#fcba03',
|
||||||
|
height: '1.5em',
|
||||||
|
width: '1.5em',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
<b>{robot.nickname}</b>
|
||||||
|
{width < 19 ? null : (
|
||||||
|
<Bolt
|
||||||
|
sx={{
|
||||||
|
color: '#fcba03',
|
||||||
|
height: '1.5em',
|
||||||
|
width: '1.5em',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</Typography>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<b>{t('Rebuilding your robot!')}</b>
|
||||||
|
<LinearProgress />
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
<Grid item sx={{ width: `13.5em` }}>
|
||||||
|
<RobotAvatar
|
||||||
|
nickname={robot.nickname}
|
||||||
|
smooth={true}
|
||||||
|
style={{ maxWidth: '12.5em', maxHeight: '12.5em' }}
|
||||||
|
placeholderType='generating'
|
||||||
|
imageStyle={{
|
||||||
|
transform: '',
|
||||||
|
border: '2px solid #555',
|
||||||
|
filter: 'drop-shadow(1px 1px 1px #000000)',
|
||||||
|
height: `12.4em`,
|
||||||
|
width: `12.4em`,
|
||||||
|
}}
|
||||||
|
tooltip={t('This is your trading avatar')}
|
||||||
|
tooltipPosition='top'
|
||||||
|
baseUrl={baseUrl}
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
{robotFound ? (
|
||||||
|
<Grid item>
|
||||||
|
<Typography variant='subtitle2' color='primary'>
|
||||||
|
{t('Welcome back!')}
|
||||||
|
<br />
|
||||||
|
</Typography>
|
||||||
|
</Grid>
|
||||||
|
) : (
|
||||||
|
<></>
|
||||||
|
)}
|
||||||
|
<Grid item sx={{ width: '100%' }}>
|
||||||
|
<TokenInput
|
||||||
|
inputToken={inputToken}
|
||||||
|
editable={false}
|
||||||
|
setInputToken={setInputToken}
|
||||||
|
setRobot={setRobot}
|
||||||
|
badRequest={badRequest}
|
||||||
|
robot={robot}
|
||||||
|
onPressEnter={() => null}
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -21,6 +21,7 @@ import { saveAsJson } from '../../utils';
|
|||||||
|
|
||||||
interface TokenInputProps {
|
interface TokenInputProps {
|
||||||
robot: Robot;
|
robot: Robot;
|
||||||
|
editable?: boolean;
|
||||||
showDownload?: boolean;
|
showDownload?: boolean;
|
||||||
fullWidth?: boolean;
|
fullWidth?: boolean;
|
||||||
setRobot: (state: Robot) => void;
|
setRobot: (state: Robot) => void;
|
||||||
@ -29,11 +30,14 @@ interface TokenInputProps {
|
|||||||
badRequest: string | undefined;
|
badRequest: string | undefined;
|
||||||
setInputToken: (state: string) => void;
|
setInputToken: (state: string) => void;
|
||||||
showCopy?: boolean;
|
showCopy?: boolean;
|
||||||
|
label?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const TokenInput = ({
|
const TokenInput = ({
|
||||||
robot,
|
robot,
|
||||||
|
editable = true,
|
||||||
showCopy = true,
|
showCopy = true,
|
||||||
|
label,
|
||||||
setRobot,
|
setRobot,
|
||||||
showDownload = false,
|
showDownload = false,
|
||||||
fullWidth = true,
|
fullWidth = true,
|
||||||
@ -58,12 +62,14 @@ const TokenInput = ({
|
|||||||
return (
|
return (
|
||||||
<TextField
|
<TextField
|
||||||
error={!!badRequest}
|
error={!!badRequest}
|
||||||
|
disabled={!editable}
|
||||||
required={true}
|
required={true}
|
||||||
|
label={label ? label : undefined}
|
||||||
value={inputToken}
|
value={inputToken}
|
||||||
autoFocus
|
autoFocus
|
||||||
fullWidth={fullWidth}
|
fullWidth={fullWidth}
|
||||||
sx={{ borderColor: 'primary' }}
|
sx={{ borderColor: 'primary' }}
|
||||||
variant='outlined'
|
variant={editable ? 'outlined' : 'filled'}
|
||||||
helperText={badRequest}
|
helperText={badRequest}
|
||||||
size='medium'
|
size='medium'
|
||||||
onChange={(e) => setInputToken(e.target.value)}
|
onChange={(e) => setInputToken(e.target.value)}
|
||||||
|
@ -5,7 +5,7 @@ import { useParams } from 'react-router-dom';
|
|||||||
|
|
||||||
import { Page } from '../NavBar';
|
import { Page } from '../NavBar';
|
||||||
import { Robot } from '../../models';
|
import { Robot } from '../../models';
|
||||||
import { genBase62Token, saveAsJson, tokenStrength } from '../../utils';
|
import { tokenStrength } from '../../utils';
|
||||||
import { systemClient } from '../../services/System';
|
import { systemClient } from '../../services/System';
|
||||||
import { apiClient } from '../../services/api';
|
import { apiClient } from '../../services/api';
|
||||||
import { genKey } from '../../pgp';
|
import { genKey } from '../../pgp';
|
||||||
@ -45,20 +45,18 @@ const RobotPage = ({
|
|||||||
const [badRequest, setBadRequest] = useState<string | undefined>(undefined);
|
const [badRequest, setBadRequest] = useState<string | undefined>(undefined);
|
||||||
const [tokenChanged, setTokenChanged] = useState<boolean>(false);
|
const [tokenChanged, setTokenChanged] = useState<boolean>(false);
|
||||||
const [inputToken, setInputToken] = useState<string>('');
|
const [inputToken, setInputToken] = useState<string>('');
|
||||||
const [view, setView] = useState<'welcome' | 'onboarding' | 'recovery' | 'profile'>('welcome');
|
const [view, setView] = useState<'welcome' | 'onboarding' | 'recovery' | 'profile'>(
|
||||||
|
robot.token ? 'profile' : 'welcome',
|
||||||
|
);
|
||||||
|
|
||||||
// useEffect(() => {
|
useEffect(() => {
|
||||||
// if (robot.nickname != null) {
|
if (robot.token) {
|
||||||
// setInputToken(robot.token);
|
setInputToken(robot.token);
|
||||||
// } else if (robot.token) {
|
}
|
||||||
// setInputToken(robot.token);
|
if (robot.nickname == null && robot.token) {
|
||||||
// getGenerateRobot(robot.token);
|
getGenerateRobot(robot.token);
|
||||||
// } else {
|
}
|
||||||
// const newToken = genBase62Token(36);
|
}, []);
|
||||||
// setInputToken(newToken);
|
|
||||||
// getGenerateRobot(newToken);
|
|
||||||
// }
|
|
||||||
// }, []);
|
|
||||||
|
|
||||||
const getGenerateRobot = (token: string) => {
|
const getGenerateRobot = (token: string) => {
|
||||||
const strength = tokenStrength(token);
|
const strength = tokenStrength(token);
|
||||||
@ -152,6 +150,11 @@ const RobotPage = ({
|
|||||||
overflowX: 'clip',
|
overflowX: 'clip',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
{/* TOR LOADING
|
||||||
|
Your connection is being encrypted and annonimized using the TOR Network. This ensures maximum privacy, however you might feel it is a bit slow or even lose connection from time to time.
|
||||||
|
|
||||||
|
*/}
|
||||||
|
|
||||||
{view === 'welcome' ? <Welcome setView={setView} width={width} /> : null}
|
{view === 'welcome' ? <Welcome setView={setView} width={width} /> : null}
|
||||||
|
|
||||||
{view === 'onboarding' ? (
|
{view === 'onboarding' ? (
|
||||||
@ -172,8 +175,10 @@ const RobotPage = ({
|
|||||||
<RobotProfile
|
<RobotProfile
|
||||||
setView={setView}
|
setView={setView}
|
||||||
robot={robot}
|
robot={robot}
|
||||||
|
robotFound={robotFound}
|
||||||
setRobot={setRobot}
|
setRobot={setRobot}
|
||||||
badRequest={badRequest}
|
badRequest={badRequest}
|
||||||
|
width={width}
|
||||||
inputToken={inputToken}
|
inputToken={inputToken}
|
||||||
setInputToken={setInputToken}
|
setInputToken={setInputToken}
|
||||||
getGenerateRobot={getGenerateRobot}
|
getGenerateRobot={getGenerateRobot}
|
||||||
|
@ -56,12 +56,6 @@ body {
|
|||||||
position: fixed;
|
position: fixed;
|
||||||
}
|
}
|
||||||
|
|
||||||
.clickTrough {
|
|
||||||
height: 50px;
|
|
||||||
pointer-events: none;
|
|
||||||
z-index: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* No arrows on numeric inputs */
|
/* No arrows on numeric inputs */
|
||||||
input::-webkit-outer-spin-button,
|
input::-webkit-outer-spin-button,
|
||||||
input::-webkit-inner-spin-button {
|
input::-webkit-inner-spin-button {
|
||||||
|
Loading…
Reference in New Issue
Block a user