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: allow removing counterfactual safes from safe list #4643

Merged
merged 2 commits into from
Dec 13, 2024
Merged
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: 11 additions & 2 deletions src/components/sidebar/SafeListRemoveDialog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import type { ReactElement } from 'react'
import ModalDialog from '@/components/common/ModalDialog'
import { useAppDispatch } from '@/store'
import useAddressBook from '@/hooks/useAddressBook'
import { removeSafe } from '@/store/addedSafesSlice'
import Track from '@/components/common/Track'
import { OVERVIEW_EVENTS, OVERVIEW_LABELS } from '@/services/analytics'
import { AppRoutes } from '@/config/routes'
import router from 'next/router'
import { removeAddressBookEntry } from '@/store/addressBookSlice'
import { removeSafe, removeUndeployedSafe } from '@/store/slices'
import useSafeAddress from '@/hooks/useSafeAddress'
import useChainId from '@/hooks/useChainId'

const SafeListRemoveDialog = ({
handleClose,
Expand All @@ -24,13 +26,20 @@ const SafeListRemoveDialog = ({
chainId: string
}): ReactElement => {
const dispatch = useAppDispatch()
const safeAddress = useSafeAddress()
const safeChainId = useChainId()
const addressBook = useAddressBook()
const trackingLabel =
router.pathname === AppRoutes.welcome.accounts ? OVERVIEW_LABELS.login_page : OVERVIEW_LABELS.sidebar

const safe = addressBook?.[address] || address

const handleConfirm = () => {
const handleConfirm = async () => {
// When removing the current counterfactual safe, redirect to the accounts page
if (safeAddress === address && safeChainId === chainId) {
await router.push(AppRoutes.welcome.accounts)
}
dispatch(removeUndeployedSafe({ chainId, address }))
dispatch(removeSafe({ chainId, address }))
usame-algan marked this conversation as resolved.
Show resolved Hide resolved
dispatch(removeAddressBookEntry({ chainId, address }))
handleClose()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Consolidate useSafeAddress and useChainId within a custom hook or context if they are frequently used together to avoid code repetition.

  2. Add error-handling logic to handleConfirm for the router.push call to manage possible navigation failures.

Expand Down
Loading