-
Notifications
You must be signed in to change notification settings - Fork 464
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor: a review screen for recovery attempts (#4200)
- Loading branch information
Showing
8 changed files
with
160 additions
and
37 deletions.
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
101 changes: 101 additions & 0 deletions
101
src/components/tx-flow/flows/RecoveryAttempt/RecoveryAttemptReview.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,101 @@ | ||
import { type SyntheticEvent, useContext, useCallback, useEffect } from 'react' | ||
import { CircularProgress, CardActions, Button, Typography, Stack, Divider } from '@mui/material' | ||
import CheckWallet from '@/components/common/CheckWallet' | ||
import { Errors, trackError } from '@/services/exceptions' | ||
import { dispatchRecoveryExecution } from '@/features/recovery/services/recovery-sender' | ||
import useWallet from '@/hooks/wallets/useWallet' | ||
import useSafeInfo from '@/hooks/useSafeInfo' | ||
import ErrorMessage from '@/components/tx/ErrorMessage' | ||
import TxCard from '@/components/tx-flow/common/TxCard' | ||
import { TxModalContext } from '@/components/tx-flow' | ||
import NetworkWarning from '@/components/new-safe/create/NetworkWarning' | ||
import { RecoveryValidationErrors } from '@/features/recovery/components/RecoveryValidationErrors' | ||
import type { RecoveryQueueItem } from '@/features/recovery/services/recovery-state' | ||
import { RecoveryDescription } from '@/features/recovery/components/RecoveryDescription' | ||
import { useAsyncCallback } from '@/hooks/useAsync' | ||
import FieldsGrid from '@/components/tx/FieldsGrid' | ||
import EthHashInfo from '@/components/common/EthHashInfo' | ||
import { SafeTxContext } from '../../SafeTxProvider' | ||
|
||
type RecoveryAttemptReviewProps = { | ||
item: RecoveryQueueItem | ||
} | ||
|
||
const RecoveryAttemptReview = ({ item }: RecoveryAttemptReviewProps) => { | ||
const { asyncCallback, isLoading, error } = useAsyncCallback(dispatchRecoveryExecution) | ||
const wallet = useWallet() | ||
const { safe } = useSafeInfo() | ||
const { setTxFlow } = useContext(TxModalContext) | ||
const { setNonceNeeded } = useContext(SafeTxContext) | ||
|
||
const onFormSubmit = useCallback( | ||
async (e: SyntheticEvent) => { | ||
e.preventDefault() | ||
|
||
if (!wallet) return | ||
|
||
try { | ||
await asyncCallback({ | ||
provider: wallet.provider, | ||
chainId: safe.chainId, | ||
args: item.args, | ||
delayModifierAddress: item.address, | ||
signerAddress: wallet.address, | ||
}) | ||
setTxFlow(undefined) | ||
} catch (err) { | ||
trackError(Errors._812, err) | ||
} | ||
}, | ||
[asyncCallback, setTxFlow, wallet, safe, item.address, item.args], | ||
) | ||
|
||
useEffect(() => { | ||
setNonceNeeded(false) | ||
}, [setNonceNeeded]) | ||
|
||
return ( | ||
<TxCard> | ||
<form onSubmit={onFormSubmit}> | ||
<Stack gap={3} mb={2}> | ||
<Typography>Execute this transaction to finalize the recovery.</Typography> | ||
|
||
<FieldsGrid title="Initiator"> | ||
<EthHashInfo address={item.executor} showName showCopyButton hasExplorer /> | ||
</FieldsGrid> | ||
|
||
<Divider sx={{ mx: -3 }} /> | ||
|
||
<RecoveryDescription item={item} /> | ||
|
||
<NetworkWarning /> | ||
|
||
<RecoveryValidationErrors item={item} /> | ||
|
||
{error && <ErrorMessage error={error}>Error submitting the transaction.</ErrorMessage>} | ||
</Stack> | ||
|
||
<Divider sx={{ mx: -3, my: 3.5 }} /> | ||
|
||
<CardActions> | ||
{/* Submit button, also available to non-owner role members */} | ||
<CheckWallet allowNonOwner> | ||
{(isOk) => ( | ||
<Button | ||
data-testid="execute-through-role-form-btn" | ||
variant="contained" | ||
type="submit" | ||
disabled={!isOk || isLoading} | ||
sx={{ minWidth: '112px' }} | ||
> | ||
{isLoading ? <CircularProgress size={20} /> : 'Execute'} | ||
</Button> | ||
)} | ||
</CheckWallet> | ||
</CardActions> | ||
</form> | ||
</TxCard> | ||
) | ||
} | ||
|
||
export default RecoveryAttemptReview |
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,14 @@ | ||
import TxLayout from '@/components/tx-flow/common/TxLayout' | ||
import SaveAddressIcon from '@/public/images/common/save-address.svg' | ||
import RecoveryAttemptReview from './RecoveryAttemptReview' | ||
import type { RecoveryQueueItem } from '@/features/recovery/services/recovery-state' | ||
|
||
const RecoveryAttemptFlow = ({ item }: { item: RecoveryQueueItem }) => { | ||
return ( | ||
<TxLayout title="Recovery" subtitle="Execute recovery" icon={SaveAddressIcon} step={0} hideNonce> | ||
<RecoveryAttemptReview item={item} /> | ||
</TxLayout> | ||
) | ||
} | ||
|
||
export default RecoveryAttemptFlow |
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
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
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