Skip to content

Commit

Permalink
Remove changes from CurrencyDisplay component
Browse files Browse the repository at this point in the history
  • Loading branch information
whymarrh committed Oct 25, 2018
1 parent b551822 commit 99acde4
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ import CurrencyDisplay from './currency-display.component'
import { getValueFromWeiHex, formatCurrency } from '../../helpers/confirm-transaction/util'

const mapStateToProps = state => {
const { metamask: { nativeCurrency, currentCurrency, conversionRate } } = state
const { metamask: { currentCurrency, conversionRate } } = state

return {
currentCurrency,
conversionRate,
nativeCurrency,
}
}

const mergeProps = (stateProps, dispatchProps, ownProps) => {
const { nativeCurrency, currentCurrency, conversionRate, ...restStateProps } = stateProps
const { currentCurrency, conversionRate, ...restStateProps } = stateProps
const {
value,
numberOfDecimals = 2,
Expand All @@ -23,9 +22,9 @@ const mergeProps = (stateProps, dispatchProps, ownProps) => {
...restOwnProps
} = ownProps

const toCurrency = currency === 'ETH' ? nativeCurrency || currency : currency || currentCurrency
const toCurrency = currency || currentCurrency
const convertedValue = getValueFromWeiHex({
value, nativeCurrency, toCurrency, conversionRate, numberOfDecimals, toDenomination: denomination,
value, toCurrency, conversionRate, numberOfDecimals, toDenomination: denomination,
})
const displayValue = formatCurrency(convertedValue, toCurrency)
const suffix = hideLabel ? undefined : toCurrency.toUpperCase()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import CurrencyDisplay from '../currency-display.component'
describe('CurrencyDisplay Component', () => {
it('should render text with a className', () => {
const wrapper = shallow(<CurrencyDisplay
nativeCurrency={'ETH'}
displayValue="$123.45"
className="currency-display"
/>)
Expand All @@ -17,7 +16,6 @@ describe('CurrencyDisplay Component', () => {

it('should render text with a prefix', () => {
const wrapper = shallow(<CurrencyDisplay
nativeCurrency={'ETH'}
displayValue="$123.45"
className="currency-display"
prefix="-"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@ describe('CurrencyDisplay container', () => {
metamask: {
conversionRate: 280.45,
currentCurrency: 'usd',
nativeCurrency: 'ETH',
},
}

assert.deepEqual(mapStateToProps(mockState), {
conversionRate: 280.45,
currentCurrency: 'usd',
nativeCurrency: 'ETH',
})
})
})
Expand All @@ -37,7 +35,6 @@ describe('CurrencyDisplay container', () => {
const mockStateProps = {
conversionRate: 280.45,
currentCurrency: 'usd',
nativeCurrency: 'ETH',
}

const tests = [
Expand All @@ -46,48 +43,40 @@ describe('CurrencyDisplay container', () => {
value: '0x2386f26fc10000',
numberOfDecimals: 2,
currency: 'usd',
nativeCurrency: 'ETH',
},
result: {
displayValue: '$2.80',
suffix: 'USD',
nativeCurrency: 'ETH',
},
},
{
props: {
value: '0x2386f26fc10000',
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,
},
Expand All @@ -96,12 +85,10 @@ describe('CurrencyDisplay container', () => {
props: {
value: '0x3b9aca00',
currency: 'ETH',
nativeCurrency: 'ETH',
denomination: 'GWEI',
hideLabel: true,
},
result: {
nativeCurrency: 'ETH',
displayValue: '1',
suffix: undefined,
},
Expand All @@ -110,12 +97,10 @@ describe('CurrencyDisplay container', () => {
props: {
value: '0x3b9aca00',
currency: 'ETH',
nativeCurrency: 'ETH',
denomination: 'WEI',
hideLabel: true,
},
result: {
nativeCurrency: 'ETH',
displayValue: '1000000000',
suffix: undefined,
},
Expand All @@ -124,12 +109,10 @@ describe('CurrencyDisplay container', () => {
props: {
value: '0x3b9aca00',
currency: 'ETH',
nativeCurrency: 'ETH',
numberOfDecimals: 100,
hideLabel: true,
},
result: {
nativeCurrency: 'ETH',
displayValue: '1e-9',
suffix: undefined,
},
Expand Down
2 changes: 1 addition & 1 deletion ui/app/components/transaction-breakdown/index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default } from './transaction-breakdown.component'
export { default } from './transaction-breakdown.container'
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Card from '../card'
import CurrencyDisplay from '../currency-display'
import UserPreferencedCurrencyDisplay from '../user-preferenced-currency-display'
import HexToDecimal from '../hex-to-decimal'
import { ETH, GWEI, PRIMARY, SECONDARY } from '../../constants/common'
import { GWEI, PRIMARY, SECONDARY } from '../../constants/common'
import { getHexGasTotal } from '../../helpers/confirm-transaction/util'
import { sumHexes } from '../../helpers/transactions.util'

Expand All @@ -18,6 +18,7 @@ export default class TransactionBreakdown extends PureComponent {
static propTypes = {
transaction: PropTypes.object,
className: PropTypes.string,
nativeCurrency: PropTypes.string.isRequired,
}

static defaultProps = {
Expand All @@ -26,7 +27,7 @@ export default class TransactionBreakdown extends PureComponent {

render () {
const { t } = this.context
const { transaction, className } = this.props
const { transaction, className, nativeCurrency } = this.props
const { txParams: { gas, gasPrice, value } = {}, txReceipt: { gasUsed } = {} } = transaction

const gasLimit = typeof gasUsed === 'string' ? gasUsed : gas
Expand Down Expand Up @@ -72,7 +73,7 @@ export default class TransactionBreakdown extends PureComponent {
<TransactionBreakdownRow title={t('gasPrice')}>
<CurrencyDisplay
className="transaction-breakdown__value"
currency={ETH}
currency={nativeCurrency}
denomination={GWEI}
value={gasPrice}
hideLabel
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { connect } from 'react-redux'
import TransactionBreakdown from './transaction-breakdown.component'
import { getNativeCurrency } from '../../selectors'

const mapStateToProps = (state) => {
return {
nativeCurrency: getNativeCurrency(state),
}
}

export default connect(mapStateToProps)(TransactionBreakdown)

0 comments on commit 99acde4

Please sign in to comment.