aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/currency-input
diff options
context:
space:
mode:
authorChi Kei Chan <chikeichan@gmail.com>2019-03-22 07:03:30 +0800
committerDan J Miller <danjm.com@gmail.com>2019-03-22 07:03:30 +0800
commit31175625b446cb5d18b17db23018bca8b14d280c (patch)
treef54e159883deef003fb281267025edf796eb8004 /ui/app/components/currency-input
parent7287133e15fab22299e07704206e85bc855d1064 (diff)
downloadtangerine-wallet-browser-31175625b446cb5d18b17db23018bca8b14d280c.tar.gz
tangerine-wallet-browser-31175625b446cb5d18b17db23018bca8b14d280c.tar.zst
tangerine-wallet-browser-31175625b446cb5d18b17db23018bca8b14d280c.zip
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
Diffstat (limited to 'ui/app/components/currency-input')
-rw-r--r--ui/app/components/currency-input/currency-input.component.js160
-rw-r--r--ui/app/components/currency-input/currency-input.container.js31
-rw-r--r--ui/app/components/currency-input/index.js1
-rw-r--r--ui/app/components/currency-input/index.scss26
-rw-r--r--ui/app/components/currency-input/tests/currency-input.component.test.js345
-rw-r--r--ui/app/components/currency-input/tests/currency-input.container.test.js170
6 files changed, 0 insertions, 733 deletions
diff --git a/ui/app/components/currency-input/currency-input.component.js b/ui/app/components/currency-input/currency-input.component.js
deleted file mode 100644
index 30e0e919b..000000000
--- a/ui/app/components/currency-input/currency-input.component.js
+++ /dev/null
@@ -1,160 +0,0 @@
-import React, { PureComponent } from 'react'
-import PropTypes from 'prop-types'
-import UnitInput from '../unit-input'
-import CurrencyDisplay from '../currency-display'
-import { getValueFromWeiHex, getWeiHexFromDecimalValue } from '../../helpers/conversions.util'
-import { ETH } from '../../constants/common'
-
-/**
- * Component that allows user to enter currency values as a number, and props receive a converted
- * hex value in WEI. props.value, used as a default or forced value, should be a hex value, which
- * gets converted into a decimal value depending on the currency (ETH or Fiat).
- */
-export default class CurrencyInput extends PureComponent {
- static contextTypes = {
- t: PropTypes.func,
- }
-
- static propTypes = {
- conversionRate: PropTypes.number,
- currentCurrency: PropTypes.string,
- nativeCurrency: PropTypes.string,
- onChange: PropTypes.func,
- onBlur: PropTypes.func,
- useFiat: PropTypes.bool,
- hideFiat: PropTypes.bool,
- value: PropTypes.string,
- fiatSuffix: PropTypes.string,
- nativeSuffix: PropTypes.string,
- }
-
- constructor (props) {
- super(props)
-
- const { value: hexValue } = props
- const decimalValue = hexValue ? this.getDecimalValue(props) : 0
-
- this.state = {
- decimalValue,
- hexValue,
- isSwapped: false,
- }
- }
-
- componentDidUpdate (prevProps) {
- const { value: prevPropsHexValue } = prevProps
- const { value: propsHexValue } = this.props
- const { hexValue: stateHexValue } = this.state
-
- if (prevPropsHexValue !== propsHexValue && propsHexValue !== stateHexValue) {
- const decimalValue = this.getDecimalValue(this.props)
- this.setState({ hexValue: propsHexValue, decimalValue })
- }
- }
-
- getDecimalValue (props) {
- const { value: hexValue, currentCurrency, conversionRate } = props
- const decimalValueString = this.shouldUseFiat()
- ? getValueFromWeiHex({
- value: hexValue, toCurrency: currentCurrency, conversionRate, numberOfDecimals: 2,
- })
- : getValueFromWeiHex({
- value: hexValue, toCurrency: ETH, numberOfDecimals: 6,
- })
-
- return Number(decimalValueString) || 0
- }
-
- shouldUseFiat = () => {
- const { useFiat, hideFiat } = this.props
- const { isSwapped } = this.state || {}
-
- if (hideFiat) {
- return false
- }
-
- return isSwapped ? !useFiat : useFiat
- }
-
- swap = () => {
- const { isSwapped, decimalValue } = this.state
- this.setState({isSwapped: !isSwapped}, () => {
- this.handleChange(decimalValue)
- })
- }
-
- handleChange = decimalValue => {
- const { currentCurrency: fromCurrency, conversionRate, onChange } = this.props
-
- const hexValue = this.shouldUseFiat()
- ? getWeiHexFromDecimalValue({
- value: decimalValue, fromCurrency, conversionRate, invertConversionRate: true,
- })
- : getWeiHexFromDecimalValue({
- value: decimalValue, fromCurrency: ETH, fromDenomination: ETH, conversionRate,
- })
-
- this.setState({ hexValue, decimalValue })
- onChange(hexValue)
- }
-
- handleBlur = () => {
- this.props.onBlur(this.state.hexValue)
- }
-
- renderConversionComponent () {
- const { currentCurrency, nativeCurrency, hideFiat } = this.props
- const { hexValue } = this.state
- let currency, numberOfDecimals
-
- if (hideFiat) {
- return (
- <div className="currency-input__conversion-component">
- { this.context.t('noConversionRateAvailable') }
- </div>
- )
- }
-
- if (this.shouldUseFiat()) {
- // Display ETH
- currency = nativeCurrency || ETH
- numberOfDecimals = 6
- } else {
- // Display Fiat
- currency = currentCurrency
- numberOfDecimals = 2
- }
-
- return (
- <CurrencyDisplay
- className="currency-input__conversion-component"
- currency={currency}
- value={hexValue}
- numberOfDecimals={numberOfDecimals}
- />
- )
- }
-
- render () {
- const { fiatSuffix, nativeSuffix, ...restProps } = this.props
- const { decimalValue } = this.state
-
- return (
- <UnitInput
- {...restProps}
- suffix={this.shouldUseFiat() ? fiatSuffix : nativeSuffix}
- onChange={this.handleChange}
- onBlur={this.handleBlur}
- value={decimalValue}
- actionComponent={(
- <div
- className="currency-input__swap-component"
- onClick={this.swap}
- />
- )}
- >
- { this.renderConversionComponent() }
- </UnitInput>
- )
- }
-}
diff --git a/ui/app/components/currency-input/currency-input.container.js b/ui/app/components/currency-input/currency-input.container.js
deleted file mode 100644
index 428be4557..000000000
--- a/ui/app/components/currency-input/currency-input.container.js
+++ /dev/null
@@ -1,31 +0,0 @@
-import { connect } from 'react-redux'
-import CurrencyInput from './currency-input.component'
-import { ETH } from '../../constants/common'
-import {getIsMainnet, preferencesSelector} from '../../selectors'
-
-const mapStateToProps = state => {
- const { metamask: { nativeCurrency, currentCurrency, conversionRate } } = state
- const { showFiatInTestnets } = preferencesSelector(state)
- const isMainnet = getIsMainnet(state)
-
- return {
- nativeCurrency,
- currentCurrency,
- conversionRate,
- hideFiat: (!isMainnet && !showFiatInTestnets),
- }
-}
-
-const mergeProps = (stateProps, dispatchProps, ownProps) => {
- const { nativeCurrency, currentCurrency } = stateProps
-
- return {
- ...stateProps,
- ...dispatchProps,
- ...ownProps,
- nativeSuffix: nativeCurrency || ETH,
- fiatSuffix: currentCurrency.toUpperCase(),
- }
-}
-
-export default connect(mapStateToProps, null, mergeProps)(CurrencyInput)
diff --git a/ui/app/components/currency-input/index.js b/ui/app/components/currency-input/index.js
deleted file mode 100644
index d8069fb67..000000000
--- a/ui/app/components/currency-input/index.js
+++ /dev/null
@@ -1 +0,0 @@
-export { default } from './currency-input.container'
diff --git a/ui/app/components/currency-input/index.scss b/ui/app/components/currency-input/index.scss
deleted file mode 100644
index f659f5b35..000000000
--- a/ui/app/components/currency-input/index.scss
+++ /dev/null
@@ -1,26 +0,0 @@
-.currency-input {
- &__conversion-component {
- font-size: 12px;
- line-height: 12px;
- padding-left: 1px;
- }
-
- &__swap-component {
- flex: 0 0 auto;
- height: 24px;
- width: 24px;
- background-image: url("images/icons/swap.svg");
- background-size: contain;
- background-repeat: no-repeat;
- cursor: pointer;
- opacity: .4;
-
- &:hover {
- opacity: .3;
- }
-
- &:active {
- opacity: .5;
- }
- }
-}
diff --git a/ui/app/components/currency-input/tests/currency-input.component.test.js b/ui/app/components/currency-input/tests/currency-input.component.test.js
deleted file mode 100644
index 6d4612e3c..000000000
--- a/ui/app/components/currency-input/tests/currency-input.component.test.js
+++ /dev/null
@@ -1,345 +0,0 @@
-import React from 'react'
-import PropTypes from 'prop-types'
-import assert from 'assert'
-import { shallow, mount } from 'enzyme'
-import sinon from 'sinon'
-import { Provider } from 'react-redux'
-import configureMockStore from 'redux-mock-store'
-import CurrencyInput from '../currency-input.component'
-import UnitInput from '../../unit-input'
-import CurrencyDisplay from '../../currency-display'
-
-describe('CurrencyInput Component', () => {
- describe('rendering', () => {
- it('should render properly without a suffix', () => {
- const wrapper = shallow(
- <CurrencyInput />
- )
-
- assert.ok(wrapper)
- assert.equal(wrapper.find(UnitInput).length, 1)
- })
-
- it('should render properly with a suffix', () => {
- const mockStore = {
- metamask: {
- nativeCurrency: 'ETH',
- currentCurrency: 'usd',
- conversionRate: 231.06,
- },
- }
- const store = configureMockStore()(mockStore)
-
- const wrapper = mount(
- <Provider store={store}>
- <CurrencyInput
- nativeSuffix="ETH"
- fiatSuffix="USD"
- nativeCurrency="ETH"
- />
- </Provider>
- )
-
- assert.ok(wrapper)
- assert.equal(wrapper.find('.unit-input__suffix').length, 1)
- assert.equal(wrapper.find('.unit-input__suffix').text(), 'ETH')
- assert.equal(wrapper.find(CurrencyDisplay).length, 1)
- })
-
- it('should render properly with an ETH value', () => {
- const mockStore = {
- metamask: {
- nativeCurrency: 'ETH',
- currentCurrency: 'usd',
- conversionRate: 231.06,
- },
- }
- const store = configureMockStore()(mockStore)
-
- const wrapper = mount(
- <Provider store={store}>
- <CurrencyInput
- value="de0b6b3a7640000"
- fiatSuffix="USD"
- nativeSuffix="ETH"
- nativeCurrency="ETH"
- currentCurrency="usd"
- conversionRate={231.06}
- />
- </Provider>
- )
-
- assert.ok(wrapper)
- const currencyInputInstance = wrapper.find(CurrencyInput).at(0).instance()
- assert.equal(currencyInputInstance.state.decimalValue, 1)
- assert.equal(currencyInputInstance.state.hexValue, 'de0b6b3a7640000')
- assert.equal(wrapper.find('.unit-input__suffix').length, 1)
- assert.equal(wrapper.find('.unit-input__suffix').text(), 'ETH')
- assert.equal(wrapper.find('.unit-input__input').props().value, '1')
- assert.equal(wrapper.find('.currency-display-component').text(), '$231.06USD')
- })
-
- it('should render properly with a fiat value', () => {
- const mockStore = {
- metamask: {
- nativeCurrency: 'ETH',
- currentCurrency: 'usd',
- conversionRate: 231.06,
- },
- }
- const store = configureMockStore()(mockStore)
-
- const wrapper = mount(
- <Provider store={store}>
- <CurrencyInput
- value="f602f2234d0ea"
- fiatSuffix="USD"
- nativeSuffix="ETH"
- useFiat
- nativeCurrency="ETH"
- currentCurrency="usd"
- conversionRate={231.06}
- />
- </Provider>
- )
-
- assert.ok(wrapper)
- const currencyInputInstance = wrapper.find(CurrencyInput).at(0).instance()
- assert.equal(currencyInputInstance.state.decimalValue, 1)
- assert.equal(currencyInputInstance.state.hexValue, 'f602f2234d0ea')
- assert.equal(wrapper.find('.unit-input__suffix').length, 1)
- assert.equal(wrapper.find('.unit-input__suffix').text(), 'USD')
- assert.equal(wrapper.find('.unit-input__input').props().value, '1')
- assert.equal(wrapper.find('.currency-display-component').text(), '0.004328ETH')
- })
-
- it('should render properly with a native value when hideFiat is true', () => {
- const mockStore = {
- metamask: {
- nativeCurrency: 'ETH',
- currentCurrency: 'usd',
- conversionRate: 231.06,
- },
- }
- const store = configureMockStore()(mockStore)
-
- const wrapper = mount(
- <Provider store={store}>
- <CurrencyInput
- value="f602f2234d0ea"
- fiatSuffix="USD"
- nativeSuffix="ETH"
- useFiat
- hideFiat={true}
- nativeCurrency="ETH"
- currentCurrency="usd"
- conversionRate={231.06}
- />
- </Provider>,
- {
- context: { t: str => str + '_t' },
- childContextTypes: { t: PropTypes.func },
- }
- )
-
- assert.ok(wrapper)
- const currencyInputInstance = wrapper.find(CurrencyInput).at(0).instance()
- assert.equal(currencyInputInstance.state.decimalValue, 0.004328)
- assert.equal(currencyInputInstance.state.hexValue, 'f602f2234d0ea')
- assert.equal(wrapper.find('.unit-input__suffix').length, 1)
- assert.equal(wrapper.find('.unit-input__suffix').text(), 'ETH')
- assert.equal(wrapper.find('.unit-input__input').props().value, '0.004328')
- assert.equal(wrapper.find('.currency-input__conversion-component').text(), 'noConversionRateAvailable_t')
- })
- })
-
- describe('handling actions', () => {
- const handleChangeSpy = sinon.spy()
- const handleBlurSpy = sinon.spy()
-
- afterEach(() => {
- handleChangeSpy.resetHistory()
- handleBlurSpy.resetHistory()
- })
-
- it('should call onChange and onBlur on input changes with the hex value for ETH', () => {
- const mockStore = {
- metamask: {
- nativeCurrency: 'ETH',
- currentCurrency: 'usd',
- conversionRate: 231.06,
- },
- }
- const store = configureMockStore()(mockStore)
- const wrapper = mount(
- <Provider store={store}>
- <CurrencyInput
- onChange={handleChangeSpy}
- onBlur={handleBlurSpy}
- suffix="ETH"
- nativeCurrency="ETH"
- currentCurrency="usd"
- conversionRate={231.06}
- />
- </Provider>
- )
-
- assert.ok(wrapper)
- assert.equal(handleChangeSpy.callCount, 0)
- assert.equal(handleBlurSpy.callCount, 0)
-
- const currencyInputInstance = wrapper.find(CurrencyInput).at(0).instance()
- assert.equal(currencyInputInstance.state.decimalValue, 0)
- assert.equal(currencyInputInstance.state.hexValue, undefined)
- assert.equal(wrapper.find('.currency-display-component').text(), '$0.00USD')
- const input = wrapper.find('input')
- assert.equal(input.props().value, 0)
-
- input.simulate('change', { target: { value: 1 } })
- assert.equal(handleChangeSpy.callCount, 1)
- assert.ok(handleChangeSpy.calledWith('de0b6b3a7640000'))
- assert.equal(wrapper.find('.currency-display-component').text(), '$231.06USD')
- assert.equal(currencyInputInstance.state.decimalValue, 1)
- assert.equal(currencyInputInstance.state.hexValue, 'de0b6b3a7640000')
-
- assert.equal(handleBlurSpy.callCount, 0)
- input.simulate('blur')
- assert.equal(handleBlurSpy.callCount, 1)
- assert.ok(handleBlurSpy.calledWith('de0b6b3a7640000'))
- })
-
- it('should call onChange and onBlur on input changes with the hex value for fiat', () => {
- const mockStore = {
- metamask: {
- nativeCurrency: 'ETH',
- currentCurrency: 'usd',
- conversionRate: 231.06,
- },
- }
- const store = configureMockStore()(mockStore)
- const wrapper = mount(
- <Provider store={store}>
- <CurrencyInput
- onChange={handleChangeSpy}
- onBlur={handleBlurSpy}
- suffix="USD"
- nativeCurrency="ETH"
- currentCurrency="usd"
- conversionRate={231.06}
- useFiat
- />
- </Provider>
- )
-
- assert.ok(wrapper)
- assert.equal(handleChangeSpy.callCount, 0)
- assert.equal(handleBlurSpy.callCount, 0)
-
- const currencyInputInstance = wrapper.find(CurrencyInput).at(0).instance()
- assert.equal(currencyInputInstance.state.decimalValue, 0)
- assert.equal(currencyInputInstance.state.hexValue, undefined)
- assert.equal(wrapper.find('.currency-display-component').text(), '0ETH')
- const input = wrapper.find('input')
- assert.equal(input.props().value, 0)
-
- input.simulate('change', { target: { value: 1 } })
- assert.equal(handleChangeSpy.callCount, 1)
- assert.ok(handleChangeSpy.calledWith('f602f2234d0ea'))
- assert.equal(wrapper.find('.currency-display-component').text(), '0.004328ETH')
- assert.equal(currencyInputInstance.state.decimalValue, 1)
- assert.equal(currencyInputInstance.state.hexValue, 'f602f2234d0ea')
-
- assert.equal(handleBlurSpy.callCount, 0)
- input.simulate('blur')
- assert.equal(handleBlurSpy.callCount, 1)
- assert.ok(handleBlurSpy.calledWith('f602f2234d0ea'))
- })
-
- it('should change the state and pass in a new decimalValue when props.value changes', () => {
- const mockStore = {
- metamask: {
- nativeCurrency: 'ETH',
- currentCurrency: 'usd',
- conversionRate: 231.06,
- },
- }
- const store = configureMockStore()(mockStore)
- const wrapper = shallow(
- <Provider store={store}>
- <CurrencyInput
- onChange={handleChangeSpy}
- onBlur={handleBlurSpy}
- suffix="USD"
- nativeCurrency="ETH"
- currentCurrency="usd"
- conversionRate={231.06}
- useFiat
- />
- </Provider>
- )
-
- assert.ok(wrapper)
- const currencyInputInstance = wrapper.find(CurrencyInput).dive()
- assert.equal(currencyInputInstance.state('decimalValue'), 0)
- assert.equal(currencyInputInstance.state('hexValue'), undefined)
- assert.equal(currencyInputInstance.find(UnitInput).props().value, 0)
-
- currencyInputInstance.setProps({ value: '1ec05e43e72400' })
- currencyInputInstance.update()
- assert.equal(currencyInputInstance.state('decimalValue'), 2)
- assert.equal(currencyInputInstance.state('hexValue'), '1ec05e43e72400')
- assert.equal(currencyInputInstance.find(UnitInput).props().value, 2)
- })
-
- it('should swap selected currency when swap icon is clicked', () => {
- const mockStore = {
- metamask: {
- nativeCurrency: 'ETH',
- currentCurrency: 'usd',
- conversionRate: 231.06,
- },
- }
- const store = configureMockStore()(mockStore)
- const wrapper = mount(
- <Provider store={store}>
- <CurrencyInput
- onChange={handleChangeSpy}
- onBlur={handleBlurSpy}
- nativeSuffix="ETH"
- fiatSuffix="USD"
- nativeCurrency="ETH"
- currentCurrency="usd"
- conversionRate={231.06}
- />
- </Provider>
- )
-
- assert.ok(wrapper)
- assert.equal(handleChangeSpy.callCount, 0)
- assert.equal(handleBlurSpy.callCount, 0)
-
- const currencyInputInstance = wrapper.find(CurrencyInput).at(0).instance()
- assert.equal(currencyInputInstance.state.decimalValue, 0)
- assert.equal(currencyInputInstance.state.hexValue, undefined)
- assert.equal(wrapper.find('.currency-display-component').text(), '$0.00USD')
- const input = wrapper.find('input')
- assert.equal(input.props().value, 0)
-
- input.simulate('change', { target: { value: 1 } })
- assert.equal(handleChangeSpy.callCount, 1)
- assert.ok(handleChangeSpy.calledWith('de0b6b3a7640000'))
- assert.equal(wrapper.find('.currency-display-component').text(), '$231.06USD')
- assert.equal(currencyInputInstance.state.decimalValue, 1)
- assert.equal(currencyInputInstance.state.hexValue, 'de0b6b3a7640000')
-
- assert.equal(handleBlurSpy.callCount, 0)
- input.simulate('blur')
- assert.equal(handleBlurSpy.callCount, 1)
- assert.ok(handleBlurSpy.calledWith('de0b6b3a7640000'))
-
- const swap = wrapper.find('.currency-input__swap-component')
- swap.simulate('click')
- assert.equal(wrapper.find('.currency-display-component').text(), '0.004328ETH')
- })
- })
-})
diff --git a/ui/app/components/currency-input/tests/currency-input.container.test.js b/ui/app/components/currency-input/tests/currency-input.container.test.js
deleted file mode 100644
index 6109d29b6..000000000
--- a/ui/app/components/currency-input/tests/currency-input.container.test.js
+++ /dev/null
@@ -1,170 +0,0 @@
-import assert from 'assert'
-import proxyquire from 'proxyquire'
-
-let mapStateToProps, mergeProps
-
-proxyquire('../currency-input.container.js', {
- 'react-redux': {
- connect: (ms, md, mp) => {
- mapStateToProps = ms
- mergeProps = mp
- return () => ({})
- },
- },
-})
-
-describe('CurrencyInput container', () => {
- describe('mapStateToProps()', () => {
- const tests = [
- // Test # 1
- {
- comment: 'should return correct props in mainnet',
- mockState: {
- metamask: {
- conversionRate: 280.45,
- currentCurrency: 'usd',
- nativeCurrency: 'ETH',
- preferences: {
- showFiatInTestnets: false,
- },
- provider: {
- type: 'mainnet',
- },
- },
- },
- expected: {
- conversionRate: 280.45,
- currentCurrency: 'usd',
- nativeCurrency: 'ETH',
- hideFiat: false,
- },
- },
- // Test # 2
- {
- comment: 'should return correct props when not in mainnet and showFiatInTestnets is false',
- mockState: {
- metamask: {
- conversionRate: 280.45,
- currentCurrency: 'usd',
- nativeCurrency: 'ETH',
- preferences: {
- showFiatInTestnets: false,
- },
- provider: {
- type: 'rinkeby',
- },
- },
- },
- expected: {
- conversionRate: 280.45,
- currentCurrency: 'usd',
- nativeCurrency: 'ETH',
- hideFiat: true,
- },
- },
- // Test # 3
- {
- comment: 'should return correct props when not in mainnet and showFiatInTestnets is true',
- mockState: {
- metamask: {
- conversionRate: 280.45,
- currentCurrency: 'usd',
- nativeCurrency: 'ETH',
- preferences: {
- showFiatInTestnets: true,
- },
- provider: {
- type: 'rinkeby',
- },
- },
- },
- expected: {
- conversionRate: 280.45,
- currentCurrency: 'usd',
- nativeCurrency: 'ETH',
- hideFiat: false,
- },
- },
- // Test # 4
- {
- comment: 'should return correct props when in mainnet and showFiatInTestnets is true',
- mockState: {
- metamask: {
- conversionRate: 280.45,
- currentCurrency: 'usd',
- nativeCurrency: 'ETH',
- preferences: {
- showFiatInTestnets: true,
- },
- provider: {
- type: 'mainnet',
- },
- },
- },
- expected: {
- conversionRate: 280.45,
- currentCurrency: 'usd',
- nativeCurrency: 'ETH',
- hideFiat: false,
- },
- },
- ]
-
- tests.forEach(({ mockState, expected, comment }) => {
- it(comment, () => assert.deepEqual(mapStateToProps(mockState), expected))
- })
- })
-
- describe('mergeProps()', () => {
- const tests = [
- // Test # 1
- {
- comment: 'should return the correct props',
- mock: {
- stateProps: {
- conversionRate: 280.45,
- currentCurrency: 'usd',
- nativeCurrency: 'ETH',
- },
- dispatchProps: {},
- ownProps: {},
- },
- expected: {
- conversionRate: 280.45,
- currentCurrency: 'usd',
- nativeCurrency: 'ETH',
- // useFiat: true,
- nativeSuffix: 'ETH',
- fiatSuffix: 'USD',
- },
- },
- // Test # 1
- {
- comment: 'should return the correct props when useFiat is true',
- mock: {
- stateProps: {
- conversionRate: 280.45,
- currentCurrency: 'usd',
- nativeCurrency: 'ETH',
- },
- dispatchProps: {},
- ownProps: { useFiat: true },
- },
- expected: {
- conversionRate: 280.45,
- currentCurrency: 'usd',
- nativeCurrency: 'ETH',
- useFiat: true,
- nativeSuffix: 'ETH',
- fiatSuffix: 'USD',
- },
- },
- ]
-
- tests.forEach(({ mock: { stateProps, dispatchProps, ownProps }, expected, comment }) => {
- it(comment, () => {
- assert.deepEqual(mergeProps(stateProps, dispatchProps, ownProps), expected)
- })
- })
- })
-})