Skip to content

Commit

Permalink
Refactor: rename and rearrange components (#2676)
Browse files Browse the repository at this point in the history
* Refactor: rename and rearrange components

* Move useWcUri

* Show/hide popup on session change

* Remove auto-pasting
  • Loading branch information
katspaugh authored Oct 23, 2023
1 parent e77fa3f commit 2028dff
Show file tree
Hide file tree
Showing 36 changed files with 425 additions and 429 deletions.
4 changes: 2 additions & 2 deletions src/components/common/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import SafeLogo from '@/public/images/logo.svg'
import Link from 'next/link'
import useSafeAddress from '@/hooks/useSafeAddress'
import BatchIndicator from '@/components/batch/BatchIndicator'
import WalletConnectHeaderWidget from '@/components/walletconnect/HeaderWidget'
import WalletConnectUi from '@/components/walletconnect'
import { PushNotificationsBanner } from '@/components/settings/PushNotifications/PushNotificationsBanner'

type HeaderProps = {
Expand Down Expand Up @@ -79,7 +79,7 @@ const Header = ({ onMenuToggle, onBatchToggle }: HeaderProps): ReactElement => {
</div>

<div className={classnames(css.element, css.hideMobile)}>
<WalletConnectHeaderWidget />
<WalletConnectUi />
</div>

<div className={classnames(css.element, css.connectWallet)}>
Expand Down
File renamed without changes.
38 changes: 0 additions & 38 deletions src/components/walletconnect/HeaderWidget/Icon.tsx

This file was deleted.

107 changes: 0 additions & 107 deletions src/components/walletconnect/HeaderWidget/index.tsx

This file was deleted.

11 changes: 0 additions & 11 deletions src/components/walletconnect/ProposalForm/bridges.ts

This file was deleted.

76 changes: 0 additions & 76 deletions src/components/walletconnect/SessionManager/index.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import useLocalStorage from '@/services/local-storage/useLocalStorage'
import { useCallback, useEffect } from 'react'
import { Grid, Typography, Divider, SvgIcon, IconButton, Tooltip } from '@mui/material'
import { useCallback, useContext, useEffect } from 'react'
import type { ReactElement } from 'react'
import type { SessionTypes } from '@walletconnect/types'

import { Hints } from '../Hints'
import SessionList from '../SessionList'
import WcInput from '../WcInput'
import useLocalStorage from '@/services/local-storage/useLocalStorage'
import InfoIcon from '@/public/images/notifications/info.svg'
import { WalletConnectHeader } from '../SessionManager/Header'
import { WalletConnectContext } from '@/services/walletconnect/WalletConnectContext'

import WcHints from '../WcHints'
import WcSessionList from '../WcSessionList'
import WcInput from '../WcInput'
import WcLogoHeader from '../WcLogoHeader'
import css from './styles.module.css'
import useSafeAddress from '@/hooks/useSafeAddress'

const WC_HINTS_KEY = 'wcHints'

export const ConnectionForm = ({
export const WcConnectionForm = ({
sessions,
onDisconnect,
uri,
Expand All @@ -24,24 +22,16 @@ export const ConnectionForm = ({
onDisconnect: (session: SessionTypes.Struct) => Promise<void>
uri: string
}): ReactElement => {
const { walletConnect } = useContext(WalletConnectContext)
const [showHints = false, setShowHints] = useLocalStorage<boolean>(WC_HINTS_KEY)
const [showHints = true, setShowHints] = useLocalStorage<boolean>(WC_HINTS_KEY)
const safeAddress = useSafeAddress()

const onToggle = () => {
const onToggle = useCallback(() => {
setShowHints((prev) => !prev)
}

const onHide = useCallback(() => {
setShowHints(false)
}, [setShowHints])

useEffect(() => {
if (!walletConnect) {
return
}

return walletConnect.onSessionPropose(onHide)
}, [onHide, walletConnect])
return () => setShowHints(false)
}, [setShowHints])

return (
<Grid className={css.container}>
Expand All @@ -59,30 +49,32 @@ export const ConnectionForm = ({
</span>
</Tooltip>

<WalletConnectHeader />
<WcLogoHeader />

<Typography variant="body2" color="text.secondary" mb={3}>
Paste the pairing code below to connect to your {`Safe{Wallet}`} via WalletConnect
</Typography>

<WcInput uri={uri} />
<WcInput uri={uri} disabled={!safeAddress} />
</Grid>

<Divider flexItem className={css.divider} />

<Grid item>
<SessionList sessions={sessions} onDisconnect={onDisconnect} />
<WcSessionList sessions={sessions} onDisconnect={onDisconnect} />
</Grid>

{showHints && (
<>
<Divider flexItem className={css.divider} />

<Grid item mt={1}>
<Hints />
<WcHints />
</Grid>
</>
)}
</Grid>
)
}

export default WcConnectionForm
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import { useCurrentChain } from '@/hooks/useChains'

import css from './styles.module.css'

export const ConnectionBanner = ({
const WcConnectionState = ({
metadata,
isDelete = false,
isDelete,
}: {
metadata?: CoreTypes.Metadata
isDelete?: boolean
metadata: CoreTypes.Metadata
isDelete: boolean
}): ReactElement | null => {
const chain = useCurrentChain()

Expand Down Expand Up @@ -46,3 +46,5 @@ export const ConnectionBanner = ({
</div>
)
}

export default WcConnectionState
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { Typography } from '@mui/material'
import type { ReactElement } from 'react'

import { WalletConnectHeader } from './Header'

import WcLogoHeader from '../WcLogoHeader'
import css from './styles.module.css'

export const WalletConnectErrorMessage = ({ error }: { error: Error }): ReactElement => {
const WcErrorMessage = ({ error }: { error: Error }) => {
return (
<div className={css.errorContainer}>
<WalletConnectHeader error />
<WcLogoHeader error />

<Typography title={error.message} className={css.errorMessage}>
{error.message}
</Typography>
</div>
)
}

export default WcErrorMessage
Loading

0 comments on commit 2028dff

Please sign in to comment.