From 31175625b446cb5d18b17db23018bca8b14d280c Mon Sep 17 00:00:00 2001 From: Chi Kei Chan Date: Thu, 21 Mar 2019 16:03:30 -0700 Subject: Folder restructure (#6304) * Remove ui/app/keychains/ * Remove ui/app/img/ (unused images) * Move conversion-util to helpers/utils/ * Move token-util to helpers/utils/ * Move /helpers/*.js inside /helpers/utils/ * Move util tests inside /helpers/utils/ * Renameand move confirm-transaction/util.js to helpers/utils/ * Move higher-order-components to helpers/higher-order-components/ * Move infura-conversion.json to helpers/constants/ * Move all utility functions to helpers/utils/ * Move pages directory to top-level * Move all constants to helpers/constants/ * Move metametrics inside helpers/ * Move app and root inside pages/ * Move routes inside helpers/ * Re-organize ducks/ * Move reducers to ducks/ * Move selectors inside selectors/ * Move test out of test folder * Move action, reducer, store inside store/ * Move ui components inside ui/ * Move UI components inside ui/ * Move connected components inside components/app/ * Move i18n-helper inside helpers/ * Fix unit tests * Fix unit test * Move pages components * Rename routes component * Move reducers to ducks/index * Fix bad path in unit test --- .../token-input/token-input.component.js | 145 --------------------- 1 file changed, 145 deletions(-) delete mode 100644 ui/app/components/token-input/token-input.component.js (limited to 'ui/app/components/token-input/token-input.component.js') diff --git a/ui/app/components/token-input/token-input.component.js b/ui/app/components/token-input/token-input.component.js deleted file mode 100644 index 398b762ec..000000000 --- a/ui/app/components/token-input/token-input.component.js +++ /dev/null @@ -1,145 +0,0 @@ -import React, { PureComponent } from 'react' -import PropTypes from 'prop-types' -import UnitInput from '../unit-input' -import CurrencyDisplay from '../currency-display' -import { getWeiHexFromDecimalValue } from '../../helpers/conversions.util' -import ethUtil from 'ethereumjs-util' -import { conversionUtil, multiplyCurrencies } from '../../conversion-util' -import { ETH } from '../../constants/common' - -/** - * Component that allows user to enter token values as a number, and props receive a converted - * hex value. props.value, used as a default or forced value, should be a hex value, which - * gets converted into a decimal value. - */ -export default class TokenInput extends PureComponent { - static contextTypes = { - t: PropTypes.func, - } - - static propTypes = { - currentCurrency: PropTypes.string, - onChange: PropTypes.func, - onBlur: PropTypes.func, - value: PropTypes.string, - suffix: PropTypes.string, - showFiat: PropTypes.bool, - hideConversion: PropTypes.bool, - selectedToken: PropTypes.object, - selectedTokenExchangeRate: PropTypes.number, - } - - constructor (props) { - super(props) - - const { value: hexValue } = props - const decimalValue = hexValue ? this.getValue(props) : 0 - - this.state = { - decimalValue, - hexValue, - } - } - - componentDidUpdate (prevProps) { - const { value: prevPropsHexValue } = prevProps - const { value: propsHexValue } = this.props - const { hexValue: stateHexValue } = this.state - - if (prevPropsHexValue !== propsHexValue && propsHexValue !== stateHexValue) { - const decimalValue = this.getValue(this.props) - this.setState({ hexValue: propsHexValue, decimalValue }) - } - } - - getValue (props) { - const { value: hexValue, selectedToken: { decimals, symbol } = {} } = props - - const multiplier = Math.pow(10, Number(decimals || 0)) - const decimalValueString = conversionUtil(ethUtil.addHexPrefix(hexValue), { - fromNumericBase: 'hex', - toNumericBase: 'dec', - toCurrency: symbol, - conversionRate: multiplier, - invertConversionRate: true, - }) - - return Number(decimalValueString) ? decimalValueString : '' - } - - handleChange = decimalValue => { - const { selectedToken: { decimals } = {}, onChange } = this.props - - const multiplier = Math.pow(10, Number(decimals || 0)) - const hexValue = multiplyCurrencies(decimalValue || 0, multiplier, { toNumericBase: 'hex' }) - - this.setState({ hexValue, decimalValue }) - onChange(hexValue) - } - - handleBlur = () => { - this.props.onBlur(this.state.hexValue) - } - - renderConversionComponent () { - const { selectedTokenExchangeRate, showFiat, currentCurrency, hideConversion } = this.props - const { decimalValue } = this.state - let currency, numberOfDecimals - - if (hideConversion) { - return ( -
- { this.context.t('noConversionRateAvailable') } -
- ) - } - - if (showFiat) { - // Display Fiat - currency = currentCurrency - numberOfDecimals = 2 - } else { - // Display ETH - currency = ETH - numberOfDecimals = 6 - } - - const decimalEthValue = (decimalValue * selectedTokenExchangeRate) || 0 - const hexWeiValue = getWeiHexFromDecimalValue({ - value: decimalEthValue, - fromCurrency: ETH, - fromDenomination: ETH, - }) - - return selectedTokenExchangeRate - ? ( - - ) : ( -
- { this.context.t('noConversionRateAvailable') } -
- ) - } - - render () { - const { suffix, ...restProps } = this.props - const { decimalValue } = this.state - - return ( - - { this.renderConversionComponent() } - - ) - } -} -- cgit v1.2.3