mirror of
https://github.com/status-im/MyCrypto.git
synced 2025-01-10 02:55:41 +00:00
e0c4599b64
* add gas limit/price constants * add gas limit/price validators & selectors * apply new gas limit/price validation to components and sagas * create/apply function to sanitize advanced fields input * add types, update tests * fix unrelated failing test
47 lines
1.5 KiB
TypeScript
47 lines
1.5 KiB
TypeScript
import React from 'react';
|
|
import { GasLimitFieldFactory } from './GasLimitFieldFactory';
|
|
import translate from 'translations';
|
|
import { CSSTransition } from 'react-transition-group';
|
|
import { Spinner } from 'components/ui';
|
|
import { gasLimitValidator } from 'libs/validators';
|
|
|
|
interface Props {
|
|
includeLabel: boolean;
|
|
onlyIncludeLoader: boolean;
|
|
}
|
|
|
|
export const GaslimitLoading: React.SFC<{ gasEstimationPending: boolean }> = ({
|
|
gasEstimationPending
|
|
}) => (
|
|
<CSSTransition in={gasEstimationPending} timeout={300} classNames="fade">
|
|
<div className={`SimpleGas-estimating small ${gasEstimationPending ? 'active' : ''}`}>
|
|
Calculating gas limit
|
|
<Spinner />
|
|
</div>
|
|
</CSSTransition>
|
|
);
|
|
|
|
export const GasLimitField: React.SFC<Props> = ({ includeLabel, onlyIncludeLoader }) => (
|
|
<React.Fragment>
|
|
{includeLabel ? <label>{translate('TRANS_gas')} </label> : null}
|
|
|
|
<GasLimitFieldFactory
|
|
withProps={({ gasLimit: { raw }, onChange, readOnly, gasEstimationPending }) => (
|
|
<>
|
|
<GaslimitLoading gasEstimationPending={gasEstimationPending} />
|
|
{onlyIncludeLoader ? null : (
|
|
<input
|
|
className={`form-control ${gasLimitValidator(raw) ? 'is-valid' : 'is-invalid'}`}
|
|
type="number"
|
|
placeholder="e.g. 21000"
|
|
readOnly={!!readOnly}
|
|
value={raw}
|
|
onChange={onChange}
|
|
/>
|
|
)}
|
|
</>
|
|
)}
|
|
/>
|
|
</React.Fragment>
|
|
);
|