Skip to content

Commit

Permalink
Merge branch 'recovery-epic' into edit-recovery-flow
Browse files Browse the repository at this point in the history
  • Loading branch information
iamacook committed Nov 22, 2023
2 parents e90ffa6 + 79b4f21 commit c9d7f56
Show file tree
Hide file tree
Showing 19 changed files with 1,032 additions and 280 deletions.
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,
})
182 changes: 0 additions & 182 deletions src/components/dashboard/RecoveryInProgress/index.test.tsx

This file was deleted.

Loading

0 comments on commit c9d7f56

Please sign in to comment.