mirror of
https://github.com/status-im/MyCrypto.git
synced 2025-01-09 10:41:56 +00:00
0d13dc93c5
* Adjust the validator and update validity class logic on AmountField * Improve readability and add a condition to invalidity for Input * Undo changes to Input and pass down showInvalidWithoutValue * Fix prop ordering issue * Add removed validator * Adjust logic for NoneField
50 lines
1.5 KiB
TypeScript
50 lines
1.5 KiB
TypeScript
import React from 'react';
|
|
|
|
import translate from 'translations';
|
|
import { UnitDropDown, SendEverything } from 'components';
|
|
import { Input } from 'components/ui';
|
|
import { AmountFieldFactory } from './AmountFieldFactory';
|
|
|
|
interface Props {
|
|
hasUnitDropdown?: boolean;
|
|
hasSendEverything?: boolean;
|
|
showAllTokens?: boolean;
|
|
showInvalidWithoutValue?: boolean;
|
|
customValidator?(rawAmount: string): boolean;
|
|
}
|
|
|
|
export const AmountField: React.SFC<Props> = ({
|
|
hasUnitDropdown,
|
|
hasSendEverything,
|
|
showAllTokens,
|
|
customValidator,
|
|
showInvalidWithoutValue
|
|
}) => (
|
|
<AmountFieldFactory
|
|
withProps={({ currentValue: { raw }, isValid, onChange, readOnly }) => (
|
|
<div className="AmountField input-group-wrapper">
|
|
<label className="AmountField-group input-group input-group-inline">
|
|
<div className="input-group-header">{translate('SEND_AMOUNT_SHORT')}</div>
|
|
<Input
|
|
isValid={isAmountValid(raw, customValidator, isValid)}
|
|
type="number"
|
|
placeholder="1"
|
|
value={raw}
|
|
readOnly={!!readOnly}
|
|
onChange={onChange}
|
|
showInvalidWithoutValue={showInvalidWithoutValue}
|
|
/>
|
|
{hasSendEverything && <SendEverything />}
|
|
{hasUnitDropdown && <UnitDropDown showAllTokens={showAllTokens} />}
|
|
</label>
|
|
</div>
|
|
)}
|
|
/>
|
|
);
|
|
|
|
const isAmountValid = (
|
|
raw: string,
|
|
customValidator: ((rawAmount: string) => boolean) | undefined,
|
|
isValid: boolean
|
|
) => (customValidator ? customValidator(raw) : isValid);
|