-
Notifications
You must be signed in to change notification settings - Fork 454
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: edit recovery flow #2824
Merged
Merged
feat: edit recovery flow #2824
Changes from 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8baedf9
feat: edit recovery flow
iamacook 8a316e9
fix: edit initial recovery module
iamacook c705999
Merge branch 'recovery-epic' into edit-recovery-flow
iamacook 5370666
Merge branch 'recovery-epic' into edit-recovery-flow
iamacook e90ffa6
Merge branch 'recovery-epic' into edit-recovery-flow
iamacook c9d7f56
Merge branch 'recovery-epic' into edit-recovery-flow
iamacook 3bffc0b
fix: add guardian validation + test periods
iamacook 6dcfc49
feat: add recovery delay tooltip
iamacook 338d61e
Merge branch 'recovery-epic' into edit-recovery-flow
iamacook 09cad6f
fix: set flow, improve comment + remove caching
iamacook fdeb566
Merge branch 'recovery-epic' into edit-recovery-flow
iamacook cb4e3bb
Merge branch 'recovery-epic' into edit-recovery-flow
iamacook 0a253d5
fix: tests
iamacook File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
74 changes: 74 additions & 0 deletions
74
src/components/settings/Recovery/ConfirmRemoveRecoveryModal.tsx
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,74 @@ | ||
import { | ||
Button, | ||
Dialog, | ||
DialogActions, | ||
DialogContent, | ||
DialogContentText, | ||
DialogTitle, | ||
IconButton, | ||
SvgIcon, | ||
} from '@mui/material' | ||
import CloseIcon from '@mui/icons-material/Close' | ||
import { useContext } from 'react' | ||
import type { ReactElement } from 'react' | ||
|
||
import AlertIcon from '@/public/images/notifications/alert.svg' | ||
import { TxModalContext } from '@/components/tx-flow' | ||
import { RemoveRecoveryFlow } from '@/components/tx-flow/flows/RemoveRecovery' | ||
import type { RecoveryState } from '@/store/recoverySlice' | ||
|
||
export function ConfirmRemoveRecoveryModal({ | ||
open, | ||
onClose, | ||
delayModifier, | ||
}: { | ||
open: boolean | ||
onClose: () => void | ||
delayModifier: RecoveryState[number] | ||
}): ReactElement { | ||
const { setTxFlow } = useContext(TxModalContext) | ||
|
||
const onConfirm = () => { | ||
setTxFlow(<RemoveRecoveryFlow delayModifier={delayModifier} />) | ||
onClose() | ||
} | ||
|
||
return ( | ||
<Dialog open={open} onClose={onClose}> | ||
<DialogTitle display="flex" alignItems="center" sx={{ pt: 3 }}> | ||
<SvgIcon | ||
component={AlertIcon} | ||
inheritViewBox | ||
sx={{ | ||
color: (theme) => theme.palette.error.main, | ||
mr: '10px', | ||
}} | ||
/> | ||
Remove the recovery module? | ||
<IconButton | ||
onClick={onClose} | ||
sx={{ | ||
color: (theme) => theme.palette.text.secondary, | ||
ml: 'auto', | ||
}} | ||
> | ||
<CloseIcon /> | ||
</IconButton> | ||
</DialogTitle> | ||
|
||
<DialogContent dividers sx={{ py: 2, px: 3 }}> | ||
<DialogContentText color="text.primary"> | ||
Are you sure you wish to remove the recovery module? The assigned guardian won't be able to recover this | ||
Safe account for you. | ||
</DialogContentText> | ||
</DialogContent> | ||
|
||
<DialogActions sx={{ display: 'flex', justifyContent: 'space-between', p: 3, pb: 2 }}> | ||
<Button onClick={onClose}>Cancel</Button> | ||
<Button onClick={onConfirm} autoFocus variant="danger"> | ||
Remove | ||
</Button> | ||
</DialogActions> | ||
</Dialog> | ||
) | ||
} |
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,62 @@ | ||
import { IconButton, SvgIcon, Tooltip } from '@mui/material' | ||
import { useContext, useState } from 'react' | ||
import type { ReactElement } from 'react' | ||
|
||
import { TxModalContext } from '@/components/tx-flow' | ||
import useIsSafeOwner from '@/hooks/useIsSafeOwner' | ||
import DeleteIcon from '@/public/images/common/delete.svg' | ||
import EditIcon from '@/public/images/common/edit.svg' | ||
import CheckWallet from '@/components/common/CheckWallet' | ||
import { ConfirmRemoveRecoveryModal } from './ConfirmRemoveRecoveryModal' | ||
import type { RecoveryState } from '@/store/recoverySlice' | ||
|
||
export function DelayModifierRow({ delayModifier }: { delayModifier: RecoveryState[number] }): ReactElement | null { | ||
const { setTxFlow } = useContext(TxModalContext) | ||
const isOwner = useIsSafeOwner() | ||
const [confirm, setConfirm] = useState(false) | ||
|
||
if (!isOwner) { | ||
return null | ||
} | ||
|
||
const onEdit = () => { | ||
// TODO: Display flow | ||
setTxFlow(undefined) | ||
} | ||
|
||
const onDelete = () => { | ||
setConfirm(true) | ||
} | ||
|
||
const onCloseConfirm = () => { | ||
setConfirm(false) | ||
} | ||
|
||
return ( | ||
<> | ||
<CheckWallet> | ||
{(isOk) => ( | ||
<> | ||
<Tooltip title={isOk ? 'Edit recovery setup' : undefined}> | ||
<span> | ||
<IconButton onClick={onEdit} size="small" disabled={!isOk}> | ||
<SvgIcon component={EditIcon} inheritViewBox color="border" fontSize="small" /> | ||
</IconButton> | ||
</span> | ||
</Tooltip> | ||
|
||
<Tooltip title={isOk ? 'Disable recovery' : undefined}> | ||
<span> | ||
<IconButton onClick={onDelete} size="small" disabled={!isOk}> | ||
<SvgIcon component={DeleteIcon} inheritViewBox color="error" fontSize="small" /> | ||
</IconButton> | ||
</span> | ||
</Tooltip> | ||
</> | ||
)} | ||
</CheckWallet> | ||
|
||
<ConfirmRemoveRecoveryModal open={confirm} onClose={onCloseConfirm} delayModifier={delayModifier} /> | ||
</> | ||
) | ||
} |
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 |
---|---|---|
@@ -1,20 +1,19 @@ | ||
import { Alert, Box, Button, Grid, IconButton, Paper, SvgIcon, Tooltip, Typography } from '@mui/material' | ||
import { Alert, Box, Button, Grid, Paper, SvgIcon, Tooltip, Typography } from '@mui/material' | ||
import { useContext, useMemo } from 'react' | ||
import type { ReactElement } from 'react' | ||
|
||
import { EnableRecoveryFlow } from '@/components/tx-flow/flows/EnableRecovery' | ||
import { UpsertRecoveryFlow } from '@/components/tx-flow/flows/UpsertRecovery' | ||
import { TxModalContext } from '@/components/tx-flow' | ||
import { Chip } from '@/components/common/Chip' | ||
import ExternalLink from '@/components/common/ExternalLink' | ||
import { DelayModifierRow } from './DelayModifierRow' | ||
import useIsSafeOwner from '@/hooks/useIsSafeOwner' | ||
import { useAppSelector } from '@/store' | ||
import { selectRecovery } from '@/store/recoverySlice' | ||
import EthHashInfo from '@/components/common/EthHashInfo' | ||
import DeleteIcon from '@/public/images/common/delete.svg' | ||
import EditIcon from '@/public/images/common/edit.svg' | ||
import EnhancedTable from '@/components/common/EnhancedTable' | ||
import CheckWallet from '@/components/common/CheckWallet' | ||
import InfoIcon from '@/public/images/notifications/info.svg' | ||
import CheckWallet from '@/components/common/CheckWallet' | ||
|
||
import tableCss from '@/components/common/EnhancedTable/styles.module.css' | ||
|
||
|
@@ -68,13 +67,16 @@ const headCells = [ | |
{ id: HeadCells.Actions, label: '', sticky: true }, | ||
] | ||
|
||
// TODO: Migrate section | ||
export function Recovery(): ReactElement { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this still valid? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, the settings need to be merged with spending limits. I've clarified the comment in 09cad6f. |
||
const { setTxFlow } = useContext(TxModalContext) | ||
const recovery = useAppSelector(selectRecovery) | ||
const isOwner = useIsSafeOwner() | ||
|
||
const rows = useMemo(() => { | ||
return recovery.flatMap(({ guardians, txCooldown, txExpiration }) => { | ||
return recovery.flatMap((delayModifier) => { | ||
const { guardians, txCooldown, txExpiration } = delayModifier | ||
|
||
return guardians.map((guardian) => { | ||
const DAY_IN_SECONDS = 60 * 60 * 24 | ||
|
||
|
@@ -108,39 +110,15 @@ export function Recovery(): ReactElement { | |
sticky: true, | ||
content: ( | ||
<div className={tableCss.actions}> | ||
{isOwner && ( | ||
<CheckWallet> | ||
{(isOk) => ( | ||
<> | ||
<Tooltip title={isOk ? 'Edit recovery setup' : undefined}> | ||
<span> | ||
{/* TODO: Display flow */} | ||
<IconButton onClick={() => setTxFlow(undefined)} size="small" disabled={!isOk}> | ||
<SvgIcon component={EditIcon} inheritViewBox color="border" fontSize="small" /> | ||
</IconButton> | ||
</span> | ||
</Tooltip> | ||
|
||
<Tooltip title={isOk ? 'Disable recovery' : undefined}> | ||
<span> | ||
{/* TODO: Display flow */} | ||
<IconButton onClick={() => setTxFlow(undefined)} size="small" disabled={!isOk}> | ||
<SvgIcon component={DeleteIcon} inheritViewBox color="error" fontSize="small" /> | ||
</IconButton> | ||
</span> | ||
</Tooltip> | ||
</> | ||
)} | ||
</CheckWallet> | ||
)} | ||
<DelayModifierRow delayModifier={delayModifier} /> | ||
</div> | ||
), | ||
}, | ||
}, | ||
} | ||
}) | ||
}) | ||
}, [recovery, isOwner, setTxFlow]) | ||
}, [recovery]) | ||
|
||
return ( | ||
<Paper sx={{ p: 4 }}> | ||
|
@@ -169,9 +147,18 @@ export function Recovery(): ReactElement { | |
Give us feedback | ||
</ExternalLink> | ||
</Alert> | ||
<Button variant="contained" onClick={() => setTxFlow(<EnableRecoveryFlow />)} sx={{ mt: 2 }}> | ||
Set up recovery | ||
</Button> | ||
<CheckWallet> | ||
{(isOk) => ( | ||
<Button | ||
variant="contained" | ||
disabled={!isOk} | ||
onClick={() => setTxFlow(<UpsertRecoveryFlow />)} | ||
sx={{ mt: 2 }} | ||
> | ||
Set up recovery | ||
</Button> | ||
)} | ||
</CheckWallet> | ||
</> | ||
) : ( | ||
<EnhancedTable rows={rows} headCells={headCells} /> | ||
|
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you forgot to add the UpsertRecoveryFlow here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, good catch. I've added it in 09cad6f.