Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
katspaugh committed Oct 19, 2023
1 parent 920981b commit 87cec80
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 36 deletions.
71 changes: 41 additions & 30 deletions src/components/dashboard/FeaturedApps/FeaturedApps.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ReactElement, useContext } from 'react'
import type { ReactElement } from 'react'
import { useContext } from 'react'
import { Box, Grid, Typography, Link } from '@mui/material'
import type { SafeAppInfo } from '@safe-global/safe-gateway-typescript-sdk'
import type { SafeAppData } from '@safe-global/safe-gateway-typescript-sdk'
import { Card, WidgetBody, WidgetContainer } from '../styled'
import { useRouter } from 'next/router'
import NextLink from 'next/link'
Expand All @@ -10,20 +11,41 @@ import { useRemoteSafeApps } from '@/hooks/safe-apps/useRemoteSafeApps'
import SafeAppIconCard from '@/components/safe-apps/SafeAppIconCard'
import { WalletConnectContext } from '@/services/walletconnect/WalletConnectContext'

const isWalletConnectSafeApp = (app: SafeAppData): boolean => {
return WALLET_CONNECT.test(app.url)
}

const WALLET_CONNECT = /wallet-connect/

const FeaturedAppCard = ({ app }: { app: SafeAppData }) => (
<Card>
<Grid container alignItems="center" spacing={3}>
<Grid item xs={12} md={3}>
<SafeAppIconCard src={app.iconUrl} alt={app.name} width={64} height={64} />
</Grid>

<Grid item xs={12} md={9}>
<Box mb={1.01}>
<Typography fontSize="lg">{app.description}</Typography>
</Box>

<Link color="primary.main" fontWeight="bold" component="span">
Use {app.name}
</Link>
</Grid>
</Grid>
</Card>
)

export const FeaturedApps = ({ stackedLayout }: { stackedLayout: boolean }): ReactElement | null => {
const router = useRouter()
const [featuredApps, _, remoteSafeAppsLoading] = useRemoteSafeApps(SafeAppsTag.DASHBOARD_FEATURED)
const { setOpen } = useContext(WalletConnectContext)

if (!featuredApps?.length && !remoteSafeAppsLoading) return null

const onWidgetClick = (e: Event, app: SafeAppInfo) => {
if (WALLET_CONNECT.test(app.url)) {
e.preventDefault()
setOpen(true)
}
const onWcWidgetClick = () => {
setOpen(true)
}

return (
Expand All @@ -41,29 +63,18 @@ export const FeaturedApps = ({ stackedLayout }: { stackedLayout: boolean }): Rea
>
{featuredApps?.map((app) => (
<Grid item xs md key={app.id}>
<NextLink
passHref
href={{ pathname: AppRoutes.apps.open, query: { ...router.query, appUrl: app.url } }}
onClick={(e) => onWidgetClick(e, app)}
>
<Card>
<Grid container alignItems="center" spacing={3}>
<Grid item xs={12} md={3}>
<SafeAppIconCard src={app.iconUrl} alt={app.name} width={64} height={64} />
</Grid>

<Grid item xs={12} md={9}>
<Box mb={1.01}>
<Typography fontSize="lg">{app.description}</Typography>
</Box>

<Link color="primary.main" fontWeight="bold" component="span">
Use {app.name}
</Link>
</Grid>
</Grid>
</Card>
</NextLink>
{isWalletConnectSafeApp(app) ? (
<a onClick={onWcWidgetClick} style={{ cursor: 'pointer' }}>
<FeaturedAppCard app={app} />
</a>
) : (
<NextLink
passHref
href={{ pathname: AppRoutes.apps.open, query: { ...router.query, appUrl: app.url } }}
>
<FeaturedAppCard app={app} />
</NextLink>
)}
</Grid>
))}
</Grid>
Expand Down
8 changes: 5 additions & 3 deletions src/components/walletconnect/HeaderWidget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ const WalletConnectHeaderWidget = (): ReactElement => {
const [uri, clearUri] = usePrepopulatedUri()
const [metadata, setMetadata] = useState<CoreTypes.Metadata>()

const onOpenSessionManager = useCallback(() => setOpen(true), [])
const onOpenSessionManager = useCallback(() => setOpen(true), [setOpen])

const onCloseSessionManager = useCallback(() => {
setOpen(false)
clearUri()
}, [clearUri])
}, [setOpen, clearUri])

const onCloseSuccesBanner = useCallback(() => setMetadata(undefined), [])

const onSuccess = useCallback(
({ peer }: SessionTypes.Struct) => {
onCloseSessionManager()
Expand Down Expand Up @@ -72,7 +74,7 @@ const WalletConnectHeaderWidget = (): ReactElement => {
// Open the popup when a prepopulated uri is found
useEffect(() => {
if (uri) setOpen(true)
}, [uri])
}, [uri, setOpen])

return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ describe('useWalletConnectSessions', () => {
} as unknown as WalletConnectWallet

const wrapper = ({ children }: any) => (
<WalletConnectContext.Provider value={{ walletConnect: mockWalletConnect, error: null }}>
<WalletConnectContext.Provider
value={{ walletConnect: mockWalletConnect, error: null, open: false, setOpen: () => {} }}
>
{children}
</WalletConnectContext.Provider>
)
Expand All @@ -49,7 +51,9 @@ describe('useWalletConnectSessions', () => {
} as unknown as WalletConnectWallet

const wrapper = ({ children }: any) => (
<WalletConnectContext.Provider value={{ walletConnect: mockWalletConnect, error: null }}>
<WalletConnectContext.Provider
value={{ walletConnect: mockWalletConnect, error: null, open: false, setOpen: () => {} }}
>
{children}
</WalletConnectContext.Provider>
)
Expand Down Expand Up @@ -97,7 +101,9 @@ describe('useWalletConnectSessions', () => {
} as unknown as WalletConnectWallet

const wrapper = ({ children }: any) => (
<WalletConnectContext.Provider value={{ walletConnect: mockWalletConnect, error: null }}>
<WalletConnectContext.Provider
value={{ walletConnect: mockWalletConnect, error: null, open: false, setOpen: () => {} }}
>
{children}
</WalletConnectContext.Provider>
)
Expand Down

0 comments on commit 87cec80

Please sign in to comment.