diff options
Diffstat (limited to 'ui/app/components/user-preferenced-currency-display')
5 files changed, 0 insertions, 351 deletions
diff --git a/ui/app/components/user-preferenced-currency-display/index.js b/ui/app/components/user-preferenced-currency-display/index.js deleted file mode 100644 index 0deddaecf..000000000 --- a/ui/app/components/user-preferenced-currency-display/index.js +++ /dev/null @@ -1 +0,0 @@ -export { default } from './user-preferenced-currency-display.container' diff --git a/ui/app/components/user-preferenced-currency-display/tests/user-preferenced-currency-display.component.test.js b/ui/app/components/user-preferenced-currency-display/tests/user-preferenced-currency-display.component.test.js deleted file mode 100644 index ead584c26..000000000 --- a/ui/app/components/user-preferenced-currency-display/tests/user-preferenced-currency-display.component.test.js +++ /dev/null @@ -1,34 +0,0 @@ -import React from 'react' -import assert from 'assert' -import { shallow } from 'enzyme' -import UserPreferencedCurrencyDisplay from '../user-preferenced-currency-display.component' -import CurrencyDisplay from '../../currency-display' - -describe('UserPreferencedCurrencyDisplay Component', () => { - describe('rendering', () => { - it('should render properly', () => { - const wrapper = shallow( - <UserPreferencedCurrencyDisplay /> - ) - - assert.ok(wrapper) - assert.equal(wrapper.find(CurrencyDisplay).length, 1) - }) - - it('should pass all props to the CurrencyDisplay child component', () => { - const wrapper = shallow( - <UserPreferencedCurrencyDisplay - prop1={true} - prop2="test" - prop3={1} - /> - ) - - assert.ok(wrapper) - assert.equal(wrapper.find(CurrencyDisplay).length, 1) - assert.equal(wrapper.find(CurrencyDisplay).props().prop1, true) - assert.equal(wrapper.find(CurrencyDisplay).props().prop2, 'test') - assert.equal(wrapper.find(CurrencyDisplay).props().prop3, 1) - }) - }) -}) diff --git a/ui/app/components/user-preferenced-currency-display/tests/user-preferenced-currency-display.container.test.js b/ui/app/components/user-preferenced-currency-display/tests/user-preferenced-currency-display.container.test.js deleted file mode 100644 index 88d63baae..000000000 --- a/ui/app/components/user-preferenced-currency-display/tests/user-preferenced-currency-display.container.test.js +++ /dev/null @@ -1,202 +0,0 @@ -import assert from 'assert' -import proxyquire from 'proxyquire' - -let mapStateToProps, mergeProps - -proxyquire('../user-preferenced-currency-display.container.js', { - 'react-redux': { - connect: (ms, md, mp) => { - mapStateToProps = ms - mergeProps = mp - return () => ({}) - }, - }, -}) - -describe('UserPreferencedCurrencyDisplay container', () => { - describe('mapStateToProps()', () => { - it('should return the correct props', () => { - const mockState = { - metamask: { - nativeCurrency: 'ETH', - preferences: { - useNativeCurrencyAsPrimaryCurrency: true, - showFiatInTestnets: false, - }, - provider: { - type: 'mainnet', - }, - }, - } - - assert.deepEqual(mapStateToProps(mockState), { - nativeCurrency: 'ETH', - useNativeCurrencyAsPrimaryCurrency: true, - isMainnet: true, - showFiatInTestnets: false, - }) - }) - - it('should return the correct props when not in mainnet and showFiatInTestnets is true', () => { - const mockState = { - metamask: { - nativeCurrency: 'ETH', - preferences: { - useNativeCurrencyAsPrimaryCurrency: true, - showFiatInTestnets: true, - }, - provider: { - type: 'rinkeby', - }, - }, - } - - assert.deepEqual(mapStateToProps(mockState), { - nativeCurrency: 'ETH', - useNativeCurrencyAsPrimaryCurrency: true, - isMainnet: false, - showFiatInTestnets: true, - }) - }) - }) - - describe('mergeProps()', () => { - it('should return the correct props', () => { - const mockDispatchProps = {} - - const tests = [ - { - stateProps: { - useNativeCurrencyAsPrimaryCurrency: true, - nativeCurrency: 'ETH', - isMainnet: true, - showFiatInTestnets: false, - }, - ownProps: { - type: 'PRIMARY', - }, - result: { - currency: 'ETH', - nativeCurrency: 'ETH', - numberOfDecimals: 6, - prefix: undefined, - }, - }, - { - stateProps: { - useNativeCurrencyAsPrimaryCurrency: false, - nativeCurrency: 'ETH', - isMainnet: true, - showFiatInTestnets: false, - }, - ownProps: { - type: 'PRIMARY', - }, - result: { - currency: undefined, - nativeCurrency: 'ETH', - numberOfDecimals: 2, - prefix: undefined, - }, - }, - { - stateProps: { - useNativeCurrencyAsPrimaryCurrency: true, - nativeCurrency: 'ETH', - isMainnet: true, - showFiatInTestnets: false, - }, - ownProps: { - type: 'SECONDARY', - fiatNumberOfDecimals: 4, - fiatPrefix: '-', - }, - result: { - nativeCurrency: 'ETH', - currency: undefined, - numberOfDecimals: 4, - prefix: '-', - }, - }, - { - stateProps: { - useNativeCurrencyAsPrimaryCurrency: false, - nativeCurrency: 'ETH', - isMainnet: true, - showFiatInTestnets: false, - }, - ownProps: { - type: 'SECONDARY', - fiatNumberOfDecimals: 4, - numberOfDecimals: 3, - fiatPrefix: 'a', - prefix: 'b', - }, - result: { - currency: 'ETH', - nativeCurrency: 'ETH', - numberOfDecimals: 3, - prefix: 'b', - }, - }, - { - stateProps: { - useNativeCurrencyAsPrimaryCurrency: false, - nativeCurrency: 'ETH', - isMainnet: false, - showFiatInTestnets: false, - }, - ownProps: { - type: 'PRIMARY', - }, - result: { - currency: 'ETH', - nativeCurrency: 'ETH', - numberOfDecimals: 6, - prefix: undefined, - }, - }, - { - stateProps: { - useNativeCurrencyAsPrimaryCurrency: false, - nativeCurrency: 'ETH', - isMainnet: false, - showFiatInTestnets: true, - }, - ownProps: { - type: 'PRIMARY', - }, - result: { - currency: undefined, - nativeCurrency: 'ETH', - numberOfDecimals: 2, - prefix: undefined, - }, - }, - { - stateProps: { - useNativeCurrencyAsPrimaryCurrency: false, - nativeCurrency: 'ETH', - isMainnet: true, - showFiatInTestnets: true, - }, - ownProps: { - type: 'PRIMARY', - }, - result: { - currency: undefined, - nativeCurrency: 'ETH', - numberOfDecimals: 2, - prefix: undefined, - }, - }, - ] - - tests.forEach(({ stateProps, ownProps, result }) => { - assert.deepEqual(mergeProps({ ...stateProps }, mockDispatchProps, { ...ownProps }), { - ...result, - }) - }) - }) - }) -}) diff --git a/ui/app/components/user-preferenced-currency-display/user-preferenced-currency-display.component.js b/ui/app/components/user-preferenced-currency-display/user-preferenced-currency-display.component.js deleted file mode 100644 index d9f29327d..000000000 --- a/ui/app/components/user-preferenced-currency-display/user-preferenced-currency-display.component.js +++ /dev/null @@ -1,47 +0,0 @@ -import React, { PureComponent } from 'react' -import PropTypes from 'prop-types' -import { PRIMARY, SECONDARY, ETH } from '../../constants/common' -import CurrencyDisplay from '../currency-display' - -export default class UserPreferencedCurrencyDisplay extends PureComponent { - static propTypes = { - className: PropTypes.string, - prefix: PropTypes.string, - value: PropTypes.string, - numberOfDecimals: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), - hideLabel: PropTypes.bool, - hideTitle: PropTypes.bool, - style: PropTypes.object, - showEthLogo: PropTypes.bool, - ethLogoHeight: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), - // Used in container - type: PropTypes.oneOf([PRIMARY, SECONDARY]), - ethNumberOfDecimals: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), - fiatNumberOfDecimals: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), - ethPrefix: PropTypes.string, - fiatPrefix: PropTypes.string, - // From container - currency: PropTypes.string, - nativeCurrency: PropTypes.string, - } - - renderEthLogo () { - const { currency, showEthLogo, ethLogoHeight = 12 } = this.props - - return currency === ETH && showEthLogo && ( - <img - src="/images/eth.svg" - height={ethLogoHeight} - /> - ) - } - - render () { - return ( - <CurrencyDisplay - {...this.props} - prefixComponent={this.renderEthLogo()} - /> - ) - } -} diff --git a/ui/app/components/user-preferenced-currency-display/user-preferenced-currency-display.container.js b/ui/app/components/user-preferenced-currency-display/user-preferenced-currency-display.container.js deleted file mode 100644 index 3c5bd0f21..000000000 --- a/ui/app/components/user-preferenced-currency-display/user-preferenced-currency-display.container.js +++ /dev/null @@ -1,67 +0,0 @@ -import { connect } from 'react-redux' -import UserPreferencedCurrencyDisplay from './user-preferenced-currency-display.component' -import { preferencesSelector, getIsMainnet } from '../../selectors' -import { ETH, PRIMARY, SECONDARY } from '../../constants/common' - -const mapStateToProps = (state, ownProps) => { - const { - useNativeCurrencyAsPrimaryCurrency, - showFiatInTestnets, - } = preferencesSelector(state) - - const isMainnet = getIsMainnet(state) - - return { - useNativeCurrencyAsPrimaryCurrency, - showFiatInTestnets, - isMainnet, - nativeCurrency: state.metamask.nativeCurrency, - } -} - -const mergeProps = (stateProps, dispatchProps, ownProps) => { - const { useNativeCurrencyAsPrimaryCurrency, showFiatInTestnets, isMainnet, nativeCurrency, ...restStateProps } = stateProps - const { - type, - numberOfDecimals: propsNumberOfDecimals, - ethNumberOfDecimals, - fiatNumberOfDecimals, - ethPrefix, - fiatPrefix, - prefix: propsPrefix, - ...restOwnProps - } = ownProps - - let currency, numberOfDecimals, prefix - - if (type === PRIMARY && useNativeCurrencyAsPrimaryCurrency || - type === SECONDARY && !useNativeCurrencyAsPrimaryCurrency) { - // Display ETH - currency = nativeCurrency || ETH - numberOfDecimals = propsNumberOfDecimals || ethNumberOfDecimals || 6 - prefix = propsPrefix || ethPrefix - } else if (type === SECONDARY && useNativeCurrencyAsPrimaryCurrency || - type === PRIMARY && !useNativeCurrencyAsPrimaryCurrency) { - // Display Fiat - numberOfDecimals = propsNumberOfDecimals || fiatNumberOfDecimals || 2 - prefix = propsPrefix || fiatPrefix - } - - if (!isMainnet && !showFiatInTestnets) { - currency = nativeCurrency || ETH - numberOfDecimals = propsNumberOfDecimals || ethNumberOfDecimals || 6 - prefix = propsPrefix || ethPrefix - } - - return { - ...restStateProps, - ...dispatchProps, - ...restOwnProps, - nativeCurrency, - currency, - numberOfDecimals, - prefix, - } -} - -export default connect(mapStateToProps, null, mergeProps)(UserPreferencedCurrencyDisplay) |