mirror of
https://github.com/RoboSats/robosats.git
synced 2025-01-11 00:31:34 +00:00
Add robot generation step
This commit is contained in:
parent
1ce2dc4200
commit
35e12480f3
@ -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,6 +80,9 @@ const Onboarding = ({
|
|||||||
</Alert>
|
</Alert>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item sx={{ width: '100%' }}>
|
<Grid item sx={{ width: '100%' }}>
|
||||||
|
{showMimickProgress ? (
|
||||||
|
<LinearProgress sx={{ height: '0.7em' }} />
|
||||||
|
) : (
|
||||||
<TokenInput
|
<TokenInput
|
||||||
inputToken={inputToken}
|
inputToken={inputToken}
|
||||||
setInputToken={setInputToken}
|
setInputToken={setInputToken}
|
||||||
@ -88,21 +92,14 @@ const Onboarding = ({
|
|||||||
onPressEnter={() => null}
|
onPressEnter={() => null}
|
||||||
badRequest={badRequest}
|
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}>
|
||||||
|
{robot.avatarLoaded && robot.nickname ? (
|
||||||
|
<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>
|
<Grid item>
|
||||||
<Typography>{t('Your robot is under consctruction!')}</Typography>
|
<Typography>{t('Your robot is under consctruction!')}</Typography>
|
||||||
</Grid>
|
</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 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>
|
||||||
|
@ -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',
|
||||||
}}
|
}}
|
||||||
|
BIN
frontend/src/components/RobotAvatar/generatingCompressed.gif
Normal file
BIN
frontend/src/components/RobotAvatar/generatingCompressed.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 97 KiB |
Before Width: | Height: | Size: 388 KiB After Width: | Height: | Size: 388 KiB |
@ -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={{
|
||||||
|
Before Width: | Height: | Size: 72 KiB After Width: | Height: | Size: 72 KiB |
File diff suppressed because one or more lines are too long
@ -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;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user