// Copyright 2017-2025 @pezkuwi/react-params authors & contributors // SPDX-License-Identifier: Apache-2.0 import type { Props as BaseProps } from '../types.js'; import React, { useCallback, useState } from 'react'; import { InputAddressSimple } from '@pezkuwi/react-components'; import { isEthereumAddress, validateAddress } from '@pezkuwi/util-crypto'; import Bare from './Bare.js'; interface Props extends BaseProps { bytesLength: 20 | 32; } function isValidAddress (value: string | null | undefined, isEthereum: boolean): boolean { if (value) { try { return isEthereum ? isEthereumAddress(value) : validateAddress(value); } catch (err) { console.error(err); } } return false; } function BasicAccountIdBase (props: Props): React.ReactElement { const { bytesLength, className = '', defaultValue: { value }, isDisabled, isError, label, onChange } = props; const [defaultValue] = useState(() => (value as string)?.toString()); const _onChange = useCallback( (value?: string | null) => onChange && onChange({ isValid: isValidAddress(value, bytesLength === 20), value }), [bytesLength, onChange] ); return ( ); } export default React.memo(BasicAccountIdBase);