diff --git a/frontend/src/basic/Main.tsx b/frontend/src/basic/Main.tsx index 51aeb783..010c346d 100644 --- a/frontend/src/basic/Main.tsx +++ b/frontend/src/basic/Main.tsx @@ -352,6 +352,7 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => { void; + getGenerateRobot: (token: string) => void; + badRequest: string | undefined; + setPage: (state: Page) => void; + baseUrl: string; +} + +const Onboarding = ({ + robot, + inputToken, + setInputToken, + setRobot, + badRequest, + getGenerateRobot, + setPage, + baseUrl, +}: OnboardingProps): JSX.Element => { + const { t } = useTranslation(); + const theme = useTheme(); + + const [step, setStep] = useState<'1' | '2' | '3'>('1'); + const [generatedToken, setGeneratedToken] = useState(false); + + return ( + + + + {t('1. Generate a token')} + + + + + + {t( + 'This temporary key gives you access to a unique and private robot identity for your trade.', + )} + + + {!generatedToken ? ( + + + + ) : ( + + + + + + {`${t('Store it somewhere safe!')} `} + {t( + `This token is the one and only key to your robot and trade. You will need it later to recover your order or check it's status.`, + )} + + + + null} + badRequest={badRequest} + /> + + + + {t( + 'You can also add your own random characters into the token or roll the dice again', + )} + + + + + + + + + + + )} + + + + + + {t('2. Meet your robot identity')} + + + + + + + {t('Your robot is under consctruction!')} + + + + {t('Hi! My name is')} + + + + + + + {t('3. Browse or create an order')} + + + + + ); +}; + +export default Onboarding; diff --git a/frontend/src/basic/RobotPage/Recovery.tsx b/frontend/src/basic/RobotPage/Recovery.tsx new file mode 100644 index 00000000..d8f830c5 --- /dev/null +++ b/frontend/src/basic/RobotPage/Recovery.tsx @@ -0,0 +1,38 @@ +import React, { useEffect, useState } from 'react'; +import { useTranslation } from 'react-i18next'; +import { Button, Collapse, Grid, Typography, useTheme } from '@mui/material'; +import { useParams } from 'react-router-dom'; + +import { Page } from '../NavBar'; +import { Robot } from '../../models'; +import { Casino, Download, ContentCopy, SmartToy, Bolt } from '@mui/icons-material'; +import RobotAvatar from '../../components/RobotAvatar'; + +interface RecoveryProps { + robot: Robot; + inputToken: string; + setInputToken: (state: string) => void; + getGenerateRobot: (token: string) => void; + setPage: (state: Page) => void; + baseUrl: string; +} + +const Recovery = ({ + robot, + inputToken, + setInputToken, + getGenerateRobot, + setPage, + baseUrl, +}: RecoveryProps): JSX.Element => { + const { t } = useTranslation(); + const theme = useTheme(); + + return ( + + + + ); +}; + +export default Recovery; diff --git a/frontend/src/basic/RobotPage/RobotProfile.tsx b/frontend/src/basic/RobotPage/RobotProfile.tsx new file mode 100644 index 00000000..e69de29b diff --git a/frontend/src/basic/RobotPage/TokenInput.tsx b/frontend/src/basic/RobotPage/TokenInput.tsx new file mode 100644 index 00000000..d5c2c1d5 --- /dev/null +++ b/frontend/src/basic/RobotPage/TokenInput.tsx @@ -0,0 +1,104 @@ +import React, { useEffect, useState } from 'react'; +import { useTranslation } from 'react-i18next'; +import { + Button, + Collapse, + Grid, + IconButton, + TextField, + Tooltip, + Typography, + useTheme, +} from '@mui/material'; +import { useParams } from 'react-router-dom'; + +import { Page } from '../NavBar'; +import { Robot } from '../../models'; +import { Casino, Download, ContentCopy, SmartToy, Bolt } from '@mui/icons-material'; +import RobotAvatar from '../../components/RobotAvatar'; +import { systemClient } from '../../services/System'; +import { saveAsJson } from '../../utils'; + +interface TokenInputProps { + robot: Robot; + showDownload?: boolean; + fullWidth?: boolean; + setRobot: (state: Robot) => void; + inputToken: string; + onPressEnter: () => void; + badRequest: string | undefined; + setInputToken: (state: string) => void; +} + +const TokenInput = ({ + robot, + setRobot, + showDownload = false, + fullWidth = true, + onPressEnter, + inputToken, + badRequest, + setInputToken, +}: TokenInputProps): JSX.Element => { + const { t } = useTranslation(); + const theme = useTheme(); + + const createJsonFile = () => { + return { + token: robot.token, + token_shannon_entropy: robot.shannonEntropy, + token_bit_entropy: robot.bitsEntropy, + public_key: robot.pubKey, + encrypted_private_key: robot.encPrivKey, + }; + }; + + return ( + setInputToken(e.target.value)} + onKeyPress={(e) => { + if (e.key === 'Enter') { + onPressEnter(); + } + }} + InputProps={{ + startAdornment: showDownload ? ( + + + saveAsJson(robot.nickname + '.json', createJsonFile())} + > + + + + + ) : null, + endAdornment: ( + + { + systemClient.copyToClipboard(inputToken); + setRobot({ ...robot, copiedToken: true }); + }} + > + + + + ), + }} + /> + ); +}; + +export default TokenInput; diff --git a/frontend/src/basic/RobotPage/Welcome.tsx b/frontend/src/basic/RobotPage/Welcome.tsx new file mode 100644 index 00000000..e69de29b diff --git a/frontend/src/basic/RobotPage/index.tsx b/frontend/src/basic/RobotPage/index.tsx index 0112f4f3..3ad44c68 100644 --- a/frontend/src/basic/RobotPage/index.tsx +++ b/frontend/src/basic/RobotPage/index.tsx @@ -2,7 +2,7 @@ import React, { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { Button, - CircularProgress, + Paper, Grid, IconButton, TextField, @@ -21,12 +21,14 @@ import { genKey } from '../../pgp'; import { sha256 } from 'js-sha256'; import { Casino, Download, ContentCopy, SmartToy, Bolt } from '@mui/icons-material'; import RobotAvatar from '../../components/RobotAvatar'; +import Onboarding from './Onboarding'; interface RobotPageProps { setPage: (state: Page) => void; setCurrentOrder: (state: number) => void; robot: Robot; setRobot: (state: Robot) => void; + windowSize: { width: number; height: number }; fetchRobot: ({}) => void; baseUrl: string; } @@ -34,6 +36,7 @@ interface RobotPageProps { const RobotPage = ({ setPage, setCurrentOrder, + windowSize, robot, setRobot, fetchRobot, @@ -43,9 +46,10 @@ const RobotPage = ({ const params = useParams(); const theme = useTheme(); const refCode = params.refCode; + const maxHeight = windowSize.height * 0.85 - 3; const [robotFound, setRobotFound] = useState(false); - const [badRequest, setBadRequest] = useState(null); + const [badRequest, setBadRequest] = useState(undefined); const [tokenChanged, setTokenChanged] = useState(false); const [inputToken, setInputToken] = useState(''); @@ -144,217 +148,244 @@ const RobotPage = ({ const handleClickSubmitToken = () => {}; const handleClickNewRandomToken = () => {}; - const createJsonFile = () => { - return { - token: robot.token, - token_shannon_entropy: robot.shannonEntropy, - token_bit_entropy: robot.bitsEntropy, - public_key: robot.pub_key, - encrypted_private_key: robot.enc_priv_key, - }; - }; - return ( - - -
- - - {robot.avatarLoaded && robot.nickname ? ( -
- - - - {robot.nickname && systemClient.getCookie('sessionid') ? ( - - ) : ( - '' - )} - - - - - -
-
-
- ) : ( - - )} -
- {robotFound ? ( - - - {t('A robot avatar was found, welcome back!')} -
-
-
- ) : ( - <> - )} - - - { - if (e.key === 'Enter') { - handleClickSubmitToken(); - } - }} - InputProps={{ - startAdornment: ( -
- - - - - saveAsJson(robot.nickname + '.json', createJsonFile())} - > - - - - - - - - - systemClient.copyToClipboard(systemClient.getItem('robot_token')) & - setRobot({ ...robot, copiedToken: true }) - } - > - - - - - -
- ), - endAdornment: ( - - - - - - ), - }} - /> -
-
- - {tokenChanged ? ( - - ) : ( - -
- -
-
- )} -
+ + {/* // Welcome to RoboSats + // Easy and private LN exchange - {/* - -
- -
- - - - - {t('Simple and Private LN P2P Exchange')} - - - - - - -
- */} + // I am a newbie + // Skip (fast robot gen) + // Recover existing token */} + + + + + + ); }; export default RobotPage; +// return ( +// +// {/* +//
+// +// +// {robot.avatarLoaded && robot.nickname ? ( +//
+// +// +// +// {robot.nickname && systemClient.getCookie('sessionid') ? ( +//
+// +// {robot.nickname} +// +//
+// ) : ( +// '' +// )} +//
+//
+//
+// +// +//
+//
+//
+// ) : ( +// +// )} +//
+// {robotFound ? ( +// +// +// {t('A robot avatar was found, welcome back!')} +//
+//
+//
+// ) : ( +// <> +// )} +// +// +// { +// if (e.key === 'Enter') { +// handleClickSubmitToken(); +// } +// }} +// InputProps={{ +// startAdornment: ( +//
+// +// +// +// +// saveAsJson(robot.nickname + '.json', createJsonFile())} +// > +// +// +// +// +// +// +// +// +// systemClient.copyToClipboard(systemClient.getItem('robot_token')) & +// setRobot({ ...robot, copiedToken: true }) +// } +// > +// +// +// +// +// +//
+// ), +// endAdornment: ( +// +// +// +// +// +// ), +// }} +// /> +//
+//
+// +// {tokenChanged ? ( +// +// ) : ( +// +//
+// +//
+//
+// )} +//
+ +// {/* +// +//
+// +//
+// +// +// +// +// {t('Simple and Private LN P2P Exchange')} +// +// +// +// +// +// +//
+// */} +// +// ); +// }; + +// export default RobotPage; */} + // class UserGenPage extends Component { // handleClickNewRandomToken = () => {