-
Notifications
You must be signed in to change notification settings - Fork 454
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: recovery info modals + widgets
- Loading branch information
Showing
19 changed files
with
782 additions
and
281 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
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 { RecoveryProposal } from '@/components/recovery/RecoveryModal/RecoveryProposal' | ||
import { RecoveryInProgress } from '@/components/recovery/RecoveryModal/RecoveryInProgress' | ||
import { WidgetContainer, WidgetBody } from '../styled' | ||
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 ? ( | ||
<RecoveryInProgress variant="widget" recovery={next} /> | ||
) : isGuardian ? ( | ||
<RecoveryProposal variant="widget" /> | ||
) : 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, { | ||
isGuardian: useIsGuardian, | ||
supportsRecovery: _useSupportedRecovery, | ||
queue: useRecoveryQueue, | ||
}) |
182 changes: 0 additions & 182 deletions
182
src/components/dashboard/RecoveryInProgress/index.test.tsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.