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

feat: recovery info modals + widgets #2843

Merged
merged 4 commits into from
Nov 22, 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
29 changes: 29 additions & 0 deletions public/images/common/propose-recovery.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion src/components/common/PageLayout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import useDebounce from '@/hooks/useDebounce'
import { useRouter } from 'next/router'
import { TxModalContext } from '@/components/tx-flow'
import BatchSidebar from '@/components/batch/BatchSidebar'
import { RecoveryModal } from '@/components/recovery/RecoveryModal'

const isNoSidebarRoute = (pathname: string): boolean => {
return [
Expand Down Expand Up @@ -60,7 +61,9 @@ const PageLayout = ({ pathname, children }: { pathname: string; children: ReactE
})}
>
<div className={css.content}>
<SafeLoadingError>{children}</SafeLoadingError>
<SafeLoadingError>
<RecoveryModal>{children}</RecoveryModal>
</SafeLoadingError>
</div>

<BatchSidebar isOpen={isBatchOpen} onToggle={setBatchOpen} />
Expand Down
58 changes: 58 additions & 0 deletions src/components/dashboard/RecoveryHeader/index.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { BigNumber } from 'ethers'

import { _RecoveryHeader } from '.'
import { render } from '@/tests/test-utils'
import type { RecoveryQueueItem } from '@/store/recoverySlice'

describe('RecoveryHeader', () => {
it('should not render a widget if the chain does not support recovery', () => {
const { container } = render(
<_RecoveryHeader
isOwner
isGuardian
queue={[{ validFrom: BigNumber.from(0) } as RecoveryQueueItem]}
supportsRecovery={false}
/>,
)

expect(container).toBeEmptyDOMElement()
})

it('should render the in-progress widget if there is a queue for guardians', () => {
const { queryByText } = render(
<_RecoveryHeader
isOwner={false}
isGuardian
queue={[{ validFrom: BigNumber.from(0) } as RecoveryQueueItem]}
supportsRecovery
/>,
)

expect(queryByText('Account recovery in progress')).toBeTruthy()
})

it('should render the in-progress widget if there is a queue for owners', () => {
const { queryByText } = render(
<_RecoveryHeader
isOwner
isGuardian={false}
queue={[{ validFrom: BigNumber.from(0) } as RecoveryQueueItem]}
supportsRecovery
/>,
)

expect(queryByText('Account recovery in progress')).toBeTruthy()
})

it('should render the proposal widget when there is no queue for guardians', () => {
const { queryByText } = render(<_RecoveryHeader isOwner={false} isGuardian queue={[]} supportsRecovery />)

expect(queryByText('Recover this Account')).toBeTruthy()
})

it('should not render the proposal widget when there is no queue for owners', () => {
const { container } = render(<_RecoveryHeader isOwner isGuardian={false} queue={[]} supportsRecovery />)

expect(container).toBeEmptyDOMElement()
})
})
57 changes: 57 additions & 0 deletions src/components/dashboard/RecoveryHeader/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { Grid } from '@mui/material'
import type { ReactElement } from 'react'

import { useRecoveryQueue } from '@/hooks/useRecoveryQueue'
import { useIsGuardian } from '@/hooks/useIsGuardian'
import madProps from '@/utils/mad-props'
import { FEATURES } from '@/utils/chains'
import { useHasFeature } from '@/hooks/useChains'
import { RecoveryProposalCard } from '@/components/recovery/RecoveryCards/RecoveryProposalCard'
import { RecoveryInProgressCard } from '@/components/recovery/RecoveryCards/RecoveryInProgressCard'
import { WidgetContainer, WidgetBody } from '../styled'
import useIsSafeOwner from '@/hooks/useIsSafeOwner'
import type { RecoveryQueueItem } from '@/store/recoverySlice'

export function _RecoveryHeader({
isGuardian,
supportsRecovery,
queue,
}: {
isOwner: boolean
isGuardian: boolean
supportsRecovery: boolean
queue: Array<RecoveryQueueItem>
}): ReactElement | null {
const next = queue[0]

if (!supportsRecovery) {
return null
}

const modal = next ? (
<RecoveryInProgressCard orientation="horizontal" recovery={next} />
) : isGuardian ? (
<RecoveryProposalCard orientation="horizontal" />
) : null

if (modal) {
return (
<Grid item xs={12}>
<WidgetContainer>
<WidgetBody>{modal}</WidgetBody>
</WidgetContainer>
</Grid>
)
}
return null
}

// Appease TypeScript
const _useSupportedRecovery = () => useHasFeature(FEATURES.RECOVERY)

export const RecoveryHeader = madProps(_RecoveryHeader, {
isOwner: useIsSafeOwner,
isGuardian: useIsGuardian,
supportsRecovery: _useSupportedRecovery,
queue: useRecoveryQueue,
})
Comment on lines +52 to +57
Copy link
Member

Choose a reason for hiding this comment

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

👍

182 changes: 0 additions & 182 deletions src/components/dashboard/RecoveryInProgress/index.test.tsx

This file was deleted.

Loading
Loading