From a5b63aed93e084fae19d9e444e06238a52f24f3a Mon Sep 17 00:00:00 2001 From: Reckless_Satoshi Date: Sun, 30 Oct 2022 10:46:05 -0700 Subject: [PATCH] Small fixes --- api/views.py | 26 +++++----- frontend/src/basic/Main.tsx | 7 +-- frontend/src/basic/NavBar/NavBar.tsx | 8 ++-- frontend/src/basic/SettingsPage/index.tsx | 6 ++- frontend/src/basic/UserGenPage.js | 5 +- frontend/src/components/Dialogs/Profile.tsx | 7 ++- .../src/components/SettingsForm/index.tsx | 47 +++++++++++-------- frontend/static/css/index.css | 23 ++++++++- 8 files changed, 83 insertions(+), 46 deletions(-) diff --git a/api/views.py b/api/views.py index 034aff50..5f214d82 100644 --- a/api/views.py +++ b/api/views.py @@ -632,20 +632,22 @@ class UserView(APIView): context = {"bad_request": "Invalid serializer"} return Response(context, status=status.HTTP_400_BAD_REQUEST) + # Deprecated + # # If an existing user opens the main page by mistake, we do not want it to create a new nickname/profile for him - if request.user.is_authenticated: - context = {"nickname": request.user.username} - not_participant, _, order = Logics.validate_already_maker_or_taker( - request.user - ) + # if request.user.is_authenticated: + # context = {"nickname": request.user.username} + # not_participant, _, order = Logics.validate_already_maker_or_taker( + # request.user + # ) - # Does not allow this 'mistake' if an active order - if not not_participant: - context["active_order_id"] = order.id - context[ - "bad_request" - ] = f"You are already logged in as {request.user} and have an active order" - return Response(context, status.HTTP_400_BAD_REQUEST) + # # Does not allow this 'mistake' if an active order + # if not not_participant: + # context["active_order_id"] = order.id + # context[ + # "bad_request" + # ] = f"You are already logged in as {request.user} and have an active order" + # return Response(context, status.HTTP_400_BAD_REQUEST) # The new way. The token is never sent. Only its SHA256 token_sha256 = serializer.data.get("token_sha256") diff --git a/frontend/src/basic/Main.tsx b/frontend/src/basic/Main.tsx index 921e2116..2345095f 100644 --- a/frontend/src/basic/Main.tsx +++ b/frontend/src/basic/Main.tsx @@ -101,7 +101,6 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => { } fetchBook(); fetchLimits(); - fetchInfo(); return () => { if (typeof window !== undefined) { window.removeEventListener('resize', onResize); @@ -152,6 +151,10 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => { }); }; + useEffect(() => { + fetchInfo(); + }, [open.stats, open.coordinator]); + const fetchRobot = function () { const requestBody = { token_sha256: sha256(robot.token), @@ -194,8 +197,6 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => { } }, []); - console.log(page); - return ( {/* load robot avatar image, set avatarLoaded: true */} diff --git a/frontend/src/basic/NavBar/NavBar.tsx b/frontend/src/basic/NavBar/NavBar.tsx index 931fffd9..6a9c36ca 100644 --- a/frontend/src/basic/NavBar/NavBar.tsx +++ b/frontend/src/basic/NavBar/NavBar.tsx @@ -53,7 +53,7 @@ const NavBar = ({ const smallBar = width < 50; const tabSx = smallBar - ? { position: 'relative', bottom: nickname ? '0.8em' : '0em', minWidth: '1em' } + ? { position: 'relative', bottom: nickname ? '1em' : '0em', minWidth: '1em' } : { position: 'relative', bottom: '1em', minWidth: '2em' }; const pagesPosition = { robot: 1, @@ -103,12 +103,13 @@ const NavBar = ({ setOpen({ ...closeAll, profile: !open.profile })} icon={ nickname ? ( ) : ( @@ -160,7 +161,6 @@ const NavBar = ({ label={smallBar ? undefined : t('More')} value='none' onClick={(e) => { - console.log(e); open.more ? null : setOpen({ ...open, more: true }); }} icon={ diff --git a/frontend/src/basic/SettingsPage/index.tsx b/frontend/src/basic/SettingsPage/index.tsx index eebd4292..4a8ecf51 100644 --- a/frontend/src/basic/SettingsPage/index.tsx +++ b/frontend/src/basic/SettingsPage/index.tsx @@ -22,7 +22,11 @@ const SettingsPage = ({ settings, setSettings, windowSize }: SettingsPageProps): > - + diff --git a/frontend/src/basic/UserGenPage.js b/frontend/src/basic/UserGenPage.js index 0de1232b..65ded8e6 100644 --- a/frontend/src/basic/UserGenPage.js +++ b/frontend/src/basic/UserGenPage.js @@ -42,7 +42,10 @@ class UserGenPage extends Component { // Displays the existing one if (this.props.robot.nickname != null) { this.setState({ inputToken: this.props.robot.token }); - } else if (this.props.robot.token) { + } else if ( + this.props.robot.token || + (window.NativeRobosats && systemClient.getCookie('robot_token')) + ) { this.setState({ inputToken: this.props.robot.token }); this.getGeneratedUser(this.props.robot.token); } else { diff --git a/frontend/src/components/Dialogs/Profile.tsx b/frontend/src/components/Dialogs/Profile.tsx index 4cb4716d..2fef3e4a 100644 --- a/frontend/src/components/Dialogs/Profile.tsx +++ b/frontend/src/components/Dialogs/Profile.tsx @@ -4,7 +4,6 @@ import { useTheme } from '@mui/material/styles'; import { Link as LinkRouter } from 'react-router-dom'; import { - Avatar, Badge, Button, CircularProgress, @@ -102,10 +101,10 @@ const ProfileDialog = ({ open = false, onClose, robot, setRobot }: Props): JSX.E .post('/api/reward/', { invoice: rewardInvoice, }) - .then((data) => { - setBadInvoice(data.bad_invoice); + .then((data: any) => { + setBadInvoice(data.bad_invoice ?? ''); setShowRewardsSpinner(false); - setWithdrawn(!!data.successful_withdrawal); + setWithdrawn(data.successful_withdrawal); setOpenClaimRewards(!data.successful_withdrawal); setRobot({ ...robot, earnedRewards: data.successful_withdrawal ? 0 : robot.earnedRewards }); }); diff --git a/frontend/src/components/SettingsForm/index.tsx b/frontend/src/components/SettingsForm/index.tsx index c1af1cee..b7ed48da 100644 --- a/frontend/src/components/SettingsForm/index.tsx +++ b/frontend/src/components/SettingsForm/index.tsx @@ -29,9 +29,15 @@ interface SettingsFormProps { dense?: boolean; settings: Settings; setSettings: (state: Settings) => void; + network?: boolean; } -const SettingsForm = ({ dense = false, settings, setSettings }: SettingsFormProps): JSX.Element => { +const SettingsForm = ({ + dense = false, + settings, + setSettings, + network = false, +}: SettingsFormProps): JSX.Element => { const theme = useTheme(); const { t } = useTranslation(); const fontSizes = [ @@ -123,24 +129,27 @@ const SettingsForm = ({ dense = false, settings, setSettings }: SettingsFormProp track={false} /> - - - - - - setSettings({ ...settings, network: value })} - > - - {t('Mainnet')} - - - {t('Testnet')} - - - + {network ? ( + + + + + setSettings({ ...settings, network: value })} + > + + {t('Mainnet')} + + + {t('Testnet')} + + + + ) : ( + <> + )} diff --git a/frontend/static/css/index.css b/frontend/static/css/index.css index 12e953d5..3aca9168 100644 --- a/frontend/static/css/index.css +++ b/frontend/static/css/index.css @@ -117,14 +117,14 @@ input[type='number'] { filter: drop-shadow(0.5px 0.5px 0.5px #000000); } -.phoneFlippedSmallAvatar img { +.navBarAvatar img { transform: scaleX(-1); border: 1.3px solid #1976d2; -webkit-filter: grayscale(100%); filter: grayscale(100%) brightness(150%) contrast(150%) drop-shadow(0.7px 0.7px 0.7px #000000); } -.phoneFlippedSmallAvatar:after { +.navBarAvatar:after { content: ''; position: absolute; top: 0; @@ -136,6 +136,25 @@ input[type='number'] { box-shadow: inset 0px 0px 35px rgb(255, 255, 255); } +.navBarAvatarDark img { + transform: scaleX(-1); + border: 1.3px solid #90caf9; + -webkit-filter: grayscale(100%); + filter: grayscale(100%) brightness(100%) contrast(150%) drop-shadow(0.7px 0.7px 0.7px #000000); +} + +.navBarAvatarDark:after { + content: ''; + position: absolute; + top: 0; + left: 0; + bottom: 0; + right: 0; + border-radius: 50%; + border: 2.4px solid #90caf9; + box-shadow: inset 0px 0px 35px rgb(255, 255, 255); +} + .MuiButton-textInherit { color: '#111111'; }