2018-01-15 09:59:59 +00:00
|
|
|
import React from 'react';
|
2018-06-18 01:53:00 +00:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
2018-02-10 19:24:05 +00:00
|
|
|
import translate from 'translations';
|
2018-06-18 01:53:00 +00:00
|
|
|
import { AppState } from 'features/reducers';
|
|
|
|
import { getOffline } from 'features/config';
|
|
|
|
import { transactionNetworkActions, transactionNetworkSelectors } from 'features/transaction';
|
2018-03-01 17:53:29 +00:00
|
|
|
import { Spinner, Input } from 'components/ui';
|
2018-06-18 01:53:00 +00:00
|
|
|
import Help from 'components/ui/Help';
|
|
|
|
import { NonceFieldFactory } from 'components/NonceFieldFactory';
|
2018-02-10 19:24:05 +00:00
|
|
|
import './NonceField.scss';
|
2018-01-15 09:59:59 +00:00
|
|
|
|
2018-02-08 17:51:15 +00:00
|
|
|
interface OwnProps {
|
2018-01-15 09:59:59 +00:00
|
|
|
alwaysDisplay: boolean;
|
2018-07-02 21:51:51 +00:00
|
|
|
showInvalidBeforeBlur?: boolean;
|
2018-01-15 09:59:59 +00:00
|
|
|
}
|
|
|
|
|
2018-02-08 17:51:15 +00:00
|
|
|
interface StateProps {
|
2018-02-08 23:44:30 +00:00
|
|
|
isOffline: boolean;
|
|
|
|
noncePending: boolean;
|
2018-02-08 17:51:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
interface DispatchProps {
|
2018-06-18 01:53:00 +00:00
|
|
|
requestNonce: transactionNetworkActions.TGetNonceRequested;
|
2018-02-08 17:51:15 +00:00
|
|
|
}
|
2018-01-15 09:59:59 +00:00
|
|
|
|
2018-02-08 17:51:15 +00:00
|
|
|
type Props = OwnProps & DispatchProps & StateProps;
|
|
|
|
|
|
|
|
class NonceField extends React.Component<Props> {
|
|
|
|
public render() {
|
2018-07-02 21:51:51 +00:00
|
|
|
const {
|
|
|
|
alwaysDisplay,
|
|
|
|
showInvalidBeforeBlur,
|
|
|
|
requestNonce,
|
|
|
|
noncePending,
|
|
|
|
isOffline
|
|
|
|
} = this.props;
|
2018-02-08 17:51:15 +00:00
|
|
|
return (
|
|
|
|
<NonceFieldFactory
|
|
|
|
withProps={({ nonce: { raw, value }, onChange, readOnly, shouldDisplay }) => {
|
|
|
|
return alwaysDisplay || shouldDisplay ? (
|
2018-03-01 17:53:29 +00:00
|
|
|
<div className="input-group-wrapper Nonce-label">
|
|
|
|
<label className="input-group">
|
|
|
|
<div className="input-group-header">
|
2018-03-22 03:50:25 +00:00
|
|
|
{translate('OFFLINE_STEP2_LABEL_5')}
|
2018-03-01 17:53:29 +00:00
|
|
|
<Help
|
|
|
|
size="x1"
|
|
|
|
link="https://support.mycrypto.com/transactions/what-is-nonce.html"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<Input
|
2018-05-13 19:24:50 +00:00
|
|
|
isValid={!!value}
|
|
|
|
className="Nonce-field-input"
|
2018-02-08 17:51:15 +00:00
|
|
|
type="number"
|
2018-03-22 03:50:25 +00:00
|
|
|
placeholder="7"
|
2018-02-08 17:51:15 +00:00
|
|
|
value={raw}
|
|
|
|
readOnly={readOnly}
|
|
|
|
onChange={onChange}
|
2018-02-08 23:44:30 +00:00
|
|
|
disabled={noncePending}
|
2018-06-11 22:43:39 +00:00
|
|
|
showInvalidWithoutValue={true}
|
2018-07-02 21:51:51 +00:00
|
|
|
showInvalidBeforeBlur={showInvalidBeforeBlur}
|
2018-02-08 17:51:15 +00:00
|
|
|
/>
|
2018-02-08 23:44:30 +00:00
|
|
|
{noncePending ? (
|
|
|
|
<div className="Nonce-spinner">
|
|
|
|
<Spinner />
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
!isOffline && (
|
|
|
|
<button className="Nonce-refresh" onClick={requestNonce}>
|
|
|
|
<i className="fa fa-refresh" />
|
|
|
|
</button>
|
|
|
|
)
|
|
|
|
)}
|
2018-03-01 17:53:29 +00:00
|
|
|
</label>
|
|
|
|
</div>
|
2018-02-08 17:51:15 +00:00
|
|
|
) : null;
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2018-01-15 09:59:59 +00:00
|
|
|
|
2018-02-08 23:44:30 +00:00
|
|
|
const mapStateToProps = (state: AppState): StateProps => {
|
2018-02-08 17:51:15 +00:00
|
|
|
return {
|
2018-02-08 23:44:30 +00:00
|
|
|
isOffline: getOffline(state),
|
2018-06-18 01:53:00 +00:00
|
|
|
noncePending: transactionNetworkSelectors.nonceRequestPending(state)
|
2018-02-08 17:51:15 +00:00
|
|
|
};
|
|
|
|
};
|
2018-01-15 09:59:59 +00:00
|
|
|
|
2018-06-18 01:53:00 +00:00
|
|
|
export default connect(mapStateToProps, {
|
|
|
|
requestNonce: transactionNetworkActions.getNonceRequested
|
|
|
|
})(NonceField);
|