From eac29c0b55c704a88ace236e5ad98af02f1cea34 Mon Sep 17 00:00:00 2001 From: Anton Lykhoyda Date: Mon, 9 Oct 2023 11:51:15 +0200 Subject: [PATCH] feat: Update network select (#385) Co-authored-by: Thibaut Sardan <33178835+Tbaut@users.noreply.github.com> --- packages/ui/src/components/ConnectOrWatch.tsx | 30 ++- .../ui/src/components/Drawer/DrawerMenu.tsx | 18 +- packages/ui/src/components/Header/Header.tsx | 16 +- packages/ui/src/components/library/Select.tsx | 56 ++--- packages/ui/src/components/modals/Send.tsx | 18 +- .../components/select/MultiProxySelection.tsx | 16 +- .../components/select/NetworkSelection.tsx | 195 ++++++++++++++++-- packages/ui/src/constants.ts | 14 ++ 8 files changed, 293 insertions(+), 70 deletions(-) diff --git a/packages/ui/src/components/ConnectOrWatch.tsx b/packages/ui/src/components/ConnectOrWatch.tsx index 1c755114..90605a8d 100644 --- a/packages/ui/src/components/ConnectOrWatch.tsx +++ b/packages/ui/src/components/ConnectOrWatch.tsx @@ -10,14 +10,16 @@ export const ConnectOrWatch = () => { return ( - No multisig found for your accounts or watched accounts.{' '} - {isAllowedToConnectToExtension ? ( - - ) : ( - - )} - or - +
No multisig found for your accounts or watched accounts.
+ + {isAllowedToConnectToExtension ? ( + + ) : ( + + )} + or + +
) } @@ -26,8 +28,16 @@ const ConnectButtonWrapperStyled = styled('div')` display: flex; justify-content: center; align-items: center; + flex-direction: column; +` + +const ButtonWrapperStyled = styled('div')` + display: flex; + align-items: center; + justify-content: center; + padding: 1rem 0; - & > button { - margin: 0 1rem; + button { + margin: 0 0.5rem; } ` diff --git a/packages/ui/src/components/Drawer/DrawerMenu.tsx b/packages/ui/src/components/Drawer/DrawerMenu.tsx index 668e50cf..99038a6c 100644 --- a/packages/ui/src/components/Drawer/DrawerMenu.tsx +++ b/packages/ui/src/components/Drawer/DrawerMenu.tsx @@ -28,7 +28,7 @@ function DrawerMenu({ handleDrawerClose }: DrawerMenuProps) { - + {!isAllowedToConnectToExtension && ( theme.breakpoints.values.md}px) { + justify-content: flex-end; + } + + a { + width: 100%; + text-align: center; + + @media (min-width: ${({ theme }) => theme.breakpoints.values.md}px) { + width: auto; + } + } ` const ButtonStyled = styled(Button)` diff --git a/packages/ui/src/components/Header/Header.tsx b/packages/ui/src/components/Header/Header.tsx index 56c3f535..ccaff8ce 100644 --- a/packages/ui/src/components/Header/Header.tsx +++ b/packages/ui/src/components/Header/Header.tsx @@ -97,20 +97,28 @@ const RightButtonsWrapperStyled = styled(Box)` display: flex; align-items: center; justify-content: flex-end; + flex: 1; ` const MenuWrapperStyled = styled(Box)` width: 100%; + display: flex; + align-items: center; ` const DesktopMenuStyled = styled(Box)` display: none; @media (min-width: ${({ theme }) => theme.breakpoints.values.md}px) { - flex-grow: 1; + width: 100%; + flex-grow: 0; display: flex; align-items: center; } + + @media (min-width: ${({ theme }) => theme.breakpoints.values.lg}px) { + flex-grow: 1; + } ` const LogoWrapperStyled = styled(Box)` @@ -119,8 +127,12 @@ const LogoWrapperStyled = styled(Box)` flex: 1; @media (min-width: ${({ theme }) => theme.breakpoints.values.md}px) { - margin-right: 1rem; flex: 0; + margin-right: 0.5rem; + } + + @media (min-width: ${({ theme }) => theme.breakpoints.values.lg}px) { + margin-right: 1rem; } ` diff --git a/packages/ui/src/components/library/Select.tsx b/packages/ui/src/components/library/Select.tsx index 3211096e..219c7bb8 100644 --- a/packages/ui/src/components/library/Select.tsx +++ b/packages/ui/src/components/library/Select.tsx @@ -15,11 +15,11 @@ import { theme } from '../../styles/theme' interface SelectProps { value: string menuItems?: { value: string; logo?: string }[] - onChange: (event: SelectChangeEvent) => void + onChange: (event: SelectChangeEvent) => void minified?: boolean inputSize?: 'medium' | 'large' fullWidth?: boolean - children?: React.ReactNode[] + children?: React.ReactNode[] | React.ReactNode sx?: SxProps } @@ -43,30 +43,8 @@ const Select = ({ value={value} fullWidth={fullWidth} IconComponent={HiOutlineChevronDown} - MenuProps={{ - sx: { - marginTop: '.75rem', - '.MuiPaper-root': { - boxShadow: 'none' - }, - - '.MuiList-root': { - padding: 0, - border: `1px solid ${theme.custom.text.borderColor}`, - borderRadius: '0.5rem' - }, - - '.MuiMenuItem-root': { - maxWidth: '100%', - padding: '0.75rem', - borderBottom: `1px solid ${theme.custom.text.borderColor}`, - '&:last-child': { - borderBottom: 'none' - } - } - } - }} - onChange={(event) => onChange(event as SelectChangeEvent)} + MenuProps={MenuPropsStyles} + onChange={onChange} > {menuItems ? menuItems.map(({ value, logo }) => ( @@ -81,7 +59,7 @@ const Select = ({ src={logo} /> )} - {{value}} + {value} )) : children} @@ -94,6 +72,30 @@ Select.defaultProps = { inputSize: 'medium' } +const MenuPropsStyles = { + sx: { + marginTop: '.75rem', + '.MuiPaper-root': { + boxShadow: 'none' + }, + + '.MuiList-root': { + padding: 0, + border: `1px solid ${theme.custom.text.borderColor}`, + borderRadius: '0.5rem' + }, + + '.MuiMenuItem-root': { + maxWidth: '100%', + padding: '0.75rem', + borderBottom: `1px solid ${theme.custom.text.borderColor}`, + '&:last-child': { + borderBottom: 'none' + } + } + } +} + const SelectMuiStyled = styled(SelectMui)< SelectMuiProps & { slotProps: { minifiedVersion: boolean; inputSize?: string } } >` diff --git a/packages/ui/src/components/modals/Send.tsx b/packages/ui/src/components/modals/Send.tsx index 4d3ef223..6a3bf7c5 100644 --- a/packages/ui/src/components/modals/Send.tsx +++ b/packages/ui/src/components/modals/Send.tsx @@ -218,11 +218,19 @@ const Send = ({ onClose, className, onSuccess, onFinalized }: Props) => { getSubscanExtrinsicLink ]) - const onChangeEasySetupOption = useCallback((event: SelectChangeEvent) => { - setErrorMessage('') - setEasyOptionErrorMessage('') - setSelectedEasyOption(event.target.value) - }, []) + const onChangeEasySetupOption = useCallback( + ({ target: { value } }: SelectChangeEvent) => { + if (typeof value !== 'string') { + console.error('Unexpected network value, expect string but received', value) + return + } + + setErrorMessage('') + setEasyOptionErrorMessage('') + setSelectedEasyOption(value) + }, + [] + ) if (!possibleOrigin) { return null diff --git a/packages/ui/src/components/select/MultiProxySelection.tsx b/packages/ui/src/components/select/MultiProxySelection.tsx index 1cccdd79..65631fef 100644 --- a/packages/ui/src/components/select/MultiProxySelection.tsx +++ b/packages/ui/src/components/select/MultiProxySelection.tsx @@ -155,16 +155,18 @@ const BoxStyled = styled(Box)` ` export default styled(MultiProxySelection)` - min-width: 200px; - - @media (min-width: ${(props) => props.theme.breakpoints.values.md}px) { - min-width: 260px; - } - + min-width: 12.5rem; text-align: right; + width: 100%; .MuiTextField-root { - max-width: 18.875rem; + @media (min-width: ${(props) => props.theme.breakpoints.values.md}px) { + min-width: 13.6875rem; + } + + @media (min-width: ${(props) => props.theme.breakpoints.values.lg}px) { + min-width: 18.6875rem; + } } .MuiAutocomplete-endAdornment { diff --git a/packages/ui/src/components/select/NetworkSelection.tsx b/packages/ui/src/components/select/NetworkSelection.tsx index 628e9f8b..2a7ce9a5 100644 --- a/packages/ui/src/components/select/NetworkSelection.tsx +++ b/packages/ui/src/components/select/NetworkSelection.tsx @@ -1,8 +1,15 @@ -import { SelectChangeEvent } from '@mui/material' +import React, { useCallback, useMemo } from 'react' +import { ListSubheader, MenuItem, Select as SelectMui, SelectChangeEvent } from '@mui/material' +import { styled } from '@mui/material/styles' +import { HiOutlineChevronDown } from 'react-icons/hi2' import { useNetwork } from '../../contexts/NetworkContext' -import { useCallback, useMemo } from 'react' -import { networkList } from '../../constants' -import { Select } from '../library' +import { + kusamaNetworksAndParachains, + networkList, + polkadotNetworksAndParachains, + testChains +} from '../../constants' +import { theme } from '../../styles/theme' const NetworkSelection = () => { const { selectedNetwork, selectNetwork } = useNetwork() @@ -14,31 +21,185 @@ const NetworkSelection = () => { }, []) const handleNetworkSelection = useCallback( - (event: SelectChangeEvent) => { - selectNetwork(event.target.value) + ({ target: { value } }: SelectChangeEvent) => { + if (typeof value !== 'string') { + console.error('Unexpected network value, expect string but received', value) + return + } + + selectNetwork(value) }, [selectNetwork] ) + const renderNetworks = useCallback( + (allowedNetworks: string[]) => + networksToShow + .filter(([networkName]) => allowedNetworks.includes(networkName)) + .map(([networkName, { logo }]) => ( + + + {networkName} + + )), + [networksToShow] + ) + if (!selectedNetwork) { return null } return ( -