Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Open custom safe apps on click #2350

Merged
merged 1 commit into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions src/components/safe-apps/SafeAppCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import SafeAppTags from '@/components/safe-apps/SafeAppTags'
import { isOptimizedForBatchTransactions } from '@/components/safe-apps/utils'
import { AppRoutes } from '@/config/routes'
import BatchIcon from '@/public/images/apps/batch-icon.svg'
import { useOpenedSafeApps } from '@/hooks/safe-apps/useOpenedSafeApps'
import css from './styles.module.css'

export type SafeAppsViewMode = 'list-view' | 'grid-view'
Expand Down Expand Up @@ -111,7 +110,7 @@ const SafeAppCardGridView = ({
openPreviewDrawer,
}: SafeAppCardViewProps) => {
return (
<SafeAppCardContainer safeApp={safeApp} safeAppUrl={safeAppUrl} onClickSafeApp={onClickSafeApp} height={'100%'}>
<SafeAppCardContainer safeAppUrl={safeAppUrl} onClickSafeApp={onClickSafeApp} height={'100%'}>
{/* Safe App Header */}
<CardHeader
className={css.safeAppHeader}
Expand Down Expand Up @@ -168,7 +167,7 @@ const SafeAppCardListView = ({
openPreviewDrawer,
}: SafeAppCardViewProps) => {
return (
<SafeAppCardContainer safeApp={safeApp} safeAppUrl={safeAppUrl} onClickSafeApp={onClickSafeApp}>
<SafeAppCardContainer safeAppUrl={safeAppUrl} onClickSafeApp={onClickSafeApp}>
<CardContent sx={{ pb: '16px !important' }}>
<Box display="flex" flexDirection="row" alignItems="center" gap={2}>
<div className={css.safeAppIconContainer}>
Expand Down Expand Up @@ -204,7 +203,6 @@ const SafeAppCardListView = ({

type SafeAppCardContainerProps = {
onClickSafeApp?: () => void
safeApp?: SafeAppData
safeAppUrl: string
children: ReactNode
height?: string
Expand All @@ -213,18 +211,15 @@ type SafeAppCardContainerProps = {

export const SafeAppCardContainer = ({
children,
safeApp,
safeAppUrl,
onClickSafeApp,
height,
className,
}: SafeAppCardContainerProps) => {
const { openedSafeAppIds } = useOpenedSafeApps()

const handleClickSafeApp = (event: SyntheticEvent) => {
if (safeApp && !openedSafeAppIds.includes(safeApp.id)) {
if (onClickSafeApp) {
event.preventDefault()
onClickSafeApp?.()
onClickSafeApp()
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/components/safe-apps/SafeAppList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import useSafeAppPreviewDrawer from '@/hooks/safe-apps/useSafeAppPreviewDrawer'
import css from './styles.module.css'
import { Skeleton } from '@mui/material'
import useLocalStorage from '@/services/local-storage/useLocalStorage'
import { useOpenedSafeApps } from '@/hooks/safe-apps/useOpenedSafeApps'

type SafeAppListProps = {
safeAppsList: SafeAppData[]
Expand All @@ -38,6 +39,7 @@ const SafeAppList = ({
}: SafeAppListProps) => {
const [safeAppsViewMode = GRID_VIEW_MODE, setSafeAppsViewMode] = useLocalStorage<SafeAppsViewMode>(VIEW_MODE_KEY)
const { isPreviewDrawerOpen, previewDrawerApp, openPreviewDrawer, closePreviewDrawer } = useSafeAppPreviewDrawer()
const { openedSafeAppIds } = useOpenedSafeApps()

const { filteredApps, query, setQuery, setSelectedCategories, setOptimizedWithBatchFilter, selectedCategories } =
useSafeAppsFilters(safeAppsList)
Expand All @@ -48,11 +50,11 @@ const SafeAppList = ({
(safeApp: SafeAppData) => {
const isCustomApp = safeApp.id < 1

if (isCustomApp) return
if (isCustomApp || openedSafeAppIds.includes(safeApp.id)) return

return () => openPreviewDrawer(safeApp)
},
[openPreviewDrawer],
[openPreviewDrawer, openedSafeAppIds],
)

return (
Expand Down