import { Conditional } from 'components/Conditional' import { FormGroup } from 'components/FormGroup' import { useInputState } from 'components/forms/FormInput.hooks' import { useWallet } from 'contexts/wallet' import React, { useEffect, useState } from 'react' import { resolveAddress } from '../../../utils/resolveAddress' import { NumberInput, TextInput } from '../../forms/FormInput' interface RoyaltyDetailsProps { onChange: (data: RoyaltyDetailsDataProps) => void } export interface RoyaltyDetailsDataProps { royaltyType: RoyaltyState paymentAddress: string share: number } type RoyaltyState = 'none' | 'new' export const RoyaltyDetails = ({ onChange }: RoyaltyDetailsProps) => { const wallet = useWallet() const [royaltyState, setRoyaltyState] = useState('none') const royaltyPaymentAddressState = useInputState({ id: 'royalty-payment-address', name: 'royaltyPaymentAddress', title: 'Payment Address', subtitle: 'Address to receive royalties', placeholder: 'stars1234567890abcdefghijklmnopqrstuvwxyz...', }) const royaltyShareState = useInputState({ id: 'royalty-share', name: 'royaltyShare', title: 'Share Percentage', subtitle: 'Percentage of royalties to be paid', placeholder: '8%', }) useEffect(() => { void resolveAddress( royaltyPaymentAddressState.value .toLowerCase() .replace(/,/g, '') .replace(/"/g, '') .replace(/'/g, '') .replace(/ /g, ''), wallet, ).then((royaltyPaymentAddress) => { royaltyPaymentAddressState.onChange(royaltyPaymentAddress) const data: RoyaltyDetailsDataProps = { royaltyType: royaltyState, paymentAddress: royaltyPaymentAddressState.value, share: Number(royaltyShareState.value), } onChange(data) }) // eslint-disable-next-line react-hooks/exhaustive-deps }, [royaltyState, royaltyPaymentAddressState.value, royaltyShareState.value]) return (
{ setRoyaltyState('none') }} type="radio" value="None" />
{ setRoyaltyState('new') }} type="radio" value="Existing" />
) }