Files
William O'Beirne bf6a122e38 Night Mode Theme (#1896)
* Initial changes to define theme maps, color function, and convert all global styles.

* More global styles.

* All styles converted, colors uncertain.

* Fix tabs, temporary theme toggle button.

* Color refinements

* Color network selector, introduce shade function

* Make palette page

* Add theme button and minor styling to nav

* Blueify dark theme

* A bunch of color adjustments to work better with dark theme

* Fix tables

* Fix wallet decrypt colors

* More misc fixes

* Fix up electron colors

* Convert web theme to redux state / action

* Theme toggle in app, prevent rerenders

* Get rid of all variables, fix selects

* Fix conf modal, modal close styles

* Fix test

* Adjust swap colors

* Check in breaking out component, changing icons

* Check in progress

* Theme toggle in footer. New icons

* Prevent rerender on theme change

* Fix up outstanding merge conflicts

* Fix generate colors to be dark mode friendly

* Reduce swap color intensity

* Make disabled buttons darker in dark mode

* Reduce button size by 25%
2018-06-26 23:51:42 -05:00

130 lines
3.3 KiB
TypeScript

import React from 'react';
import { connect } from 'react-redux';
import Select from 'react-select';
import moment from 'moment';
import translate from 'translations';
import { isValidTxHash } from 'libs/validators';
import { AppState } from 'features/reducers';
import * as selectors from 'features/selectors';
import { getIsValidAddressFn } from 'features/config';
import { Input } from 'components/ui';
import './TxHashInput.scss';
interface OwnProps {
hash?: string;
onSubmit(hash: string): void;
}
interface ReduxProps {
recentTxs: AppState['transactions']['recent'];
isValidAddress: ReturnType<typeof getIsValidAddressFn>;
}
type Props = OwnProps & ReduxProps;
interface State {
hash: string;
}
interface Option {
label: string;
value: string;
}
class TxHashInput extends React.Component<Props, State> {
public constructor(props: Props) {
super(props);
this.state = { hash: props.hash || '' };
}
public UNSAFE_componentWillReceiveProps(nextProps: Props) {
if (this.props.hash !== nextProps.hash && nextProps.hash) {
this.setState({ hash: nextProps.hash });
}
}
public render() {
const { recentTxs, isValidAddress } = this.props;
const { hash } = this.state;
let selectOptions: Option[] = [];
if (recentTxs && recentTxs.length) {
selectOptions = recentTxs.map(tx => ({
label: `
${moment(tx.time).format('lll')}
-
${tx.from.substr(0, 8)}...
to
${tx.to.substr(0, 8)}...
`,
value: tx.hash
}));
}
return (
<form className="TxHashInput" onSubmit={this.handleSubmit}>
{!!selectOptions.length && (
<div className="TxHashInput-recent">
<Select
value={hash}
onChange={this.handleSelectTx}
options={selectOptions}
placeholder={translate('SELECT_RECENT_TX')}
searchable={false}
/>
<em className="TxHashInput-recent-separator">{translate('OR')}</em>
</div>
)}
<Input
value={hash}
isValid={hash ? isValidTxHash(hash) : true}
placeholder="0x16e521..."
className="TxHashInput-field"
onChange={this.handleChange}
/>
{isValidAddress(hash) && (
<p className="TxHashInput-message help-block is-invalid">
{translate('SELECT_RECENT_TX_BY_TXHASH')}
</p>
)}
<button
className="TxHashInput-submit btn btn-primary btn-block"
disabled={!isValidTxHash(hash)}
>
{translate('NAV_CHECKTXSTATUS')}
</button>
</form>
);
}
private handleChange = (ev: React.FormEvent<HTMLInputElement>) => {
this.setState({ hash: ev.currentTarget.value });
};
private handleSelectTx = (option: Option) => {
if (option && option.value) {
this.setState({ hash: option.value });
this.props.onSubmit(option.value);
} else {
this.setState({ hash: '' });
}
};
private handleSubmit = (ev: React.FormEvent<HTMLFormElement>) => {
ev.preventDefault();
if (isValidTxHash(this.state.hash)) {
this.props.onSubmit(this.state.hash);
}
};
}
export default connect((state: AppState): ReduxProps => ({
recentTxs: selectors.getRecentNetworkTransactions(state),
isValidAddress: getIsValidAddressFn(state)
}))(TxHashInput);