import { FormControl } from 'components/FormControl'
import { NumberInput, TextInput } from 'components/forms/FormInput'
import { useEffect, useId, useMemo } from 'react'
import { FaMinus, FaPlus } from 'react-icons/fa'
import { useWallet } from 'utils/wallet'
import { useInputState, useNumberInputState } from './FormInput.hooks'
export interface DenomUnit {
denom: string
exponent: number
aliases: string
}
export interface DenomUnitsProps {
title: string
subtitle?: string
isRequired?: boolean
attributes: [string, DenomUnit][]
onAdd: () => void
onChange: (key: string, attribute: DenomUnit) => void
onRemove: (key: string) => void
}
export function DenomUnits(props: DenomUnitsProps) {
const { title, subtitle, isRequired, attributes, onAdd, onChange, onRemove } = props
return (
{attributes.map(([id], i) => (
))}
)
}
export interface DenomUnitProps {
id: string
isLast: boolean
onAdd: DenomUnitsProps['onAdd']
onChange: DenomUnitsProps['onChange']
onRemove: DenomUnitsProps['onRemove']
defaultAttribute: DenomUnit
}
export function DenomUnit({ id, isLast, onAdd, onChange, onRemove, defaultAttribute }: DenomUnitProps) {
const wallet = useWallet()
const Icon = useMemo(() => (isLast ? FaPlus : FaMinus), [isLast])
const htmlId = useId()
const denomState = useInputState({
id: `ma-denom-${htmlId}`,
name: `ma-denom-${htmlId}`,
title: `Denom`,
defaultValue: defaultAttribute.denom,
})
const exponentState = useNumberInputState({
id: `mint-exponent-${htmlId}`,
name: `mint-exponent-${htmlId}`,
title: `Exponent`,
defaultValue: defaultAttribute.exponent,
})
const aliasesState = useInputState({
id: `ma-aliases-${htmlId}`,
name: `ma-aliases-${htmlId}`,
title: `Aliases`,
defaultValue: defaultAttribute.aliases,
placeholder: 'Comma separated aliases',
})
useEffect(() => {
onChange(id, { denom: denomState.value, exponent: exponentState.value, aliases: aliasesState.value })
}, [id, denomState.value, exponentState.value, aliasesState.value])
return (
)
}