import React, { Component } from 'react'; import { setUnitMeta, TSetUnitMeta } from 'actions/transaction'; import { TokenBalance, MergedToken, getShownTokenBalances, getTokens } from 'selectors/wallet'; import { Query } from 'components/renderCbs'; import { connect } from 'react-redux'; import { AppState } from 'reducers'; import { getUnit } from 'selectors/transaction'; import { getNetworkUnit } from 'selectors/config'; import { Option } from 'react-select'; import { Dropdown } from 'components/ui'; interface DispatchProps { setUnitMeta: TSetUnitMeta; } interface StateProps { unit: string; tokens: TokenBalance[]; allTokens: MergedToken[]; showAllTokens?: boolean; networkUnit: string; } class UnitDropdownClass extends Component { public render() { const { tokens, allTokens, showAllTokens, unit, networkUnit } = this.props; const focusedTokens = showAllTokens ? allTokens : tokens; const options = [networkUnit, ...getTokenSymbols(focusedTokens)]; return ( ( 10} disabled={!!readOnly} /> )} /> ); } private handleOnChange = (unit: Option) => { if (!unit.value) { throw Error('No unit value found'); } this.props.setUnitMeta(unit.value); }; } const getTokenSymbols = (tokens: (TokenBalance | MergedToken)[]) => tokens.map(t => t.symbol); function mapStateToProps(state: AppState) { return { tokens: getShownTokenBalances(state, true), allTokens: getTokens(state), unit: getUnit(state), networkUnit: getNetworkUnit(state) }; } export const UnitDropDown = connect(mapStateToProps, { setUnitMeta })(UnitDropdownClass);