Skip to content

Commit

Permalink
Add accordion to settings page (#361)
Browse files Browse the repository at this point in the history
Co-authored-by: Thibaut Sardan <[email protected]>
Co-authored-by: Thibaut Sardan <[email protected]>
  • Loading branch information
3 people authored Sep 25, 2023
1 parent d724757 commit a0df30e
Show file tree
Hide file tree
Showing 15 changed files with 355 additions and 211 deletions.
2 changes: 2 additions & 0 deletions packages/ui/cypress/fixtures/landingData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ export const baseUrl = 'http://localhost:3333'
export const networkParams = 'network=rococo'
export const landingPageUrl = `${baseUrl}?${networkParams}`
export const settingsPageUrl = `${baseUrl}/settings?${networkParams}`
const WATCH_ACCOUNT_ANCHOR = '#watched-accounts'
export const settingsPageWatchAccountUrl = `${settingsPageUrl}${WATCH_ACCOUNT_ANCHOR}`
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { addresses } from '../../fixtures/accounts'
import { landingPageUrl, settingsPageUrl } from '../../fixtures/landingData'
import { landingPageUrl, settingsPageWatchAccountUrl } from '../../fixtures/landingData'
import { landingPage } from '../../support/page-objects/landingPage'
import { settingsPage } from '../../support/page-objects/settingsPage'

Expand Down Expand Up @@ -28,7 +28,7 @@ describe('Watched Accounts', () => {

it('can remove an account from the watch list', () => {
// add an account first
cy.visit(settingsPageUrl)
cy.visit(settingsPageWatchAccountUrl)
addWatchAccount(addresses.Alice, 'Alice')
// now remove it
settingsPage.accountContainer().within(() => {
Expand All @@ -41,7 +41,7 @@ describe('Watched Accounts', () => {

it('can see error when attemping to add same address more than once', () => {
// add an account first
cy.visit(settingsPageUrl)
cy.visit(settingsPageWatchAccountUrl)
addWatchAccount(addresses.Alice, 'Alice')
settingsPage.accountContainer().should('have.length', 1)
// attempt to add the same account again
Expand All @@ -52,7 +52,7 @@ describe('Watched Accounts', () => {
})

it('can see error when attempting to add an invalid address', () => {
cy.visit(settingsPageUrl)
cy.visit(settingsPageWatchAccountUrl)
addWatchAccount('123')
settingsPage.errorLabel().should('be.visible').should('have.text', 'Invalid address')
settingsPage.accountContainer().should('have.length', 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,48 +32,46 @@ export const WalletConnectActiveSessions = () => {

return (
<WrapperBox>
<>
Active sessions:
{activeSessions.map((session) => {
const { name, url } = session.peer.metadata
const expiryDate = new Date(session.expiry * 1000)

const content = (
<ContentBoxStyled>
<div className="info">
<ul>
<li>Namespace: {session.requiredNamespaces.polkadot.chains?.join(', ')}</li>
<li>Methods: {session.requiredNamespaces.polkadot.methods?.join(', ')}</li>
<li>Expiring: {expiryDate.toDateString()}</li>
</ul>
</div>
<div className="buttonWrapper">
<Button
variant="primary"
onClick={() => onDeleteSession(session.topic)}
disabled={isLoading}
>
{isLoading ? <CircularProgress size={24} /> : 'Delete session'}
</Button>
</div>
</ContentBoxStyled>
)

return (
<ExpanderStyled
key={session.topic}
expanded={false}
title={
<TitleBoxStyled>
<div className="name">{name}</div>
<div className="url">{url}</div>
</TitleBoxStyled>
}
content={content}
/>
)
})}
</>
Active sessions:
{activeSessions.map((session) => {
const { name, url } = session.peer.metadata
const expiryDate = new Date(session.expiry * 1000)

const content = (
<ContentBoxStyled>
<div className="info">
<ul>
<li>Namespace: {session.requiredNamespaces.polkadot.chains?.join(', ')}</li>
<li>Methods: {session.requiredNamespaces.polkadot.methods?.join(', ')}</li>
<li>Expiring: {expiryDate.toDateString()}</li>
</ul>
</div>
<div className="buttonWrapper">
<Button
variant="primary"
onClick={() => onDeleteSession(session.topic)}
disabled={isLoading}
>
{isLoading ? <CircularProgress size={24} /> : 'Delete session'}
</Button>
</div>
</ContentBoxStyled>
)

return (
<ExpanderStyled
key={session.topic}
expanded={false}
title={
<TitleBoxStyled>
<div className="name">{name}</div>
<div className="url">{url}</div>
</TitleBoxStyled>
}
content={content}
/>
)
})}
</WrapperBox>
)
}
Expand Down
45 changes: 23 additions & 22 deletions packages/ui/src/components/WalletConnect/WalletConnectSession.tsx
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 { Button, InputField } from '../library'
import { useCallback, useMemo, useState, ChangeEvent } from 'react'
import { useWalletConnect } from '../../contexts/WalletConnectContext'
import { useMultiProxy } from '../../contexts/MultiProxyContext'

Expand All @@ -25,7 +25,7 @@ export const WalletConnectSession = () => {
}
}, [pair, uri])

const onUriChange = useCallback((event: React.ChangeEvent<HTMLInputElement>) => {
const onUriChange = useCallback((event: ChangeEvent<HTMLInputElement>) => {
setUri(event.target.value.trim())
}, [])

Expand All @@ -36,9 +36,6 @@ export const WalletConnectSession = () => {
>
<Grid
item
xs={12}
sm={12}
md={12}
alignItems="center"
>
{!canUseWalletConnect && (
Expand All @@ -52,24 +49,28 @@ export const WalletConnectSession = () => {
)}
</Grid>
<Grid
item
xs={12}
sm={12}
md={12}
alignItems="center"
md={8}
item
>
<TextFieldStyled
onChange={onUriChange}
value={uri}
placeholder="WalletConnect key..."
disabled={!canUseWalletConnect}
/>
<ButtonStyled
disabled={!uri || !canUseWalletConnect}
onClick={onConnect}
<Grid
container
direction="column"
>
{loading ? <CircularProgress size={25} /> : 'Connect Dapp'}
</ButtonStyled>
<InputField
label="WalletConnect key"
onChange={onUriChange}
value={uri}
disabled={!canUseWalletConnect}
/>
<ButtonStyled
variant="primary"
disabled={!uri || !canUseWalletConnect}
onClick={onConnect}
>
{loading ? <CircularProgress size={24} /> : 'Connect Dapp'}
</ButtonStyled>
</Grid>
</Grid>
</Grid>
)
Expand All @@ -81,5 +82,5 @@ const AlertStyled = styled(Alert)`
`

const ButtonStyled = styled(Button)`
margin-left: 1rem;
margin-top: 0.5rem;
`
109 changes: 0 additions & 109 deletions packages/ui/src/components/WatchedAccounts.tsx

This file was deleted.

3 changes: 2 additions & 1 deletion packages/ui/src/components/library/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
}

export const Button = styled('button')<ButtonProps>`
display: inline-flex;
display: inline-block;
padding: 0.5rem 1rem;
font-size: 1rem;
height: 100%;
Expand All @@ -21,6 +21,7 @@ export const Button = styled('button')<ButtonProps>`
box-shadow: ${({ theme }) => theme.custom.boxShadow};
transition: background 0.2s ease-in-out;
white-space: nowrap;
text-align: center;
&:disabled {
cursor: not-allowed;
Expand Down
9 changes: 7 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="secondary"
variant={actionButtonVariant}
disabled={!selected || !!errorMessage}
data-cy="button-add-watched-account"
>
Add
{actionButtonLabel}
</ButtonStyled>
)}
</BoxStyled>
Expand All @@ -203,6 +207,7 @@ const BoxStyled = styled(Box)`
const ButtonStyled = styled(Button)`
margin-left: 1rem;
align-self: end;
text-align: center;
`

export default styled(AccountSelection)`
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/src/contexts/WalletConnectContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface IWalletConnectContext {
web3wallet: IWeb3Wallet | undefined
core: ICore
pair: (params: { uri: string }) => Promise<PairingTypes.Struct>
refresh: () => void
refresh: () => Promise<void>
}

const WalletConnectContext = createContext<IWalletConnectContext | undefined>(undefined)
Expand Down Expand Up @@ -58,7 +58,7 @@ const WalletConnectContextProvider = ({ children }: WalletConnectContextProps) =
)

const refresh = useCallback(() => {
createWeb3Wallet()
return createWeb3Wallet()
}, [createWeb3Wallet])

useEffect(() => {
Expand Down
5 changes: 5 additions & 0 deletions packages/ui/src/logos/walletConnectSVG.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit a0df30e

Please sign in to comment.