Skip to content

Commit

Permalink
fix: cleanup code + rename test
Browse files Browse the repository at this point in the history
  • Loading branch information
iamacook committed Nov 18, 2023
1 parent e513ebc commit 0fb3786
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useContext, useEffect, useMemo } from 'react'
import { useContext, useEffect } from 'react'
import type { ReactElement } from 'react'

import SignOrExecuteForm from '@/components/tx/SignOrExecuteForm'
Expand All @@ -20,37 +20,34 @@ export function EnableRecoveryFlowReview({ params }: { params: EnableRecoveryFlo
const { safe } = useSafeInfo()
const { setSafeTx, safeTxError, setSafeTxError } = useContext(SafeTxContext)

const recoverySetup = useMemo(() => {
const guardian = params[EnableRecoveryFlowFields.guardians]
const delay = RecoveryDelayPeriods.find(({ value }) => value === params[EnableRecoveryFlowFields.txCooldown])!.label
const expiration = RecoveryExpirationPeriods.find(
({ value }) => value === params[EnableRecoveryFlowFields.txExpiration],
)!.label
const emailAddress = params[EnableRecoveryFlowFields.emailAddress]

useEffect(() => {
if (!web3) {
return
}

return getRecoverySetup({
const { transactions } = getRecoverySetup({
...params,
guardians: [guardian],
safe,
provider: web3,
})
}, [params, safe, web3])

useEffect(() => {
if (recoverySetup) {
createMultiSendCallOnlyTx(recoverySetup.transactions).then(setSafeTx).catch(setSafeTxError)
}
}, [recoverySetup, setSafeTx, setSafeTxError])
createMultiSendCallOnlyTx(transactions).then(setSafeTx).catch(setSafeTxError)
}, [guardian, params, safe, setSafeTx, setSafeTxError, web3])

useEffect(() => {
if (safeTxError) {
logError(Errors._809, safeTxError.message)
}
}, [safeTxError])

const guardian = params[EnableRecoveryFlowFields.guardians][0]
const delay = RecoveryDelayPeriods.find(({ value }) => value === params[EnableRecoveryFlowFields.txCooldown])!.label
const expiration = RecoveryExpirationPeriods.find(
({ value }) => value === params[EnableRecoveryFlowFields.txExpiration],
)!.label
const emailAddress = params[EnableRecoveryFlowFields.emailAddress]

return (
<SignOrExecuteForm onSubmit={() => null}>
<Typography>This transaction will enable the Account recovery feature once executed.</Typography>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,7 @@ export function EnableRecoveryFlowSettings({
recovery process in the future.
</Typography>

<AddressBookInput
label="Guardian address"
name={`${EnableRecoveryFlowFields.guardians}.0`}
required
fullWidth
/>
<AddressBookInput label="Guardian address" name={EnableRecoveryFlowFields.guardians} required fullWidth />

<Typography variant="h5">Recovery delay</Typography>

Expand Down
19 changes: 7 additions & 12 deletions src/components/tx-flow/flows/EnableRecovery/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export const RecoveryExpirationPeriods = [
...RecoveryDelayPeriods,
] as const

const Subtitles = ['How does recovery work?', 'Set up recovery settings', 'Set up account recovery']

export enum EnableRecoveryFlowFields {
guardians = 'guardians',
txCooldown = 'txCooldown',
Expand All @@ -48,41 +50,34 @@ export enum EnableRecoveryFlowFields {
}

export type EnableRecoveryFlowProps = {
[EnableRecoveryFlowFields.guardians]: Array<string>
[EnableRecoveryFlowFields.guardians]: string
[EnableRecoveryFlowFields.txCooldown]: string
[EnableRecoveryFlowFields.txExpiration]: string
[EnableRecoveryFlowFields.emailAddress]: string
}

export function EnableRecoveryFlow(): ReactElement {
const { data, step, nextStep, prevStep } = useTxStepper<EnableRecoveryFlowProps>({
[EnableRecoveryFlowFields.guardians]: [''],
[EnableRecoveryFlowFields.txCooldown]: `${60 * 60 * 24 * 28}`, // 28 days in seconds
[EnableRecoveryFlowFields.guardians]: '',
[EnableRecoveryFlowFields.txCooldown]: `${DAY_SECONDS * 28}`, // 28 days in seconds
[EnableRecoveryFlowFields.txExpiration]: '0',
[EnableRecoveryFlowFields.emailAddress]: '',
})

const steps = [
<EnableRecoveryFlowIntro key={0} onSubmit={() => nextStep(data)} />,
<EnableRecoveryFlowSettings key={1} params={data} onSubmit={(formData) => nextStep({ ...data, ...formData })} />,
<EnableRecoveryFlowReview key={1} params={data} />,
<EnableRecoveryFlowReview key={2} params={data} />,
]

const isIntro = step === 0
const isSettings = step === 1

const subtitle = isIntro
? 'How does recovery work?'
: isSettings
? 'Set up account recovery settings'
: 'Set up account recovery'

const icon = isIntro ? undefined : RecoveryPlus

return (
<TxLayout
title="Account recovery"
subtitle={subtitle}
subtitle={Subtitles[step]}
icon={icon}
step={step}
onBack={prevStep}
Expand Down
2 changes: 1 addition & 1 deletion src/services/recovery/__tests__/setup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('getRecoverySetup', () => {
jest.clearAllMocks()
})

it('should deploy Delay Modifier, enable it on Safe and add a Guardian', () => {
it('should return deploy Delay Modifier, enable Safe guardian and add a Guardian transactions', () => {
const txCooldown = faker.string.numeric()
const txExpiration = faker.string.numeric()
const guardians = [faker.finance.ethereumAddress()]
Expand Down

0 comments on commit 0fb3786

Please sign in to comment.