Adjust reason length input (#7299)
This commit is contained in:
parent
15a5d7f342
commit
01b267c7fe
@ -3,10 +3,11 @@
|
||||
|
||||
import type { BN } from '@polkadot/util';
|
||||
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import React, { useMemo, useState } from 'react';
|
||||
|
||||
import { Button, Input, InputAddress, InputBalance, Modal, TxButton } from '@polkadot/react-components';
|
||||
import { useApi, useToggle } from '@polkadot/react-hooks';
|
||||
import { BN_ZERO } from '@polkadot/util';
|
||||
|
||||
import { useTranslation } from '../translate';
|
||||
|
||||
@ -14,7 +15,7 @@ interface Props {
|
||||
members: string[];
|
||||
}
|
||||
|
||||
const MAX_REASON_LEN = 128;
|
||||
const MAX_REASON_LEN = 256;
|
||||
const MIN_REASON_LEN = 5;
|
||||
|
||||
function TipCreate ({ members }: Props): React.ReactElement<Props> {
|
||||
@ -23,15 +24,21 @@ function TipCreate ({ members }: Props): React.ReactElement<Props> {
|
||||
const [isOpen, toggleOpen] = useToggle();
|
||||
const [accountId, setAccountId] = useState<string | null>(null);
|
||||
const [beneficiary, setBeneficiary] = useState<string | null>(null);
|
||||
const [isMember, setIsMember] = useState(false);
|
||||
const [reason, setReason] = useState('');
|
||||
const [value, setValue] = useState<BN | undefined>();
|
||||
const hasValue = value?.gtn(0);
|
||||
const hasReason = reason?.length >= MIN_REASON_LEN && reason?.length <= MAX_REASON_LEN;
|
||||
|
||||
useEffect((): void => {
|
||||
setIsMember(members.includes(accountId || ''));
|
||||
}, [accountId, members]);
|
||||
const maxReasonLen = useMemo(
|
||||
() => Math.min(MAX_REASON_LEN, (
|
||||
(api.consts.tips || api.consts.treasury)?.maximumReasonLength?.toNumber() ||
|
||||
MAX_REASON_LEN
|
||||
)),
|
||||
[api]
|
||||
);
|
||||
const isMember = useMemo(
|
||||
() => !!accountId && members.includes(accountId),
|
||||
[accountId, members]
|
||||
);
|
||||
const hasValue = !!value && value.gt(BN_ZERO);
|
||||
const hasReason = !!reason && (reason.length >= MIN_REASON_LEN) && (reason.length <= maxReasonLen);
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user