Skip to content

Commit

Permalink
fixed default vault name/symbol after changing yield source
Browse files Browse the repository at this point in the history
  • Loading branch information
Ncookiez committed Sep 30, 2024
1 parent 8dd17a9 commit 744a309
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
17 changes: 15 additions & 2 deletions apps/vault-factory/src/components/forms/CustomYieldSourceForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { useEffect } from 'react'
import { FormProvider, useForm } from 'react-hook-form'
import {
isUsingCustomYieldSourceAtom,
vaultNameAtom,
vaultSymbolAtom,
vaultYieldSourceAddressAtom,
vaultYieldSourceNameAtom
} from 'src/atoms'
Expand Down Expand Up @@ -33,6 +35,9 @@ export const CustomYieldSourceForm = (props: CustomYieldSourceFormProps) => {
const [vaultYieldSourceAddress, setVaultYieldSourceAddress] = useAtom(vaultYieldSourceAddressAtom)
const setIsUsingCustomYieldSource = useSetAtom(isUsingCustomYieldSourceAtom)

const setVaultName = useSetAtom(vaultNameAtom)
const setVaultSymbol = useSetAtom(vaultSymbolAtom)

const { step, setStep } = useVaultCreationSteps()

useEffect(() => {
Expand All @@ -45,8 +50,16 @@ export const CustomYieldSourceForm = (props: CustomYieldSourceFormProps) => {
}, [])

const onSubmit = (data: CustomYieldSourceFormValues) => {
setVaultYieldSourceName(data.vaultYieldSourceName.trim())
setVaultYieldSourceAddress(data.vaultYieldSourceAddress.trim() as Address)
const selectedYieldSourceName = data.vaultYieldSourceName.trim()
const selectedYieldSourceAddress = data.vaultYieldSourceAddress.trim() as Address

if (selectedYieldSourceAddress !== vaultYieldSourceAddress) {
setVaultName(undefined)
setVaultSymbol(undefined)
}

setVaultYieldSourceName(selectedYieldSourceName)
setVaultYieldSourceAddress(selectedYieldSourceAddress)
setStep(step + 2)
}

Expand Down
22 changes: 19 additions & 3 deletions apps/vault-factory/src/components/forms/YieldVaultForm.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { Selection, SelectionItem, Spinner } from '@shared/ui'
import classNames from 'classnames'
import { useAtom, useAtomValue } from 'jotai'
import { useAtom, useAtomValue, useSetAtom } from 'jotai'
import { useEffect, useMemo, useState } from 'react'
import { FormProvider, useForm } from 'react-hook-form'
import { vaultChainIdAtom, vaultYieldSourceAddressAtom, vaultYieldSourceIdAtom } from 'src/atoms'
import {
vaultChainIdAtom,
vaultNameAtom,
vaultSymbolAtom,
vaultYieldSourceAddressAtom,
vaultYieldSourceIdAtom
} from 'src/atoms'
import { YieldSourceVaultTag } from 'src/types'
import { Address } from 'viem'
import { NextButton } from '@components/buttons/NextButton'
Expand All @@ -29,6 +35,9 @@ export const YieldVaultForm = (props: YieldVaultFormProps) => {
const vaultYieldSourceId = useAtomValue(vaultYieldSourceIdAtom)
const [vaultYieldSourceAddress, setVaultYieldSourceAddress] = useAtom(vaultYieldSourceAddressAtom)

const setVaultName = useSetAtom(vaultNameAtom)
const setVaultSymbol = useSetAtom(vaultSymbolAtom)

const { nextStep } = useVaultCreationSteps()

const [filterId, setFilterId] = useState<'all' | YieldSourceVaultTag>('all')
Expand All @@ -41,7 +50,14 @@ export const YieldVaultForm = (props: YieldVaultFormProps) => {
}, [])

const onSubmit = (data: YieldVaultFormValues) => {
setVaultYieldSourceAddress(data.vaultYieldSourceAddress.trim() as Address)
const selectedYieldSourceAddress = data.vaultYieldSourceAddress.trim() as Address

if (selectedYieldSourceAddress !== vaultYieldSourceAddress) {
setVaultName(undefined)
setVaultSymbol(undefined)
}

setVaultYieldSourceAddress(selectedYieldSourceAddress)
nextStep()
}

Expand Down

0 comments on commit 744a309

Please sign in to comment.