Skip to content

Commit

Permalink
update after review
Browse files Browse the repository at this point in the history
  • Loading branch information
Lykhoyda committed Sep 22, 2023
1 parent 76da7dc commit d13b7b5
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Alert, CircularProgress, Grid, styled } from '@mui/material'
import { Button, TextFieldStyled } from '../library'
import { useCallback, useMemo, useState } from 'react'
import React, { useCallback, useMemo, useState } from 'react'
import { useWalletConnect } from '../../contexts/WalletConnectContext'
import { useMultiProxy } from '../../contexts/MultiProxyContext'

Expand Down
8 changes: 6 additions & 2 deletions packages/ui/src/components/select/AccountSelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ interface Props {
addAccount?: (address: string) => void
value?: string
label?: string
actionButtonLabel?: string
actionButtonVariant?: 'primary' | 'secondary'
currentSelection?: string[]
withName?: boolean
withAddButton?: boolean
Expand All @@ -31,6 +33,8 @@ const AccountSelection = ({
nameDisabled = false,
value,
label = 'Address',
actionButtonLabel = 'Add',
actionButtonVariant = 'secondary',
currentSelection = [],
withName = false,
withAddButton = false,
Expand Down Expand Up @@ -179,11 +183,11 @@ const AccountSelection = ({
{withAddButton && (
<ButtonStyled
onClick={onAdd}
variant="primary"
variant={actionButtonVariant}
disabled={!selected || !!errorMessage}
data-cy="button-add-watched-account"
>
Watch
{actionButtonLabel}
</ButtonStyled>
)}
</BoxStyled>
Expand Down
32 changes: 20 additions & 12 deletions packages/ui/src/pages/Settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,32 @@ import { WalletConnectSession } from '../../components/WalletConnect/WalletConne
import { WalletConnectActiveSessions } from '../../components/WalletConnect/WalletConnectActiveSessions'
import { HiOutlineChevronDown as ExpandMoreIcon, HiOutlineEye } from 'react-icons/hi2'
import { theme } from '../../styles/theme'
import { SyntheticEvent, useEffect, useState } from 'react'
import { SyntheticEvent, useCallback, useEffect, useState } from 'react'
import { useLocation } from 'react-router-dom'

const ACCORDION_WATCHED_ACCOUNTS = 'panel-watched-accounts'
const ACCORDION_WALLET_CONNECT = 'panel-wallet-connect'

type AccordionNames = typeof ACCORDION_WATCHED_ACCOUNTS | typeof ACCORDION_WALLET_CONNECT

const Settings = () => {
const location = useLocation()
const [expanded, setExpanded] = useState<string | false>(false)
const handleChange = (panel: string) => (event: SyntheticEvent | null, isExpanded: boolean) => {
console.log('handleChange', panel)
setExpanded(isExpanded ? panel : false)
}
const { hash } = useLocation()
const [expanded, setExpanded] = useState<AccordionNames | false>(false)

const handleChange = useCallback(
(panel: AccordionNames) => (_event: SyntheticEvent | null, isExpanded: boolean) => {
setExpanded(isExpanded ? panel : false)
},
[]
)

useEffect(() => {
if (location.hash === '#watched-acccounts') {
if (hash === '#watched-acccounts') {
handleChange('panel-watched-accounts')(null, true)
} else if (location.hash === '#wallet-connect') {
} else if (hash === '#wallet-connect') {
handleChange('panel-wallet-connect')(null, true)
}
}, [location.hash])
}, [handleChange, hash])

return (
<>
Expand Down Expand Up @@ -66,11 +74,11 @@ const SettingsHeaderStyled = styled('h1')`
const AccordionStyled = styled(Accordion)`
max-width: 42.5625rem;
box-shadow: none;
border-bottom: 1px solid #e5e5e5;
border-bottom: 1px solid ${({ theme }) => theme.custom.neutral[200]};
&.Mui-expanded {
margin: 0;
background: #fafafa;
background: ${({ theme }) => theme.custom.neutral[50]};
.MuiAccordionSummary-root {
margin: 0;
Expand Down
25 changes: 10 additions & 15 deletions packages/ui/src/pages/Settings/WatchedAccounts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,34 @@ import { useWatchedAddresses } from '../../contexts/WatchedAddressesContext'
import AccountDisplay from '../../components/AccountDisplay'
import { HiOutlineXMark } from 'react-icons/hi2'
import AccountSelection from '../../components/select/AccountSelection'
import { useCallback } from 'react'

interface Props {
className?: string
}

const WatchedAccounts = ({ className }: Props) => {
const WatchedAccounts = () => {
const { watchedAddresses, removeWatchedAccount, addWatchedAccount } = useWatchedAddresses()
const hasWatchedAddresses = useCallback(() => watchedAddresses.length > 0, [watchedAddresses])

return (
<>
<WatchAccountsHeaderStyled>Currently watched accounts:</WatchAccountsHeaderStyled>
{hasWatchedAddresses() && (
<WatchAccountsHeaderStyled>Currently watched accounts:</WatchAccountsHeaderStyled>
)}
<Grid
className={className}
container
spacing={2}
>
{watchedAddresses.length > 0 && (
{hasWatchedAddresses() && (
<Grid
item
xs={12}
md={8}
>
<PaperStyled>
{watchedAddresses.map((address, index) => {
{watchedAddresses.map((address) => {
return (
<AccountItemWrapperStyled
key={address}
data-cy="container-account-details"
>
<AccountCountStyled>{index + 1}</AccountCountStyled>
<AccountDisplayStyled address={address} />
<IconButtonDeleteStyled
aria-label="delete"
Expand All @@ -53,12 +51,13 @@ const WatchedAccounts = ({ className }: Props) => {
xs={12}
md={8}
>
<WatchAccountsHeaderStyled>Watch an account</WatchAccountsHeaderStyled>
<AccountSelectionWrapperStyled>
<AccountSelection
className="accountDropdown"
currentSelection={watchedAddresses}
addAccount={addWatchedAccount}
actionButtonLabel="Watch"
actionButtonVariant="primary"
withName
withAddButton
withPreselection={false}
Expand Down Expand Up @@ -95,10 +94,6 @@ const IconButtonDeleteStyled = styled(IconButton)`
align-self: center;
`

const AccountCountStyled = styled(Box)`
margin-right: 1rem;
`

const AccountDisplayStyled = styled(AccountDisplay)`
flex: 1;
`
Expand Down
12 changes: 12 additions & 0 deletions packages/ui/src/styles/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ declare module '@mui/material/styles' {
800: string
900: string
}
neutral: {
50: string
200: string
}
button: {
primaryDisabledColor: string
primaryDisabledBackground: string
Expand Down Expand Up @@ -79,6 +83,10 @@ declare module '@mui/material/styles' {
800: string
900: string
}
neutral: {
50: string
200: string
}
button: {
primaryDisabledColor: string
primaryDisabledBackground: string
Expand Down Expand Up @@ -140,6 +148,10 @@ export const theme = createTheme({
800: '#485568',
900: '#020617'
},
neutral: {
50: '#FAFAFA',
200: '#e5e5e5'
},
button: {
primaryDisabledColor: '#A8B3DC',
primaryDisabledBackground: '#E3E9FF',
Expand Down

0 comments on commit d13b7b5

Please sign in to comment.