Skip to content

Commit

Permalink
feat: show public delegate name under address input in delegation form
Browse files Browse the repository at this point in the history
  • Loading branch information
katamarinaki committed Oct 24, 2024
1 parent 84a00c3 commit e66140e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
2 changes: 2 additions & 0 deletions modules/delegation/ui/DelegationForm/DelegationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { DelegationFormSubmitButton } from './DelegationFormSubmitButton'
import { DelegationFormFootNote } from './DelegationFormFootNote'
import { DelegationFormController } from './DelegationFormController'
import { DelegationTxStatus } from './DelegationTxStatus'
import { DelegationFormPublicDelegateTooltip } from './DelegationFormPublicDelegateTooltip'

type Props = DelegationFormProviderProps & {
onCustomizeClick?: () => void
Expand All @@ -22,6 +23,7 @@ export function DelegationForm({ onCustomizeClick, ...providerProps }: Props) {
<DelegationFormSubtitle />
<DelegationStatus />
<DelegationAddressInput />
<DelegationFormPublicDelegateTooltip />
<DelegationFormBalance onCustomizeClick={onCustomizeClick} />
<DelegationFormSubmitButton onCustomizeClick={onCustomizeClick} />
<DelegationFormFootNote />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { useEffect, useState } from 'react'
import { useDelegationFormData } from 'modules/delegation/providers/DelegationFormContext'
import { PublicDelegate } from 'modules/delegation/types'
import { getPublicDelegateByAddress } from 'modules/delegation/utils/getPublicDelegateName'
import { isValidAddress } from 'modules/shared/utils/addressValidation'
import { DelegationFormFootNoteStyled } from './DelegationFormStyle'

export function DelegationFormPublicDelegateTooltip() {
const { watch } = useDelegationFormData()
const [selectedPublicDelegate, setSelectedPublicDelegate] =
useState<PublicDelegate | null>(null)

useEffect(() => {
const { unsubscribe } = watch(({ delegateAddress }) => {
if (!delegateAddress) return

if (isValidAddress(delegateAddress)) {
const publicDelegate = getPublicDelegateByAddress(delegateAddress)
if (
publicDelegate &&
publicDelegate.address !== selectedPublicDelegate?.address
) {
setSelectedPublicDelegate(publicDelegate)
}
}
})
return () => unsubscribe()
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [watch])

if (!selectedPublicDelegate) return null

return (
<DelegationFormFootNoteStyled>
Public delegate: <b>{selectedPublicDelegate.name}</b>
</DelegationFormFootNoteStyled>
)
}

0 comments on commit e66140e

Please sign in to comment.