aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/send
diff options
context:
space:
mode:
Diffstat (limited to 'ui/app/components/send')
-rw-r--r--ui/app/components/send/account-list-item/account-list-item.component.js29
-rw-r--r--ui/app/components/send/account-list-item/account-list-item.container.js2
-rw-r--r--ui/app/components/send/account-list-item/tests/account-list-item-component.test.js17
-rw-r--r--ui/app/components/send/account-list-item/tests/account-list-item-container.test.js2
-rw-r--r--ui/app/components/send/currency-display/currency-display.js186
-rw-r--r--ui/app/components/send/currency-display/index.js1
-rw-r--r--ui/app/components/send/currency-display/tests/currency-display.test.js91
-rw-r--r--ui/app/components/send/send-content/send-amount-row/amount-max-button/amount-max-button.component.js34
-rw-r--r--ui/app/components/send/send-content/send-amount-row/amount-max-button/tests/amount-max-button-component.test.js9
-rw-r--r--ui/app/components/send/send-content/send-amount-row/send-amount-row.component.js45
-rw-r--r--ui/app/components/send/send-content/send-amount-row/tests/send-amount-row-component.test.js26
-rw-r--r--ui/app/components/send/send-content/send-gas-row/gas-fee-display/gas-fee-display.component.js35
-rw-r--r--ui/app/components/send/send-content/send-gas-row/gas-fee-display/test/gas-fee-display.component.test.js12
-rw-r--r--ui/app/components/send/send.selectors.js5
-rw-r--r--ui/app/components/send/send.utils.js4
-rw-r--r--ui/app/components/send/tests/send-selectors-test-data.js1
-rw-r--r--ui/app/components/send/tests/send-selectors.test.js10
17 files changed, 117 insertions, 392 deletions
diff --git a/ui/app/components/send/account-list-item/account-list-item.component.js b/ui/app/components/send/account-list-item/account-list-item.component.js
index 9f4a96e61..14bb7471f 100644
--- a/ui/app/components/send/account-list-item/account-list-item.component.js
+++ b/ui/app/components/send/account-list-item/account-list-item.component.js
@@ -2,7 +2,8 @@ import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { checksumAddress } from '../../../util'
import Identicon from '../../identicon'
-import CurrencyDisplay from '../currency-display'
+import UserPreferencedCurrencyDisplay from '../../user-preferenced-currency-display'
+import { PRIMARY, SECONDARY } from '../../../constants/common'
export default class AccountListItem extends Component {
@@ -25,8 +26,6 @@ export default class AccountListItem extends Component {
const {
account,
className,
- conversionRate,
- currentCurrency,
displayAddress = false,
displayBalance = true,
handleClick,
@@ -57,16 +56,20 @@ export default class AccountListItem extends Component {
{ checksumAddress(address) }
</div>}
- {displayBalance && <CurrencyDisplay
- className="account-list-item__account-balances"
- conversionRate={conversionRate}
- convertedBalanceClassName="account-list-item__account-secondary-balance"
- convertedCurrency={currentCurrency}
- primaryBalanceClassName="account-list-item__account-primary-balance"
- primaryCurrency="ETH"
- readOnly={true}
- value={balance}
- />}
+ {
+ displayBalance && (
+ <div className="account-list-item__account-balances">
+ <UserPreferencedCurrencyDisplay
+ type={PRIMARY}
+ value={balance}
+ />
+ <UserPreferencedCurrencyDisplay
+ type={SECONDARY}
+ value={balance}
+ />
+ </div>
+ )
+ }
</div>)
}
diff --git a/ui/app/components/send/account-list-item/account-list-item.container.js b/ui/app/components/send/account-list-item/account-list-item.container.js
index 4b4519288..f8e73d923 100644
--- a/ui/app/components/send/account-list-item/account-list-item.container.js
+++ b/ui/app/components/send/account-list-item/account-list-item.container.js
@@ -2,6 +2,7 @@ import { connect } from 'react-redux'
import {
getConversionRate,
getCurrentCurrency,
+ getNativeCurrency,
} from '../send.selectors.js'
import AccountListItem from './account-list-item.component'
@@ -11,5 +12,6 @@ function mapStateToProps (state) {
return {
conversionRate: getConversionRate(state),
currentCurrency: getCurrentCurrency(state),
+ nativeCurrency: getNativeCurrency(state),
}
}
diff --git a/ui/app/components/send/account-list-item/tests/account-list-item-component.test.js b/ui/app/components/send/account-list-item/tests/account-list-item-component.test.js
index ef152d2e7..6ffc0b1c6 100644
--- a/ui/app/components/send/account-list-item/tests/account-list-item-component.test.js
+++ b/ui/app/components/send/account-list-item/tests/account-list-item-component.test.js
@@ -4,7 +4,7 @@ import { shallow } from 'enzyme'
import sinon from 'sinon'
import proxyquire from 'proxyquire'
import Identicon from '../../../identicon'
-import CurrencyDisplay from '../../currency-display'
+import UserPreferencedCurrencyDisplay from '../../../user-preferenced-currency-display'
const utilsMethodStubs = {
checksumAddress: sinon.stub().returns('mockCheckSumAddress'),
@@ -28,6 +28,7 @@ describe('AccountListItem Component', function () {
className={'mockClassName'}
conversionRate={4}
currentCurrency={'mockCurrentyCurrency'}
+ nativeCurrency={'ETH'}
displayAddress={false}
displayBalance={false}
handleClick={propsMethodSpies.handleClick}
@@ -114,17 +115,11 @@ describe('AccountListItem Component', function () {
it('should render a CurrencyDisplay with the correct props if displayBalance is true', () => {
wrapper.setProps({ displayBalance: true })
- assert.equal(wrapper.find(CurrencyDisplay).length, 1)
+ assert.equal(wrapper.find(UserPreferencedCurrencyDisplay).length, 2)
assert.deepEqual(
- wrapper.find(CurrencyDisplay).props(),
+ wrapper.find(UserPreferencedCurrencyDisplay).at(0).props(),
{
- className: 'account-list-item__account-balances',
- conversionRate: 4,
- convertedBalanceClassName: 'account-list-item__account-secondary-balance',
- convertedCurrency: 'mockCurrentyCurrency',
- primaryBalanceClassName: 'account-list-item__account-primary-balance',
- primaryCurrency: 'ETH',
- readOnly: true,
+ type: 'PRIMARY',
value: 'mockBalance',
}
)
@@ -132,7 +127,7 @@ describe('AccountListItem Component', function () {
it('should not render a CurrencyDisplay if displayBalance is false', () => {
wrapper.setProps({ displayBalance: false })
- assert.equal(wrapper.find(CurrencyDisplay).length, 0)
+ assert.equal(wrapper.find(UserPreferencedCurrencyDisplay).length, 0)
})
})
})
diff --git a/ui/app/components/send/account-list-item/tests/account-list-item-container.test.js b/ui/app/components/send/account-list-item/tests/account-list-item-container.test.js
index af0859117..7c2f5fcb2 100644
--- a/ui/app/components/send/account-list-item/tests/account-list-item-container.test.js
+++ b/ui/app/components/send/account-list-item/tests/account-list-item-container.test.js
@@ -13,6 +13,7 @@ proxyquire('../account-list-item.container.js', {
'../send.selectors.js': {
getConversionRate: (s) => `mockConversionRate:${s}`,
getCurrentCurrency: (s) => `mockCurrentCurrency:${s}`,
+ getNativeCurrency: (s) => `mockNativeCurrency:${s}`,
},
})
@@ -24,6 +25,7 @@ describe('account-list-item container', () => {
assert.deepEqual(mapStateToProps('mockState'), {
conversionRate: 'mockConversionRate:mockState',
currentCurrency: 'mockCurrentCurrency:mockState',
+ nativeCurrency: 'mockNativeCurrency:mockState',
})
})
diff --git a/ui/app/components/send/currency-display/currency-display.js b/ui/app/components/send/currency-display/currency-display.js
deleted file mode 100644
index 2b8eaa41f..000000000
--- a/ui/app/components/send/currency-display/currency-display.js
+++ /dev/null
@@ -1,186 +0,0 @@
-const Component = require('react').Component
-const h = require('react-hyperscript')
-const inherits = require('util').inherits
-const { conversionUtil, multiplyCurrencies } = require('../../../conversion-util')
-const { removeLeadingZeroes } = require('../send.utils')
-const currencyFormatter = require('currency-formatter')
-const currencies = require('currency-formatter/currencies')
-const ethUtil = require('ethereumjs-util')
-const PropTypes = require('prop-types')
-
-CurrencyDisplay.contextTypes = {
- t: PropTypes.func,
-}
-
-module.exports = CurrencyDisplay
-
-inherits(CurrencyDisplay, Component)
-function CurrencyDisplay () {
- Component.call(this)
-}
-
-function toHexWei (value) {
- return conversionUtil(value, {
- fromNumericBase: 'dec',
- toNumericBase: 'hex',
- toDenomination: 'WEI',
- })
-}
-
-CurrencyDisplay.prototype.componentWillMount = function () {
- this.setState({
- valueToRender: this.getValueToRender(this.props),
- })
-}
-
-CurrencyDisplay.prototype.componentWillReceiveProps = function (nextProps) {
- const currentValueToRender = this.getValueToRender(this.props)
- const newValueToRender = this.getValueToRender(nextProps)
- if (currentValueToRender !== newValueToRender) {
- this.setState({
- valueToRender: newValueToRender,
- })
- }
-}
-
-CurrencyDisplay.prototype.getAmount = function (value) {
- const { selectedToken } = this.props
- const { decimals } = selectedToken || {}
- const multiplier = Math.pow(10, Number(decimals || 0))
-
- const sendAmount = multiplyCurrencies(value || '0', multiplier, {toNumericBase: 'hex'})
-
- return selectedToken
- ? sendAmount
- : toHexWei(value)
-}
-
-CurrencyDisplay.prototype.getValueToRender = function ({ selectedToken, conversionRate, value, readOnly }) {
- if (value === '0x0') return readOnly ? '0' : ''
- const { decimals, symbol } = selectedToken || {}
- const multiplier = Math.pow(10, Number(decimals || 0))
-
- return selectedToken
- ? conversionUtil(ethUtil.addHexPrefix(value), {
- fromNumericBase: 'hex',
- toNumericBase: 'dec',
- toCurrency: symbol,
- conversionRate: multiplier,
- invertConversionRate: true,
- })
- : conversionUtil(ethUtil.addHexPrefix(value), {
- fromNumericBase: 'hex',
- toNumericBase: 'dec',
- fromDenomination: 'WEI',
- numberOfDecimals: 9,
- conversionRate,
- })
-}
-
-CurrencyDisplay.prototype.getConvertedValueToRender = function (nonFormattedValue) {
- const { primaryCurrency, convertedCurrency, conversionRate } = this.props
-
- if (conversionRate === 0 || conversionRate === null || conversionRate === undefined) {
- if (nonFormattedValue !== 0) {
- return null
- }
- }
-
- let convertedValue = conversionUtil(nonFormattedValue, {
- fromNumericBase: 'dec',
- fromCurrency: primaryCurrency,
- toCurrency: convertedCurrency,
- numberOfDecimals: 2,
- conversionRate,
- })
-
- convertedValue = Number(convertedValue).toFixed(2)
- const upperCaseCurrencyCode = convertedCurrency.toUpperCase()
- return currencies.find(currency => currency.code === upperCaseCurrencyCode)
- ? currencyFormatter.format(Number(convertedValue), {
- code: upperCaseCurrencyCode,
- })
- : convertedValue
- }
-
-CurrencyDisplay.prototype.handleChange = function (newVal) {
- this.setState({ valueToRender: removeLeadingZeroes(newVal) })
- this.props.onChange(this.getAmount(newVal))
-}
-
-CurrencyDisplay.prototype.getInputWidth = function (valueToRender, readOnly) {
- const valueString = String(valueToRender)
- const valueLength = valueString.length || 1
- const decimalPointDeficit = valueString.match(/\./) ? -0.5 : 0
- return (valueLength + decimalPointDeficit + 0.75) + 'ch'
-}
-
-CurrencyDisplay.prototype.onlyRenderConversions = function (convertedValueToRender) {
- const {
- convertedBalanceClassName = 'currency-display__converted-value',
- convertedCurrency,
- } = this.props
- return h('div', {
- className: convertedBalanceClassName,
- }, convertedValueToRender == null
- ? this.context.t('noConversionRateAvailable')
- : `${convertedValueToRender} ${convertedCurrency.toUpperCase()}`
-)
- }
-
-CurrencyDisplay.prototype.render = function () {
- const {
- className = 'currency-display',
- primaryBalanceClassName = 'currency-display__input',
- primaryCurrency,
- readOnly = false,
- inError = false,
- onBlur,
- step,
- } = this.props
- const { valueToRender } = this.state
-
- const convertedValueToRender = this.getConvertedValueToRender(valueToRender)
-
- return h('div', {
- className,
- style: {
- borderColor: inError ? 'red' : null,
- },
- onClick: () => {
- this.currencyInput && this.currencyInput.focus()
- },
- }, [
-
- h('div.currency-display__primary-row', [
-
- h('div.currency-display__input-wrapper', [
-
- h('input', {
- className: primaryBalanceClassName,
- value: `${valueToRender}`,
- placeholder: '0',
- type: 'number',
- readOnly,
- ...(!readOnly ? {
- onChange: e => this.handleChange(e.target.value),
- onBlur: () => onBlur(this.getAmount(valueToRender)),
- } : {}),
- ref: input => { this.currencyInput = input },
- style: {
- width: this.getInputWidth(valueToRender, readOnly),
- },
- min: 0,
- step,
- }),
-
- h('span.currency-display__currency-symbol', primaryCurrency),
-
- ]),
-
- ]), this.onlyRenderConversions(convertedValueToRender),
-
- ])
-
-}
-
diff --git a/ui/app/components/send/currency-display/index.js b/ui/app/components/send/currency-display/index.js
deleted file mode 100644
index 5dc269c5a..000000000
--- a/ui/app/components/send/currency-display/index.js
+++ /dev/null
@@ -1 +0,0 @@
-export { default } from './currency-display.js'
diff --git a/ui/app/components/send/currency-display/tests/currency-display.test.js b/ui/app/components/send/currency-display/tests/currency-display.test.js
deleted file mode 100644
index c9560b81c..000000000
--- a/ui/app/components/send/currency-display/tests/currency-display.test.js
+++ /dev/null
@@ -1,91 +0,0 @@
-import React from 'react'
-import assert from 'assert'
-import sinon from 'sinon'
-import { shallow, mount } from 'enzyme'
-import CurrencyDisplay from '../currency-display'
-
-describe('', () => {
-
- const token = {
- address: '0xTest',
- symbol: 'TST',
- decimals: '13',
- }
-
- it('retuns ETH value for wei value', () => {
- const wrapper = mount(<CurrencyDisplay />, {context: {t: str => str + '_t'}})
-
- const value = wrapper.instance().getValueToRender({
- // 1000000000000000000
- value: 'DE0B6B3A7640000',
- })
-
- assert.equal(value, 1)
- })
-
- it('returns value of token based on token decimals', () => {
- const wrapper = mount(<CurrencyDisplay />, {context: {t: str => str + '_t'}})
-
- const value = wrapper.instance().getValueToRender({
- selectedToken: token,
- // 1000000000000000000
- value: 'DE0B6B3A7640000',
- })
-
- assert.equal(value, 100000)
- })
-
- it('returns hex value with decimal adjustment', () => {
-
- const wrapper = mount(
- <CurrencyDisplay
- selectedToken={token}
- />, {context: {t: str => str + '_t'}})
-
- const value = wrapper.instance().getAmount(1)
- // 10000000000000
- assert.equal(value, '9184e72a000')
- })
-
- it('#getConvertedValueToRender converts input value based on conversionRate', () => {
-
- const wrapper = mount(
- <CurrencyDisplay
- primaryCurrency={'usd'}
- convertedCurrency={'ja'}
- conversionRate={2}
- />, {context: {t: str => str + '_t'}})
-
- const value = wrapper.instance().getConvertedValueToRender(32)
-
- assert.equal(value, 64)
- })
-
- it('#onlyRenderConversions renders single element for converted currency and value', () => {
- const wrapper = mount(
- <CurrencyDisplay
- convertedCurrency={'test'}
- />, {context: {t: str => str + '_t'}})
-
- const value = wrapper.instance().onlyRenderConversions(10)
- assert.equal(value.props.className, 'currency-display__converted-value')
- assert.equal(value.props.children, '10 TEST')
- })
-
- it('simulates change value in input', () => {
- const handleChangeSpy = sinon.spy()
-
- const wrapper = shallow(
- <CurrencyDisplay
- onChange={handleChangeSpy}
- />, {context: {t: str => str + '_t'}})
-
- const input = wrapper.find('input')
- input.simulate('focus')
- input.simulate('change', { target: { value: '100' } })
-
- assert.equal(wrapper.state().valueToRender, '100')
- assert.equal(wrapper.find('input').prop('value'), '100')
- })
-
-})
diff --git a/ui/app/components/send/send-content/send-amount-row/amount-max-button/amount-max-button.component.js b/ui/app/components/send/send-content/send-amount-row/amount-max-button/amount-max-button.component.js
index 4d0d36ab4..ceb620941 100644
--- a/ui/app/components/send/send-content/send-amount-row/amount-max-button/amount-max-button.component.js
+++ b/ui/app/components/send/send-content/send-amount-row/amount-max-button/amount-max-button.component.js
@@ -34,21 +34,27 @@ export default class AmountMaxButton extends Component {
})
}
+ onMaxClick = (event) => {
+ const { setMaxModeTo } = this.props
+
+ event.preventDefault()
+ setMaxModeTo(true)
+ this.setMaxAmount()
+ }
+
render () {
- const { setMaxModeTo, maxModeOn } = this.props
-
- return (
- <div
- className="send-v2__amount-max"
- onClick={(event) => {
- event.preventDefault()
- setMaxModeTo(true)
- this.setMaxAmount()
- }}
- >
- {!maxModeOn ? this.context.t('max') : ''}
- </div>
- )
+ return this.props.maxModeOn
+ ? null
+ : (
+ <div>
+ <span
+ className="send-v2__amount-max"
+ onClick={this.onMaxClick}
+ >
+ {this.context.t('max')}
+ </span>
+ </div>
+ )
}
}
diff --git a/ui/app/components/send/send-content/send-amount-row/amount-max-button/tests/amount-max-button-component.test.js b/ui/app/components/send/send-content/send-amount-row/amount-max-button/tests/amount-max-button-component.test.js
index 86a05ff21..b04d3897f 100644
--- a/ui/app/components/send/send-content/send-amount-row/amount-max-button/tests/amount-max-button-component.test.js
+++ b/ui/app/components/send/send-content/send-amount-row/amount-max-button/tests/amount-max-button-component.test.js
@@ -56,9 +56,8 @@ describe('AmountMaxButton Component', function () {
})
describe('render', () => {
- it('should render a div with a send-v2__amount-max class', () => {
- assert.equal(wrapper.find('.send-v2__amount-max').length, 1)
- assert(wrapper.find('.send-v2__amount-max').is('div'))
+ it('should render an element with a send-v2__amount-max class', () => {
+ assert(wrapper.exists('.send-v2__amount-max'))
})
it('should call setMaxModeTo and setMaxAmount when the send-v2__amount-max div is clicked', () => {
@@ -77,9 +76,9 @@ describe('AmountMaxButton Component', function () {
)
})
- it('should not render text when maxModeOn is true', () => {
+ it('should not render anything when maxModeOn is true', () => {
wrapper.setProps({ maxModeOn: true })
- assert.equal(wrapper.find('.send-v2__amount-max').text(), '')
+ assert.ok(!wrapper.exists('.send-v2__amount-max'))
})
it('should render the expected text when maxModeOn is false', () => {
diff --git a/ui/app/components/send/send-content/send-amount-row/send-amount-row.component.js b/ui/app/components/send/send-content/send-amount-row/send-amount-row.component.js
index c548a5695..0268376bf 100644
--- a/ui/app/components/send/send-content/send-amount-row/send-amount-row.component.js
+++ b/ui/app/components/send/send-content/send-amount-row/send-amount-row.component.js
@@ -2,7 +2,8 @@ import React, { Component } from 'react'
import PropTypes from 'prop-types'
import SendRowWrapper from '../send-row-wrapper/'
import AmountMaxButton from './amount-max-button/'
-import CurrencyDisplay from '../../currency-display'
+import UserPreferencedCurrencyInput from '../../../user-preferenced-currency-input'
+import UserPreferencedTokenInput from '../../../user-preferenced-token-input'
export default class SendAmountRow extends Component {
@@ -84,16 +85,25 @@ export default class SendAmountRow extends Component {
}
}
+ renderInput () {
+ const { amount, inError, selectedToken } = this.props
+ const Component = selectedToken ? UserPreferencedTokenInput : UserPreferencedCurrencyInput
+
+ return (
+ <Component
+ onChange={newAmount => this.validateAmount(newAmount)}
+ onBlur={newAmount => {
+ this.updateGas(newAmount)
+ this.updateAmount(newAmount)
+ }}
+ error={inError}
+ value={amount}
+ />
+ )
+ }
+
render () {
- const {
- amount,
- amountConversionRate,
- convertedCurrency,
- gasTotal,
- inError,
- primaryCurrency,
- selectedToken,
- } = this.props
+ const { gasTotal, inError } = this.props
return (
<SendRowWrapper
@@ -102,20 +112,7 @@ export default class SendAmountRow extends Component {
errorType={'amount'}
>
{!inError && gasTotal && <AmountMaxButton />}
- <CurrencyDisplay
- conversionRate={amountConversionRate}
- convertedCurrency={convertedCurrency}
- onBlur={newAmount => {
- this.updateGas(newAmount)
- this.updateAmount(newAmount)
- }}
- onChange={newAmount => this.validateAmount(newAmount)}
- inError={inError}
- primaryCurrency={primaryCurrency || 'ETH'}
- selectedToken={selectedToken}
- value={amount}
- step="any"
- />
+ { this.renderInput() }
</SendRowWrapper>
)
}
diff --git a/ui/app/components/send/send-content/send-amount-row/tests/send-amount-row-component.test.js b/ui/app/components/send/send-content/send-amount-row/tests/send-amount-row-component.test.js
index 8425e076e..56e80cb83 100644
--- a/ui/app/components/send/send-content/send-amount-row/tests/send-amount-row-component.test.js
+++ b/ui/app/components/send/send-content/send-amount-row/tests/send-amount-row-component.test.js
@@ -6,7 +6,7 @@ import SendAmountRow from '../send-amount-row.component.js'
import SendRowWrapper from '../../send-row-wrapper/send-row-wrapper.component'
import AmountMaxButton from '../amount-max-button/amount-max-button.container'
-import CurrencyDisplay from '../../../currency-display'
+import UserPreferencedTokenInput from '../../../../user-preferenced-token-input'
const propsMethodSpies = {
setMaxModeTo: sinon.spy(),
@@ -150,26 +150,18 @@ describe('SendAmountRow Component', function () {
assert(wrapper.find(SendRowWrapper).childAt(0).is(AmountMaxButton))
})
- it('should render a CurrencyDisplay as the second child of the SendRowWrapper', () => {
- assert(wrapper.find(SendRowWrapper).childAt(1).is(CurrencyDisplay))
+ it('should render a UserPreferencedTokenInput as the second child of the SendRowWrapper', () => {
+ assert(wrapper.find(SendRowWrapper).childAt(1).is(UserPreferencedTokenInput))
})
- it('should render the CurrencyDisplay with the correct props', () => {
+ it('should render the UserPreferencedTokenInput with the correct props', () => {
const {
- conversionRate,
- convertedCurrency,
onBlur,
onChange,
- inError,
- primaryCurrency,
- selectedToken,
+ error,
value,
} = wrapper.find(SendRowWrapper).childAt(1).props()
- assert.equal(conversionRate, 'mockAmountConversionRate')
- assert.equal(convertedCurrency, 'mockConvertedCurrency')
- assert.equal(inError, false)
- assert.equal(primaryCurrency, 'mockPrimaryCurrency')
- assert.deepEqual(selectedToken, { address: 'mockTokenAddress' })
+ assert.equal(error, false)
assert.equal(value, 'mockAmount')
assert.equal(SendAmountRow.prototype.updateGas.callCount, 0)
assert.equal(SendAmountRow.prototype.updateAmount.callCount, 0)
@@ -192,11 +184,5 @@ describe('SendAmountRow Component', function () {
['mockNewAmount']
)
})
-
- it('should pass the default primaryCurrency to the CurrencyDisplay if primaryCurrency is falsy', () => {
- wrapper.setProps({ primaryCurrency: null })
- const { primaryCurrency } = wrapper.find(SendRowWrapper).childAt(1).props()
- assert.equal(primaryCurrency, 'ETH')
- })
})
})
diff --git a/ui/app/components/send/send-content/send-gas-row/gas-fee-display/gas-fee-display.component.js b/ui/app/components/send/send-content/send-gas-row/gas-fee-display/gas-fee-display.component.js
index bb9a94428..9bbb67506 100644
--- a/ui/app/components/send/send-content/send-gas-row/gas-fee-display/gas-fee-display.component.js
+++ b/ui/app/components/send/send-content/send-gas-row/gas-fee-display/gas-fee-display.component.js
@@ -1,7 +1,7 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
-import CurrencyDisplay from '../../../../send/currency-display'
-
+import UserPreferencedCurrencyDisplay from '../../../../user-preferenced-currency-display'
+import { PRIMARY, SECONDARY } from '../../../../../constants/common'
export default class GasFeeDisplay extends Component {
@@ -19,27 +19,24 @@ export default class GasFeeDisplay extends Component {
};
render () {
- const {
- conversionRate,
- gasTotal,
- onClick,
- primaryCurrency = 'ETH',
- convertedCurrency,
- gasLoadingError,
- } = this.props
+ const { gasTotal, onClick, gasLoadingError } = this.props
return (
<div className="send-v2__gas-fee-display">
{gasTotal
- ? <CurrencyDisplay
- primaryCurrency={primaryCurrency}
- convertedCurrency={convertedCurrency}
- value={gasTotal}
- conversionRate={conversionRate}
- gasLoadingError={gasLoadingError}
- convertedPrefix={'$'}
- readOnly
- />
+ ? (
+ <div className="currency-display">
+ <UserPreferencedCurrencyDisplay
+ value={gasTotal}
+ type={PRIMARY}
+ />
+ <UserPreferencedCurrencyDisplay
+ className="currency-display__converted-value"
+ value={gasTotal}
+ type={SECONDARY}
+ />
+ </div>
+ )
: gasLoadingError
? <div className="currency-display.currency-display--message">
{this.context.t('setGasPrice')}
diff --git a/ui/app/components/send/send-content/send-gas-row/gas-fee-display/test/gas-fee-display.component.test.js b/ui/app/components/send/send-content/send-gas-row/gas-fee-display/test/gas-fee-display.component.test.js
index 7cbe8d0df..9ff01493a 100644
--- a/ui/app/components/send/send-content/send-gas-row/gas-fee-display/test/gas-fee-display.component.test.js
+++ b/ui/app/components/send/send-content/send-gas-row/gas-fee-display/test/gas-fee-display.component.test.js
@@ -2,7 +2,7 @@ import React from 'react'
import assert from 'assert'
import {shallow} from 'enzyme'
import GasFeeDisplay from '../gas-fee-display.component'
-import CurrencyDisplay from '../../../../../send/currency-display'
+import UserPreferencedCurrencyDisplay from '../../../../../user-preferenced-currency-display'
import sinon from 'sinon'
@@ -29,17 +29,15 @@ describe('SendGasRow Component', function () {
describe('render', () => {
it('should render a CurrencyDisplay component', () => {
- assert.equal(wrapper.find(CurrencyDisplay).length, 1)
+ assert.equal(wrapper.find(UserPreferencedCurrencyDisplay).length, 2)
})
it('should render the CurrencyDisplay with the correct props', () => {
const {
- conversionRate,
- convertedCurrency,
+ type,
value,
- } = wrapper.find(CurrencyDisplay).props()
- assert.equal(conversionRate, 20)
- assert.equal(convertedCurrency, 'mockConvertedCurrency')
+ } = wrapper.find(UserPreferencedCurrencyDisplay).at(0).props()
+ assert.equal(type, 'PRIMARY')
assert.equal(value, 'mockGasTotal')
})
diff --git a/ui/app/components/send/send.selectors.js b/ui/app/components/send/send.selectors.js
index 22e379693..eb22a08b7 100644
--- a/ui/app/components/send/send.selectors.js
+++ b/ui/app/components/send/send.selectors.js
@@ -19,6 +19,7 @@ const selectors = {
getCurrentNetwork,
getCurrentViewContext,
getForceGasMin,
+ getNativeCurrency,
getGasLimit,
getGasPrice,
getGasPriceFromRecentBlocks,
@@ -111,6 +112,10 @@ function getCurrentCurrency (state) {
return state.metamask.currentCurrency
}
+function getNativeCurrency (state) {
+ return state.metamask.nativeCurrency
+}
+
function getCurrentNetwork (state) {
return state.metamask.network
}
diff --git a/ui/app/components/send/send.utils.js b/ui/app/components/send/send.utils.js
index a18a9e4b3..eb1667c63 100644
--- a/ui/app/components/send/send.utils.js
+++ b/ui/app/components/send/send.utils.js
@@ -215,7 +215,9 @@ async function estimateGas ({
// if recipient has no code, gas is 21k max:
if (!selectedToken && !data) {
const code = Boolean(to) && await global.eth.getCode(to)
- if (!code || code === '0x') {
+ // Geth will return '0x', and ganache-core v2.2.1 will return '0x0'
+ const codeIsEmpty = !code || code === '0x' || code === '0x0'
+ if (codeIsEmpty) {
return SIMPLE_GAS_COST
}
} else if (selectedToken && !to) {
diff --git a/ui/app/components/send/tests/send-selectors-test-data.js b/ui/app/components/send/tests/send-selectors-test-data.js
index 8b939dadb..30a2666cf 100644
--- a/ui/app/components/send/tests/send-selectors-test-data.js
+++ b/ui/app/components/send/tests/send-selectors-test-data.js
@@ -26,6 +26,7 @@ module.exports = {
'currentCurrency': 'USD',
'conversionRate': 1200.88200327,
'conversionDate': 1489013762,
+ 'nativeCurrency': 'ETH',
'noActiveNotices': true,
'frequentRpcList': [],
'network': '3',
diff --git a/ui/app/components/send/tests/send-selectors.test.js b/ui/app/components/send/tests/send-selectors.test.js
index 1a47cd209..e7e901f0d 100644
--- a/ui/app/components/send/tests/send-selectors.test.js
+++ b/ui/app/components/send/tests/send-selectors.test.js
@@ -12,6 +12,7 @@ const {
getCurrentCurrency,
getCurrentNetwork,
getCurrentViewContext,
+ getNativeCurrency,
getForceGasMin,
getGasLimit,
getGasPrice,
@@ -178,6 +179,15 @@ describe('send selectors', () => {
})
})
+ describe('getNativeCurrency()', () => {
+ it('should return the ticker symbol of the selected network', () => {
+ assert.equal(
+ getNativeCurrency(mockState),
+ 'ETH'
+ )
+ })
+ })
+
describe('getCurrentNetwork()', () => {
it('should return the id of the currently selected network', () => {
assert.equal(