2018-06-18 01:53:00 +00:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import { MapStateToProps, connect } from 'react-redux';
|
|
|
|
import { Link } from 'react-router-dom';
|
|
|
|
import classnames from 'classnames';
|
|
|
|
|
|
|
|
import { ANNOUNCEMENT_MESSAGE, ANNOUNCEMENT_TYPE, languages } from 'config';
|
|
|
|
import { NetworkConfig } from 'types/network';
|
|
|
|
import { getKeyByValue } from 'utils/helpers';
|
|
|
|
import logo from 'assets/images/logo-mycrypto.svg';
|
|
|
|
import { OldDropDown } from 'components/ui';
|
2017-10-04 04:37:06 +00:00
|
|
|
import {
|
2018-06-18 01:53:00 +00:00
|
|
|
AddCustomNodeAction,
|
|
|
|
TAddCustomNetwork,
|
|
|
|
TAddCustomNode,
|
2017-10-04 04:37:06 +00:00
|
|
|
TChangeLanguage,
|
2018-05-29 14:51:42 +00:00
|
|
|
TChangeNodeRequestedOneTime,
|
2017-12-01 16:09:51 +00:00
|
|
|
TRemoveCustomNode,
|
2018-06-18 01:53:00 +00:00
|
|
|
getLanguageSelection,
|
|
|
|
getNetworkConfig,
|
|
|
|
getOffline,
|
|
|
|
isNodeChanging,
|
|
|
|
isStaticNodeId,
|
2018-02-12 20:43:07 +00:00
|
|
|
changeLanguage,
|
2018-05-29 14:51:42 +00:00
|
|
|
changeNodeRequestedOneTime,
|
2018-02-12 20:43:07 +00:00
|
|
|
addCustomNode,
|
|
|
|
removeCustomNode,
|
|
|
|
addCustomNetwork
|
2018-06-18 01:53:00 +00:00
|
|
|
} from 'features/config';
|
|
|
|
import { AppState } from 'features/reducers';
|
|
|
|
import { transactionFieldsActions } from 'features/transaction';
|
|
|
|
import CustomNodeModal from 'components/CustomNodeModal';
|
|
|
|
import NetworkDropdown from './components/NetworkDropdown';
|
2017-09-25 02:06:28 +00:00
|
|
|
import Navigation from './components/Navigation';
|
2018-01-11 18:04:11 +00:00
|
|
|
import OnlineStatus from './components/OnlineStatus';
|
2018-05-29 14:51:42 +00:00
|
|
|
import './index.scss';
|
2017-07-15 04:16:36 +00:00
|
|
|
|
2018-04-12 23:17:46 +00:00
|
|
|
interface OwnProps {
|
|
|
|
networkParam: string | null;
|
|
|
|
}
|
|
|
|
|
2018-02-12 20:43:07 +00:00
|
|
|
interface DispatchProps {
|
2017-09-25 02:06:28 +00:00
|
|
|
changeLanguage: TChangeLanguage;
|
2018-05-29 14:51:42 +00:00
|
|
|
changeNodeRequestedOneTime: TChangeNodeRequestedOneTime;
|
2018-06-18 01:53:00 +00:00
|
|
|
setGasPriceField: transactionFieldsActions.TSetGasPriceField;
|
2017-11-18 20:33:53 +00:00
|
|
|
addCustomNode: TAddCustomNode;
|
|
|
|
removeCustomNode: TRemoveCustomNode;
|
2017-12-01 16:09:51 +00:00
|
|
|
addCustomNetwork: TAddCustomNetwork;
|
2017-09-25 02:06:28 +00:00
|
|
|
}
|
2017-04-12 05:04:27 +00:00
|
|
|
|
2018-02-12 20:43:07 +00:00
|
|
|
interface StateProps {
|
2018-04-12 23:17:46 +00:00
|
|
|
shouldSetNodeFromQS: boolean;
|
2018-02-12 20:43:07 +00:00
|
|
|
network: NetworkConfig;
|
2018-06-27 04:51:42 +00:00
|
|
|
languageSelection: ReturnType<typeof getLanguageSelection>;
|
|
|
|
isChangingNode: ReturnType<typeof isNodeChanging>;
|
|
|
|
isOffline: ReturnType<typeof getOffline>;
|
2018-02-12 20:43:07 +00:00
|
|
|
}
|
|
|
|
|
2017-11-18 20:33:53 +00:00
|
|
|
interface State {
|
|
|
|
isAddingCustomNode: boolean;
|
|
|
|
}
|
|
|
|
|
2018-04-12 23:17:46 +00:00
|
|
|
type Props = OwnProps & StateProps & DispatchProps;
|
2018-02-12 20:43:07 +00:00
|
|
|
|
|
|
|
class Header extends Component<Props, State> {
|
2017-11-18 20:33:53 +00:00
|
|
|
public state = {
|
|
|
|
isAddingCustomNode: false
|
|
|
|
};
|
|
|
|
|
2018-04-12 23:17:46 +00:00
|
|
|
public componentDidMount() {
|
|
|
|
this.attemptSetNodeFromQueryParameter();
|
|
|
|
}
|
|
|
|
|
2017-09-25 02:06:28 +00:00
|
|
|
public render() {
|
2018-05-29 14:51:42 +00:00
|
|
|
const { languageSelection, isChangingNode, isOffline, network } = this.props;
|
2017-11-18 20:33:53 +00:00
|
|
|
const { isAddingCustomNode } = this.state;
|
2017-09-26 23:03:38 +00:00
|
|
|
const selectedLanguage = languageSelection;
|
2018-03-01 17:53:29 +00:00
|
|
|
const LanguageDropDown = OldDropDown as new () => OldDropDown<typeof selectedLanguage>;
|
2017-10-02 22:36:59 +00:00
|
|
|
|
2017-07-02 05:49:06 +00:00
|
|
|
return (
|
2017-07-15 04:16:36 +00:00
|
|
|
<div className="Header">
|
2017-09-25 02:06:28 +00:00
|
|
|
{ANNOUNCEMENT_MESSAGE && (
|
2018-01-29 20:51:02 +00:00
|
|
|
<div className={`Header-announcement is-${ANNOUNCEMENT_TYPE}`}>
|
|
|
|
{ANNOUNCEMENT_MESSAGE}
|
|
|
|
</div>
|
2017-09-25 02:06:28 +00:00
|
|
|
)}
|
2017-08-25 07:37:36 +00:00
|
|
|
|
2017-07-15 04:16:36 +00:00
|
|
|
<section className="Header-branding">
|
|
|
|
<section className="Header-branding-inner container">
|
2017-12-05 19:51:21 +00:00
|
|
|
<Link to="/" className="Header-branding-title" aria-label="Go to homepage">
|
2017-07-15 04:16:36 +00:00
|
|
|
<img
|
|
|
|
className="Header-branding-title-logo"
|
|
|
|
src={logo}
|
|
|
|
height="64px"
|
|
|
|
width="245px"
|
2018-02-07 04:28:28 +00:00
|
|
|
alt="MyCrypto logo"
|
2017-07-15 04:16:36 +00:00
|
|
|
/>
|
2017-07-02 05:49:06 +00:00
|
|
|
</Link>
|
2017-10-02 22:36:59 +00:00
|
|
|
<div className="Header-branding-right">
|
2018-01-11 18:04:11 +00:00
|
|
|
<div className="Header-branding-right-online">
|
|
|
|
<OnlineStatus isOffline={isOffline} />
|
|
|
|
</div>
|
|
|
|
|
2017-10-02 22:36:59 +00:00
|
|
|
<div className="Header-branding-right-dropdown">
|
|
|
|
<LanguageDropDown
|
2017-12-05 19:51:21 +00:00
|
|
|
ariaLabel={`change language. current language ${languages[selectedLanguage]}`}
|
2017-10-02 22:36:59 +00:00
|
|
|
options={Object.values(languages)}
|
|
|
|
value={languages[selectedLanguage]}
|
|
|
|
onChange={this.changeLanguage}
|
|
|
|
size="smr"
|
|
|
|
color="white"
|
|
|
|
/>
|
|
|
|
</div>
|
2017-11-18 20:33:53 +00:00
|
|
|
<div
|
|
|
|
className={classnames({
|
|
|
|
'Header-branding-right-dropdown': true,
|
|
|
|
'is-flashing': isChangingNode
|
|
|
|
})}
|
|
|
|
>
|
2018-05-29 14:51:42 +00:00
|
|
|
<NetworkDropdown openCustomNodeModal={this.openCustomNodeModal} />
|
2017-10-02 22:36:59 +00:00
|
|
|
</div>
|
2017-07-02 05:49:06 +00:00
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
</section>
|
2017-04-18 23:36:29 +00:00
|
|
|
|
2018-02-12 20:43:07 +00:00
|
|
|
<Navigation color={!network.isCustom && network.color} />
|
2017-11-18 20:33:53 +00:00
|
|
|
|
2018-03-08 19:28:43 +00:00
|
|
|
<CustomNodeModal
|
|
|
|
isOpen={isAddingCustomNode}
|
|
|
|
addCustomNode={this.addCustomNode}
|
|
|
|
handleClose={this.closeCustomNodeModal}
|
|
|
|
/>
|
2017-07-02 05:49:06 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2017-07-04 01:25:01 +00:00
|
|
|
|
2017-09-26 23:03:38 +00:00
|
|
|
public changeLanguage = (value: string) => {
|
|
|
|
const key = getKeyByValue(languages, value);
|
|
|
|
if (key) {
|
|
|
|
this.props.changeLanguage(key);
|
|
|
|
}
|
2017-07-04 03:21:19 +00:00
|
|
|
};
|
2017-11-18 20:33:53 +00:00
|
|
|
|
|
|
|
private openCustomNodeModal = () => {
|
|
|
|
this.setState({ isAddingCustomNode: true });
|
|
|
|
};
|
|
|
|
|
|
|
|
private closeCustomNodeModal = () => {
|
|
|
|
this.setState({ isAddingCustomNode: false });
|
|
|
|
};
|
|
|
|
|
2018-02-12 20:43:07 +00:00
|
|
|
private addCustomNode = (payload: AddCustomNodeAction['payload']) => {
|
2017-11-18 20:33:53 +00:00
|
|
|
this.setState({ isAddingCustomNode: false });
|
2018-02-12 20:43:07 +00:00
|
|
|
this.props.addCustomNode(payload);
|
2017-11-18 20:33:53 +00:00
|
|
|
};
|
2018-04-12 23:17:46 +00:00
|
|
|
|
|
|
|
private attemptSetNodeFromQueryParameter() {
|
|
|
|
const { shouldSetNodeFromQS, networkParam } = this.props;
|
|
|
|
if (shouldSetNodeFromQS) {
|
2018-05-29 14:51:42 +00:00
|
|
|
this.props.changeNodeRequestedOneTime(networkParam!);
|
2018-04-12 23:17:46 +00:00
|
|
|
}
|
|
|
|
}
|
2017-04-12 05:04:27 +00:00
|
|
|
}
|
2018-02-12 20:43:07 +00:00
|
|
|
|
2018-06-18 01:53:00 +00:00
|
|
|
const mapStateToProps: MapStateToProps<StateProps, OwnProps, AppState> = (
|
|
|
|
state,
|
|
|
|
{ networkParam }
|
|
|
|
): StateProps => ({
|
|
|
|
shouldSetNodeFromQS: !!(networkParam && isStaticNodeId(state, networkParam)),
|
|
|
|
isOffline: getOffline(state),
|
|
|
|
isChangingNode: isNodeChanging(state),
|
|
|
|
languageSelection: getLanguageSelection(state),
|
|
|
|
network: getNetworkConfig(state)
|
|
|
|
});
|
|
|
|
|
|
|
|
const mapDispatchToProps: DispatchProps = {
|
|
|
|
setGasPriceField: transactionFieldsActions.setGasPriceField,
|
|
|
|
changeLanguage,
|
|
|
|
changeNodeRequestedOneTime,
|
|
|
|
addCustomNode,
|
|
|
|
removeCustomNode,
|
|
|
|
addCustomNetwork
|
|
|
|
};
|
|
|
|
|
2018-02-12 20:43:07 +00:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(Header);
|