import { TChangeLanguage, TChangeNodeIntent, TAddCustomNode, TRemoveCustomNode, TAddCustomNetwork } from 'actions/config'; import logo from 'assets/images/logo-myetherwallet.svg'; import { Dropdown, ColorDropdown } from 'components/ui'; import React, { Component } from 'react'; import classnames from 'classnames'; import { Link } from 'react-router-dom'; import { TSetGasPriceField } from 'actions/transaction'; import { ANNOUNCEMENT_MESSAGE, ANNOUNCEMENT_TYPE, languages, NODES, VERSION, NodeConfig, CustomNodeConfig, CustomNetworkConfig } from 'config/data'; import GasPriceDropdown from './components/GasPriceDropdown'; import Navigation from './components/Navigation'; import CustomNodeModal from './components/CustomNodeModal'; import { getKeyByValue } from 'utils/helpers'; import { makeCustomNodeId } from 'utils/node'; import { getNetworkConfigFromId } from 'utils/network'; import './index.scss'; import { AppState } from 'reducers'; interface Props { languageSelection: string; node: NodeConfig; nodeSelection: string; isChangingNode: boolean; gasPrice: AppState['transaction']['fields']['gasPrice']; customNodes: CustomNodeConfig[]; customNetworks: CustomNetworkConfig[]; changeLanguage: TChangeLanguage; changeNodeIntent: TChangeNodeIntent; setGasPriceField: TSetGasPriceField; addCustomNode: TAddCustomNode; removeCustomNode: TRemoveCustomNode; addCustomNetwork: TAddCustomNetwork; } interface State { isAddingCustomNode: boolean; } export default class Header extends Component { public state = { isAddingCustomNode: false }; public render() { const { languageSelection, changeNodeIntent, node, nodeSelection, isChangingNode, customNodes, customNetworks } = this.props; const { isAddingCustomNode } = this.state; const selectedLanguage = languageSelection; const selectedNetwork = getNetworkConfigFromId(node.network, customNetworks); const LanguageDropDown = Dropdown as new () => Dropdown; const nodeOptions = Object.keys(NODES) .map(key => { const n = NODES[key]; const network = getNetworkConfigFromId(n.network, customNetworks); return { value: key, name: ( {network && network.name} ({n.service}) ), color: network && network.color, hidden: n.hidden }; }) .concat( customNodes.map(cn => { const network = getNetworkConfigFromId(cn.network, customNetworks); return { value: makeCustomNodeId(cn), name: ( {network && network.name} - {cn.name} (custom) ), color: network && network.color, hidden: false, onRemove: () => this.props.removeCustomNode(cn) }; }) ); return (
{ANNOUNCEMENT_MESSAGE && (
)}
MyEtherWallet
v{VERSION}
Disclaimer } onChange={this.changeLanguage} size="smr" color="white" />
Add Custom Node } disabled={nodeSelection === 'web3'} onChange={changeNodeIntent} size="smr" color="white" menuAlign="right" />
{isAddingCustomNode && ( )}
); } public changeLanguage = (value: string) => { const key = getKeyByValue(languages, value); if (key) { this.props.changeLanguage(key); } }; private openCustomNodeModal = () => { this.setState({ isAddingCustomNode: true }); }; private closeCustomNodeModal = () => { this.setState({ isAddingCustomNode: false }); }; private addCustomNode = (node: CustomNodeConfig) => { this.setState({ isAddingCustomNode: false }); this.props.addCustomNode(node); }; }