1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-12 20:57:12 +01:00
metamask-extension/ui/app/components/transaction-view-balance/transaction-view-balance.component.js
Alexander Tseung badebe017f
Adds toggle for primary currency (#5421)
* Add UnitInput component

* Add CurrencyInput component

* Add UserPreferencedCurrencyInput component

* Add UserPreferencedCurrencyDisplay component

* Add updatePreferences action

* Add styles for CurrencyInput, CurrencyDisplay, and UnitInput

* Update SettingsTab page with Primary Currency toggle

* Refactor currency displays and inputs to use UserPreferenced displays and inputs

* Add TokenInput component

* Add UserPreferencedTokenInput component

* Use TokenInput in the send screen

* Fix unit tests

* Fix e2e and integration tests

* Remove send/CurrencyDisplay component

* Replace diamond unicode character with Eth logo. Fix typos
2018-10-17 07:03:29 +08:00

99 lines
2.6 KiB
JavaScript

import React, { PureComponent } from 'react'
import PropTypes from 'prop-types'
import Button from '../button'
import Identicon from '../identicon'
import TokenBalance from '../token-balance'
import UserPreferencedCurrencyDisplay from '../user-preferenced-currency-display'
import { SEND_ROUTE } from '../../routes'
import { PRIMARY, SECONDARY } from '../../constants/common'
export default class TransactionViewBalance extends PureComponent {
static contextTypes = {
t: PropTypes.func,
}
static propTypes = {
showDepositModal: PropTypes.func,
selectedToken: PropTypes.object,
history: PropTypes.object,
network: PropTypes.string,
balance: PropTypes.string,
assetImage: PropTypes.string,
}
renderBalance () {
const { selectedToken, balance } = this.props
return selectedToken
? (
<TokenBalance
token={selectedToken}
withSymbol
className="transaction-view-balance__token-balance"
/>
) : (
<div className="transaction-view-balance__balance">
<UserPreferencedCurrencyDisplay
className="transaction-view-balance__primary-balance"
value={balance}
type={PRIMARY}
ethNumberOfDecimals={3}
/>
<UserPreferencedCurrencyDisplay
className="transaction-view-balance__secondary-balance"
value={balance}
type={SECONDARY}
ethNumberOfDecimals={3}
/>
</div>
)
}
renderButtons () {
const { t } = this.context
const { selectedToken, showDepositModal, history } = this.props
return (
<div className="transaction-view-balance__buttons">
{
!selectedToken && (
<Button
type="primary"
className="transaction-view-balance__button"
onClick={() => showDepositModal()}
>
{ t('deposit') }
</Button>
)
}
<Button
type="primary"
className="transaction-view-balance__button"
onClick={() => history.push(SEND_ROUTE)}
>
{ t('send') }
</Button>
</div>
)
}
render () {
const { network, selectedToken, assetImage } = this.props
return (
<div className="transaction-view-balance">
<div className="transaction-view-balance__balance-container">
<Identicon
diameter={50}
address={selectedToken && selectedToken.address}
network={network}
image={assetImage}
/>
{ this.renderBalance() }
</div>
{ this.renderButtons() }
</div>
)
}
}