diff options
Diffstat (limited to 'ui/app/components/currency-display')
6 files changed, 0 insertions, 284 deletions
diff --git a/ui/app/components/currency-display/currency-display.component.js b/ui/app/components/currency-display/currency-display.component.js deleted file mode 100644 index 6a743cc4e..000000000 --- a/ui/app/components/currency-display/currency-display.component.js +++ /dev/null @@ -1,46 +0,0 @@ -import React, { PureComponent } from 'react' -import PropTypes from 'prop-types' -import classnames from 'classnames' -import { GWEI } from '../../constants/common' - -export default class CurrencyDisplay extends PureComponent { - static propTypes = { - className: PropTypes.string, - displayValue: PropTypes.string, - prefix: PropTypes.string, - prefixComponent: PropTypes.node, - style: PropTypes.object, - suffix: PropTypes.string, - // Used in container - currency: PropTypes.string, - denomination: PropTypes.oneOf([GWEI]), - value: PropTypes.string, - numberOfDecimals: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), - hideLabel: PropTypes.bool, - hideTitle: PropTypes.bool, - } - - render () { - const { className, displayValue, prefix, prefixComponent, style, suffix, hideTitle } = this.props - const text = `${prefix || ''}${displayValue}` - const title = `${text} ${suffix}` - - return ( - <div - className={classnames('currency-display-component', className)} - style={style} - title={!hideTitle && title || null} - > - { prefixComponent } - <span className="currency-display-component__text">{ text }</span> - { - suffix && ( - <span className="currency-display-component__suffix"> - { suffix } - </span> - ) - } - </div> - ) - } -} diff --git a/ui/app/components/currency-display/currency-display.container.js b/ui/app/components/currency-display/currency-display.container.js deleted file mode 100644 index e581f8a5e..000000000 --- a/ui/app/components/currency-display/currency-display.container.js +++ /dev/null @@ -1,51 +0,0 @@ -import { connect } from 'react-redux' -import CurrencyDisplay from './currency-display.component' -import { getValueFromWeiHex, formatCurrency } from '../../helpers/confirm-transaction/util' - -const mapStateToProps = state => { - const { metamask: { nativeCurrency, currentCurrency, conversionRate } } = state - - return { - currentCurrency, - conversionRate, - nativeCurrency, - } -} - -const mergeProps = (stateProps, dispatchProps, ownProps) => { - const { nativeCurrency, currentCurrency, conversionRate, ...restStateProps } = stateProps - const { - value, - numberOfDecimals = 2, - currency, - denomination, - hideLabel, - displayValue: propsDisplayValue, - suffix: propsSuffix, - ...restOwnProps - } = ownProps - - const toCurrency = currency || currentCurrency - - const displayValue = propsDisplayValue || formatCurrency( - getValueFromWeiHex({ - value, - fromCurrency: nativeCurrency, - toCurrency, conversionRate, - numberOfDecimals, - toDenomination: denomination, - }), - toCurrency - ) - const suffix = propsSuffix || (hideLabel ? undefined : toCurrency.toUpperCase()) - - return { - ...restStateProps, - ...dispatchProps, - ...restOwnProps, - displayValue, - suffix, - } -} - -export default connect(mapStateToProps, null, mergeProps)(CurrencyDisplay) diff --git a/ui/app/components/currency-display/index.js b/ui/app/components/currency-display/index.js deleted file mode 100644 index 38f08765f..000000000 --- a/ui/app/components/currency-display/index.js +++ /dev/null @@ -1 +0,0 @@ -export { default } from './currency-display.container' diff --git a/ui/app/components/currency-display/index.scss b/ui/app/components/currency-display/index.scss deleted file mode 100644 index 313c932b8..000000000 --- a/ui/app/components/currency-display/index.scss +++ /dev/null @@ -1,14 +0,0 @@ -.currency-display-component { - display: flex; - align-items: center; - - &__text { - white-space: nowrap; - overflow: hidden; - text-overflow: ellipsis; - } - - &__suffix { - padding-left: 4px; - } -} diff --git a/ui/app/components/currency-display/tests/currency-display.component.test.js b/ui/app/components/currency-display/tests/currency-display.component.test.js deleted file mode 100644 index d9ef052f1..000000000 --- a/ui/app/components/currency-display/tests/currency-display.component.test.js +++ /dev/null @@ -1,27 +0,0 @@ -import React from 'react' -import assert from 'assert' -import { shallow } from 'enzyme' -import CurrencyDisplay from '../currency-display.component' - -describe('CurrencyDisplay Component', () => { - it('should render text with a className', () => { - const wrapper = shallow(<CurrencyDisplay - displayValue="$123.45" - className="currency-display" - />) - - assert.ok(wrapper.hasClass('currency-display')) - assert.equal(wrapper.text(), '$123.45') - }) - - it('should render text with a prefix', () => { - const wrapper = shallow(<CurrencyDisplay - displayValue="$123.45" - className="currency-display" - prefix="-" - />) - - assert.ok(wrapper.hasClass('currency-display')) - assert.equal(wrapper.text(), '-$123.45') - }) -}) diff --git a/ui/app/components/currency-display/tests/currency-display.container.test.js b/ui/app/components/currency-display/tests/currency-display.container.test.js deleted file mode 100644 index 9888c366e..000000000 --- a/ui/app/components/currency-display/tests/currency-display.container.test.js +++ /dev/null @@ -1,145 +0,0 @@ -import assert from 'assert' -import proxyquire from 'proxyquire' - -let mapStateToProps, mergeProps - -proxyquire('../currency-display.container.js', { - 'react-redux': { - connect: (ms, md, mp) => { - mapStateToProps = ms - mergeProps = mp - return () => ({}) - }, - }, -}) - -describe('CurrencyDisplay container', () => { - describe('mapStateToProps()', () => { - it('should return the correct props', () => { - const mockState = { - metamask: { - conversionRate: 280.45, - currentCurrency: 'usd', - nativeCurrency: 'ETH', - }, - } - - assert.deepEqual(mapStateToProps(mockState), { - conversionRate: 280.45, - currentCurrency: 'usd', - nativeCurrency: 'ETH', - }) - }) - }) - - describe('mergeProps()', () => { - it('should return the correct props', () => { - const mockStateProps = { - conversionRate: 280.45, - currentCurrency: 'usd', - nativeCurrency: 'ETH', - } - - const tests = [ - { - props: { - value: '0x2386f26fc10000', - numberOfDecimals: 2, - currency: 'usd', - nativeCurrency: 'ETH', - }, - result: { - displayValue: '$2.80', - suffix: 'USD', - nativeCurrency: 'ETH', - }, - }, - { - props: { - value: '0x2386f26fc10000', - currency: 'usd', - nativeCurrency: 'ETH', - }, - result: { - displayValue: '$2.80', - suffix: 'USD', - nativeCurrency: 'ETH', - }, - }, - { - props: { - value: '0x1193461d01595930', - currency: 'ETH', - nativeCurrency: 'ETH', - numberOfDecimals: 3, - }, - result: { - displayValue: '1.266', - suffix: 'ETH', - nativeCurrency: 'ETH', - }, - }, - { - props: { - value: '0x1193461d01595930', - currency: 'ETH', - nativeCurrency: 'ETH', - numberOfDecimals: 3, - hideLabel: true, - }, - result: { - nativeCurrency: 'ETH', - displayValue: '1.266', - suffix: undefined, - }, - }, - { - props: { - value: '0x3b9aca00', - currency: 'ETH', - nativeCurrency: 'ETH', - denomination: 'GWEI', - hideLabel: true, - }, - result: { - nativeCurrency: 'ETH', - displayValue: '1', - suffix: undefined, - }, - }, - { - props: { - value: '0x3b9aca00', - currency: 'ETH', - nativeCurrency: 'ETH', - denomination: 'WEI', - hideLabel: true, - }, - result: { - nativeCurrency: 'ETH', - displayValue: '1000000000', - suffix: undefined, - }, - }, - { - props: { - value: '0x3b9aca00', - currency: 'ETH', - nativeCurrency: 'ETH', - numberOfDecimals: 100, - hideLabel: true, - }, - result: { - nativeCurrency: 'ETH', - displayValue: '0.000000001', - suffix: undefined, - }, - }, - ] - - tests.forEach(({ props, result }) => { - assert.deepEqual(mergeProps(mockStateProps, {}, { ...props }), result) - }) - }) - }) -}) |