Add robot generation step

This commit is contained in:
Reckless_Satoshi 2023-02-17 04:31:43 -08:00
parent 1ce2dc4200
commit 35e12480f3
No known key found for this signature in database
GPG Key ID: 9C4585B561315571
8 changed files with 142 additions and 49 deletions

View File

@ -1,6 +1,6 @@
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { Alert, Button, Collapse, Grid, Typography, useTheme } from '@mui/material'; import { Alert, Button, Collapse, Grid, LinearProgress, Typography, useTheme } from '@mui/material';
import { useParams } from 'react-router-dom'; import { useParams } from 'react-router-dom';
import { Page } from '../NavBar'; import { Page } from '../NavBar';
@ -12,6 +12,7 @@ import { genBase62Token } from '../../utils';
interface OnboardingProps { interface OnboardingProps {
robot: Robot; robot: Robot;
setRobot: (state: Robot) => void;
inputToken: string; inputToken: string;
setInputToken: (state: string) => void; setInputToken: (state: string) => void;
getGenerateRobot: (token: string) => void; getGenerateRobot: (token: string) => void;
@ -35,6 +36,14 @@ const Onboarding = ({
const [step, setStep] = useState<'1' | '2' | '3'>('1'); const [step, setStep] = useState<'1' | '2' | '3'>('1');
const [generatedToken, setGeneratedToken] = useState<boolean>(false); const [generatedToken, setGeneratedToken] = useState<boolean>(false);
const [showMimickProgress, setShowMimickProgress] = useState<boolean>(false);
const generateToken = () => {
setGeneratedToken(true);
setInputToken(genBase62Token(36));
setShowMimickProgress(true);
setTimeout(() => setShowMimickProgress(false), 1000);
};
return ( return (
<Grid container direction='column' alignItems='center' spacing={2}> <Grid container direction='column' alignItems='center' spacing={2}>
@ -53,15 +62,7 @@ const Onboarding = ({
</Grid> </Grid>
{!generatedToken ? ( {!generatedToken ? (
<Grid item> <Grid item>
<Button <Button autoFocus onClick={generateToken} variant='contained' size='large'>
autoFocus
onClick={() => {
setGeneratedToken(true);
setInputToken(genBase62Token(36));
}}
variant='contained'
size='large'
>
<Casino /> <Casino />
{t('Generate token')} {t('Generate token')}
</Button> </Button>
@ -79,30 +80,26 @@ const Onboarding = ({
</Alert> </Alert>
</Grid> </Grid>
<Grid item sx={{ width: '100%' }}> <Grid item sx={{ width: '100%' }}>
<TokenInput {showMimickProgress ? (
inputToken={inputToken} <LinearProgress sx={{ height: '0.7em' }} />
setInputToken={setInputToken} ) : (
setRobot={setRobot} <TokenInput
badRequest={badRequest} inputToken={inputToken}
robot={robot} setInputToken={setInputToken}
onPressEnter={() => null} setRobot={setRobot}
badRequest={badRequest} badRequest={badRequest}
/> robot={robot}
onPressEnter={() => null}
badRequest={badRequest}
/>
)}
</Grid> </Grid>
<Grid item> <Grid item>
<Typography> <Typography>
{t( {t('You can also add your own random characters into the token or')}
'You can also add your own random characters into the token or roll the dice again', <Button size='small' onClick={generateToken}>
)}
<Button
size='small'
onClick={() => {
setGeneratedToken(true);
setInputToken(genBase62Token(36));
}}
>
<Casino /> <Casino />
{t('Generate another one')} {t('roll again')}
</Button> </Button>
</Typography> </Typography>
</Grid> </Grid>
@ -112,6 +109,7 @@ const Onboarding = ({
onClick={() => { onClick={() => {
setStep('2'); setStep('2');
getGenerateRobot(inputToken); getGenerateRobot(inputToken);
setRobot({ ...robot, nickname: null });
}} }}
variant='contained' variant='contained'
size='large' size='large'
@ -135,12 +133,67 @@ const Onboarding = ({
<Collapse in={step == '2'}> <Collapse in={step == '2'}>
<Grid container direction='column' alignItems='center' spacing={1} paddingLeft={4}> <Grid container direction='column' alignItems='center' spacing={1} paddingLeft={4}>
<Grid item> {robot.avatarLoaded && robot.nickname ? (
<Typography>{t('Your robot is under consctruction!')}</Typography> <Grid item>
<Typography>{t('Hi! My name is')}</Typography>
<Typography component='h5' variant='h5'>
<div
style={{
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
flexWrap: 'wrap',
height: '3.2em',
}}
>
<Bolt
sx={{
color: '#fcba03',
height: '1.5em',
width: '1.5em',
}}
/>
<a>{robot.nickname}</a>
<Bolt
sx={{
color: '#fcba03',
height: '1.5em',
width: '1.5em',
}}
/>
</div>
</Typography>
</Grid>
) : (
<Grid item>
<Typography>{t('Your robot is under consctruction!')}</Typography>
</Grid>
)}
<Grid item sx={{ width: '15em' }}>
<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> </Grid>
<Grid item> <Grid item>
<Typography>{t('Hi! My name is')}</Typography> <Button onClick={() => setStep('3')} variant='contained' size='large'>
<Check />
{t('Continue')}
</Button>
</Grid> </Grid>
</Grid> </Grid>
</Collapse> </Collapse>
@ -149,6 +202,13 @@ const Onboarding = ({
<Typography variant='h5' color={step == '3' ? 'text.primary' : 'text.disabled'}> <Typography variant='h5' color={step == '3' ? 'text.primary' : 'text.disabled'}>
{t('3. Browse or create an order')} {t('3. Browse or create an order')}
</Typography> </Typography>
<Collapse in={step == '3'}>
<Grid container direction='column' alignItems='center' spacing={1} paddingLeft={4}>
Marketplace See Offers contained buttonm Create Offer container button If you need
help fire away on our support public Telegram group! Support Telegram Group My profile
not contained button
</Grid>
</Collapse>
</Grid> </Grid>
</Grid> </Grid>
</Grid> </Grid>

View File

@ -53,18 +53,18 @@ const RobotPage = ({
const [tokenChanged, setTokenChanged] = useState<boolean>(false); const [tokenChanged, setTokenChanged] = useState<boolean>(false);
const [inputToken, setInputToken] = useState<string>(''); const [inputToken, setInputToken] = useState<string>('');
useEffect(() => { // useEffect(() => {
if (robot.nickname != null) { // if (robot.nickname != null) {
setInputToken(robot.token); // setInputToken(robot.token);
} else if (robot.token) { // } else if (robot.token) {
setInputToken(robot.token); // setInputToken(robot.token);
getGenerateRobot(robot.token); // getGenerateRobot(robot.token);
} else { // } else {
const newToken = genBase62Token(36); // const newToken = genBase62Token(36);
setInputToken(newToken); // setInputToken(newToken);
getGenerateRobot(newToken); // getGenerateRobot(newToken);
} // }
}, []); // }, []);
const getGenerateRobot = (token: string) => { const getGenerateRobot = (token: string) => {
const strength = tokenStrength(token); const strength = tokenStrength(token);
@ -162,7 +162,7 @@ const RobotPage = ({
elevation={12} elevation={12}
style={{ style={{
padding: '1em', padding: '1em',
width: `${Math.min(windowSize.width * 0.7, 30)}em`, width: `${Math.min(windowSize.width * 0.8, 30)}em`,
maxHeight: `${maxHeight}em`, maxHeight: `${maxHeight}em`,
overflow: 'auto', overflow: 'auto',
}} }}

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 KiB

View File

Before

Width:  |  Height:  |  Size: 388 KiB

After

Width:  |  Height:  |  Size: 388 KiB

View File

@ -12,6 +12,7 @@ interface Props {
flipHorizontally?: boolean; flipHorizontally?: boolean;
style?: object; style?: object;
imageStyle?: object; imageStyle?: object;
placeholderType?: 'loading' | 'generating';
statusColor?: 'primary' | 'secondary' | 'default' | 'error' | 'info' | 'success' | 'warning'; statusColor?: 'primary' | 'secondary' | 'default' | 'error' | 'info' | 'success' | 'warning';
orderType?: number; orderType?: number;
tooltip?: string; tooltip?: string;
@ -29,6 +30,7 @@ const RobotAvatar: React.FC<Props> = ({
tooltipPosition = 'right', tooltipPosition = 'right',
smooth = false, smooth = false,
flipHorizontally = false, flipHorizontally = false,
placeholderType = 'loading',
style = {}, style = {},
avatarClass = 'flippedSmallAvatar', avatarClass = 'flippedSmallAvatar',
imageStyle = {}, imageStyle = {},
@ -39,6 +41,16 @@ const RobotAvatar: React.FC<Props> = ({
const theme = useTheme(); const theme = useTheme();
const [avatarSrc, setAvatarSrc] = useState<string>(); const [avatarSrc, setAvatarSrc] = useState<string>();
const backgroundData =
placeholderType == 'generating' ? placeholder.generating : placeholder.loading;
const backgroundImage = `url(data:${backgroundData.mime};base64,${backgroundData.data})`;
const className =
placeholderType == 'loading'
? theme.palette.mode === 'dark'
? 'loadingAvatarDark'
: 'loadingAvatar'
: 'generatingAvatar';
useEffect(() => { useEffect(() => {
if (nickname != undefined) { if (nickname != undefined) {
if (window.NativeRobosats === undefined) { if (window.NativeRobosats === undefined) {
@ -76,10 +88,10 @@ const RobotAvatar: React.FC<Props> = ({
transform: flipHorizontally ? 'scaleX(-1)' : '', transform: flipHorizontally ? 'scaleX(-1)' : '',
border: '0.3px solid #55555', border: '0.3px solid #55555',
filter: 'dropShadow(0.5px 0.5px 0.5px #000000)', filter: 'dropShadow(0.5px 0.5px 0.5px #000000)',
backgroundImage: `url(data:${placeholder.image.mime};base64,${placeholder.image.data})`, backgroundImage,
}} }}
> >
<div className={theme.palette.mode === 'dark' ? 'loadingAvatarDark' : 'loadingAvatar'}> <div className={className}>
<SmoothImage <SmoothImage
src={avatarSrc} src={avatarSrc}
imageStyles={{ imageStyles={{

View File

Before

Width:  |  Height:  |  Size: 72 KiB

After

Width:  |  Height:  |  Size: 72 KiB

File diff suppressed because one or more lines are too long

View File

@ -228,3 +228,20 @@ input[type='number'] {
background-repeat: repeat; background-repeat: repeat;
animation: animatedBackground 5s linear infinite; animation: animatedBackground 5s linear infinite;
} }
.generatingAvatar {
background-size: 100%;
border-radius: 50%;
border: 0.3px solid #555;
filter: dropShadow(1px 1px 1px #000000);
background-image: linear-gradient(
0deg,
#ffd9001f 0%,
#3609ff33 40%,
#ff32322d 60%,
#ffd9001f 100%
);
background-position: 0px 0px;
background-repeat: repeat;
animation: animatedBackground 5s linear infinite;
}