import { useEffect, useState } from 'react'; import { useWatch } from 'react-hook-form'; import { type NetworkSymbol } from '@suite-common/wallet-config'; import { AssetSymbol } from '@suite-native/assets'; import { BottomSheetModal, Button, Card, HStack, IconButton, Input, Text, VStack, useBottomSheetModal, } from '@suite-native/atoms'; import { useFormContext } from '@suite-native/forms'; import { Icon } from '@suite-native/icons'; import { Translation, useTranslate } from '@suite-native/intl'; import { TRON_NOTE_MAX_BYTES } from '@trezor/network-tron/constants'; import { countBytesInString } from '@trezor/utils'; import { type SendOutputsFormValues } from '../sendOutputsFormSchema'; type TronNoteInputProps = { symbol: NetworkSymbol; }; export const TronNoteInput = ({ symbol }: TronNoteInputProps) => { const { bottomSheetRef, openModal, closeModal } = useBottomSheetModal(); const { setValue, control } = useFormContext(); const { translate } = useTranslate(); const [localNote, setLocalNote] = useState(''); const value = useWatch({ control, name: 'destinationTag' }) ?? ''; const hexByteSize = countBytesInString(localNote); const isHexTooLong = hexByteSize > TRON_NOTE_MAX_BYTES; useEffect(() => { setLocalNote(value); }, [value]); const onOpenPress = () => { setLocalNote(value); openModal(); }; const onSavePress = () => { setValue('destinationTag', localNote); closeModal(); }; const onRemovePress = () => { setValue('destinationTag', ''); setLocalNote(''); closeModal(); }; return ( <> {value ? ( {value} ), }} /> ) : ( )} } isCloseDisplayed onClose={closeModal} > ), }} /> {hexByteSize}/{TRON_NOTE_MAX_BYTES} bytes {value && ( )} ); };