Skip to content

Commit

Permalink
fix: Set default owner on safe creation when entering step (safe-glob…
Browse files Browse the repository at this point in the history
  • Loading branch information
usame-algan authored May 7, 2024
1 parent f6108fe commit 489a765
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
9 changes: 1 addition & 8 deletions src/components/new-safe/create/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import SetNameStep from '@/components/new-safe/create/steps/SetNameStep'
import OwnerPolicyStep from '@/components/new-safe/create/steps/OwnerPolicyStep'
import ReviewStep from '@/components/new-safe/create/steps/ReviewStep'
import { CreateSafeStatus } from '@/components/new-safe/create/steps/StatusStep'
import useAddressBook from '@/hooks/useAddressBook'
import { CardStepper } from '@/components/new-safe/CardStepper'
import { AppRoutes } from '@/config/routes'
import { CREATE_SAFE_CATEGORY } from '@/services/analytics'
Expand Down Expand Up @@ -100,12 +99,6 @@ const staticHints: Record<
const CreateSafe = () => {
const router = useRouter()
const wallet = useWallet()
const addressBook = useAddressBook()
const defaultOwnerAddressBookName = wallet?.address ? addressBook[wallet.address] : undefined
const defaultOwner: NamedAddress = {
name: defaultOwnerAddressBookName || wallet?.ens || '',
address: wallet?.address || '',
}

const [safeName, setSafeName] = useState('')
const [dynamicHint, setDynamicHint] = useState<CreateSafeInfoItem>()
Expand Down Expand Up @@ -166,7 +159,7 @@ const CreateSafe = () => {

const initialData: NewSafeFormData = {
name: isSocialLogin ? mnemonicSafeName : '',
owners: [defaultOwner],
owners: [],
threshold: 1,
saltNonce: Date.now(),
}
Expand Down
11 changes: 10 additions & 1 deletion src/components/new-safe/create/steps/OwnerPolicyStep/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import CounterfactualHint from '@/features/counterfactual/CounterfactualHint'
import useAddressBook from '@/hooks/useAddressBook'
import useWallet from '@/hooks/wallets/useWallet'
import { Button, SvgIcon, MenuItem, Tooltip, Typography, Divider, Box, Grid, TextField } from '@mui/material'
import { Controller, FormProvider, useFieldArray, useForm } from 'react-hook-form'
import type { ReactElement } from 'react'
Expand Down Expand Up @@ -37,12 +39,19 @@ const OwnerPolicyStep = ({
}: StepRenderProps<NewSafeFormData> & {
setDynamicHint: (hints: CreateSafeInfoItem | undefined) => void
}): ReactElement => {
const wallet = useWallet()
const addressBook = useAddressBook()
const defaultOwnerAddressBookName = wallet?.address ? addressBook[wallet.address] : undefined
const defaultOwner: NamedAddress = {
name: defaultOwnerAddressBookName || wallet?.ens || '',
address: wallet?.address || '',
}
useSyncSafeCreationStep(setStep)

const formMethods = useForm<OwnerPolicyStepForm>({
mode: 'onChange',
defaultValues: {
[OwnerPolicyStepFields.owners]: data.owners,
[OwnerPolicyStepFields.owners]: data.owners.length > 0 ? data.owners : [defaultOwner],
[OwnerPolicyStepFields.threshold]: data.threshold,
},
})
Expand Down

0 comments on commit 489a765

Please sign in to comment.