Add fallback when no function found, fix network colors, add fiat values for tokens with contract exchange rates

feature/default_network_editable
Alexander Tseung 6 years ago
parent e9a8c24cc4
commit d19c42fcae
  1. 9
      app/_locales/en/messages.json
  2. 18
      ui/app/components/confirm-page-container/confirm-detail-row/confirm-detail-row.component.js
  3. 6
      ui/app/components/network-display/index.scss
  4. 21
      ui/app/components/pages/confirm-approve/confirm-approve.component.js
  5. 19
      ui/app/components/pages/confirm-approve/confirm-approve.container.js
  6. 20
      ui/app/components/pages/confirm-send-token/confirm-send-token.component.js
  7. 26
      ui/app/components/pages/confirm-send-token/confirm-send-token.container.js
  8. 85
      ui/app/components/pages/confirm-token-transaction-base/confirm-token-transaction-base.component.js
  9. 34
      ui/app/components/pages/confirm-token-transaction-base/confirm-token-transaction-base.container.js
  10. 2
      ui/app/components/pages/confirm-token-transaction-base/index.js
  11. 40
      ui/app/components/pages/confirm-transaction-base/confirm-transaction-base.component.js
  12. 20
      ui/app/components/pages/confirm-transaction-switch/confirm-transaction-switch.component.js
  13. 1
      ui/app/components/pages/confirm-transaction-switch/confirm-transaction-switch.constants.js
  14. 7
      ui/app/components/pages/confirm-transaction/confirm-transaction.component.js
  15. 17
      ui/app/helpers/confirm-transaction/util.js
  16. 2
      ui/app/routes.js
  17. 99
      ui/app/selectors/confirm-transaction.js

@ -581,6 +581,9 @@
"noAddressForName": { "noAddressForName": {
"message": "No address has been set for this name." "message": "No address has been set for this name."
}, },
"noConversionRate": {
"message": "No Conversion Rate"
},
"noDeposits": { "noDeposits": {
"message": "No deposits received" "message": "No deposits received"
}, },
@ -593,6 +596,9 @@
"noTransactions": { "noTransactions": {
"message": "No Transactions" "message": "No Transactions"
}, },
"notFound": {
"message": "Not Found"
},
"notStarted": { "notStarted": {
"message": "Not Started" "message": "Not Started"
}, },
@ -972,6 +978,9 @@
"unknown": { "unknown": {
"message": "Unknown" "message": "Unknown"
}, },
"unknownFunction": {
"message": "Unknown Function"
},
"unknownNetwork": { "unknownNetwork": {
"message": "Unknown Private Network" "message": "Unknown Private Network"
}, },

@ -5,10 +5,10 @@ import classnames from 'classnames'
const ConfirmDetailRow = props => { const ConfirmDetailRow = props => {
const { const {
label, label,
fiatFee, fiatText,
ethFee, ethText,
onHeaderClick, onHeaderClick,
fiatFeeColor, fiatTextColor,
headerText, headerText,
headerTextClassName, headerTextClassName,
} = props } = props
@ -27,12 +27,12 @@ const ConfirmDetailRow = props => {
</div> </div>
<div <div
className="confirm-detail-row__fiat" className="confirm-detail-row__fiat"
style={{ color: fiatFeeColor }} style={{ color: fiatTextColor }}
> >
{ fiatFee } { fiatText }
</div> </div>
<div className="confirm-detail-row__eth"> <div className="confirm-detail-row__eth">
{ `\u2666 ${ethFee}` } { ethText }
</div> </div>
</div> </div>
</div> </div>
@ -41,9 +41,9 @@ const ConfirmDetailRow = props => {
ConfirmDetailRow.propTypes = { ConfirmDetailRow.propTypes = {
label: PropTypes.string, label: PropTypes.string,
fiatFee: PropTypes.string, fiatText: PropTypes.string,
ethFee: PropTypes.string, ethText: PropTypes.string,
fiatFeeColor: PropTypes.string, fiatTextColor: PropTypes.string,
onHeaderClick: PropTypes.func, onHeaderClick: PropTypes.func,
headerText: PropTypes.string, headerText: PropTypes.string,
headerTextClassName: PropTypes.string, headerTextClassName: PropTypes.string,

@ -9,7 +9,7 @@
height: 25px; height: 25px;
&--mainnet { &--mainnet {
background-color: lighten($blue-lagoon, 45%); background-color: lighten($blue-lagoon, 68%);
} }
&--ropsten { &--ropsten {
@ -17,11 +17,11 @@
} }
&--kovan { &--kovan {
background-color: lighten($purple, 45%); background-color: lighten($purple, 65%);
} }
&--rinkeby { &--rinkeby {
background-color: lighten($tulip-tree, 45%); background-color: lighten($tulip-tree, 35%);
} }
} }

@ -1,29 +1,18 @@
import React, { Component } from 'react' import React, { Component } from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import ConfirmTransactionBase from '../confirm-transaction-base' import ConfirmTokenTransactionBase from '../confirm-token-transaction-base'
export default class ConfirmApprove extends Component { export default class ConfirmApprove extends Component {
static contextTypes = {
t: PropTypes.func,
}
static propTypes = { static propTypes = {
tokenAddress: PropTypes.string, tokenAmount: PropTypes.number,
toAddress: PropTypes.string,
tokenAmount: PropTypes.string,
tokenSymbol: PropTypes.string,
} }
render () { render () {
const { toAddress, tokenAddress, tokenAmount, tokenSymbol } = this.props const { tokenAmount } = this.props
return ( return (
<ConfirmTransactionBase <ConfirmTokenTransactionBase
toAddress={toAddress} tokenAmount={tokenAmount}
identiconAddress={tokenAddress}
title={`${tokenAmount} ${tokenSymbol}`}
warning={`By approving this action, you grant permission for this contract to spend up to ${tokenAmount} of your ${tokenSymbol}.`}
hideSubtitle
/> />
) )
} }

@ -1,27 +1,12 @@
import { connect } from 'react-redux' import { connect } from 'react-redux'
import ConfirmApprove from './confirm-approve.component' import ConfirmApprove from './confirm-approve.component'
import { approveTokenAmountAndToAddressSelector } from '../../../selectors/confirm-transaction'
const mapStateToProps = state => { const mapStateToProps = state => {
const { confirmTransaction } = state const { tokenAmount } = approveTokenAmountAndToAddressSelector(state)
const {
tokenData = {},
txData: { txParams: { to: tokenAddress } = {} } = {},
tokenProps: { tokenSymbol } = {},
} = confirmTransaction
const { params = [] } = tokenData
let toAddress = ''
let tokenAmount = ''
if (params && params.length === 2) {
[{ value: toAddress }, { value: tokenAmount }] = params
}
return { return {
toAddress,
tokenAddress,
tokenAmount, tokenAmount,
tokenSymbol,
} }
} }

@ -1,20 +1,13 @@
import React, { Component } from 'react' import React, { Component } from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import ConfirmTransactionBase from '../confirm-transaction-base' import ConfirmTokenTransactionBase from '../confirm-token-transaction-base'
import { SEND_ROUTE } from '../../../routes' import { SEND_ROUTE } from '../../../routes'
export default class ConfirmSendToken extends Component { export default class ConfirmSendToken extends Component {
static contextTypes = {
t: PropTypes.func,
}
static propTypes = { static propTypes = {
history: PropTypes.object, history: PropTypes.object,
tokenAddress: PropTypes.string,
toAddress: PropTypes.string,
numberOfTokens: PropTypes.number,
tokenSymbol: PropTypes.string,
editTransaction: PropTypes.func, editTransaction: PropTypes.func,
tokenAmount: PropTypes.number,
} }
handleEdit (confirmTransactionData) { handleEdit (confirmTransactionData) {
@ -24,15 +17,12 @@ export default class ConfirmSendToken extends Component {
} }
render () { render () {
const { toAddress, tokenAddress, tokenSymbol, numberOfTokens } = this.props const { tokenAmount } = this.props
return ( return (
<ConfirmTransactionBase <ConfirmTokenTransactionBase
toAddress={toAddress}
identiconAddress={tokenAddress}
title={`${numberOfTokens} ${tokenSymbol}`}
onEdit={confirmTransactionData => this.handleEdit(confirmTransactionData)} onEdit={confirmTransactionData => this.handleEdit(confirmTransactionData)}
hideSubtitle tokenAmount={tokenAmount}
/> />
) )
} }

@ -2,36 +2,16 @@ import { connect } from 'react-redux'
import { compose } from 'recompose' import { compose } from 'recompose'
import { withRouter } from 'react-router-dom' import { withRouter } from 'react-router-dom'
import ConfirmSendToken from './confirm-send-token.component' import ConfirmSendToken from './confirm-send-token.component'
import { calcTokenAmount } from '../../../token-util'
import { clearConfirmTransaction } from '../../../ducks/confirm-transaction.duck' import { clearConfirmTransaction } from '../../../ducks/confirm-transaction.duck'
import { setSelectedToken, updateSend, showSendTokenPage } from '../../../actions' import { setSelectedToken, updateSend, showSendTokenPage } from '../../../actions'
import { conversionUtil } from '../../../conversion-util' import { conversionUtil } from '../../../conversion-util'
import { sendTokenTokenAmountAndToAddressSelector } from '../../../selectors/confirm-transaction'
const mapStateToProps = state => { const mapStateToProps = state => {
const { confirmTransaction } = state const { tokenAmount } = sendTokenTokenAmountAndToAddressSelector(state)
const {
tokenData = {},
tokenProps: { tokenSymbol, tokenDecimals } = {},
txData: { txParams: { to: tokenAddress } = {} } = {},
} = confirmTransaction
const { params = [] } = tokenData
let toAddress = ''
let tokenAmount = ''
if (params && params.length === 2) {
[{ value: toAddress }, { value: tokenAmount }] = params
}
const numberOfTokens = tokenAmount && tokenDecimals
? calcTokenAmount(tokenAmount, tokenDecimals)
: 0
return { return {
toAddress, tokenAmount,
tokenAddress,
tokenSymbol,
numberOfTokens,
} }
} }

@ -0,0 +1,85 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import ConfirmTransactionBase from '../confirm-transaction-base'
import {
formatCurrency,
convertTokenToFiat,
addFiat,
} from '../../../helpers/confirm-transaction/util'
export default class ConfirmTokenTransactionBase extends Component {
static contextTypes = {
t: PropTypes.func,
}
static propTypes = {
tokenAddress: PropTypes.string,
toAddress: PropTypes.string,
tokenAmount: PropTypes.number,
tokenSymbol: PropTypes.string,
fiatTransactionTotal: PropTypes.string,
ethTransactionTotal: PropTypes.string,
contractExchangeRate: PropTypes.number,
conversionRate: PropTypes.number,
currentCurrency: PropTypes.string,
}
getFiatTransactionAmount () {
const { tokenAmount, currentCurrency, conversionRate, contractExchangeRate } = this.props
return convertTokenToFiat({
value: tokenAmount,
toCurrency: currentCurrency,
conversionRate,
contractExchangeRate,
})
}
getSubtitle () {
const { currentCurrency, contractExchangeRate } = this.props
if (typeof contractExchangeRate === 'undefined') {
return this.context.t('noConversionRate')
} else {
const fiatTransactionAmount = this.getFiatTransactionAmount()
return formatCurrency(fiatTransactionAmount, currentCurrency)
}
}
getFiatTotalTextOverride () {
const { fiatTransactionTotal, currentCurrency, contractExchangeRate } = this.props
if (typeof contractExchangeRate === 'undefined') {
return formatCurrency(fiatTransactionTotal, currentCurrency)
} else {
const fiatTransactionAmount = this.getFiatTransactionAmount()
const fiatTotal = addFiat(fiatTransactionAmount, fiatTransactionTotal)
return formatCurrency(fiatTotal, currentCurrency)
}
}
render () {
const {
toAddress,
tokenAddress,
tokenSymbol,
tokenAmount,
ethTransactionTotal,
...restProps
} = this.props
const tokensText = `${tokenAmount} ${tokenSymbol}`
return (
<ConfirmTransactionBase
toAddress={toAddress}
identiconAddress={tokenAddress}
title={tokensText}
subtitle={this.getSubtitle()}
ethTotalTextOverride={`${tokensText} + \u2666 ${ethTransactionTotal}`}
fiatTotalTextOverride={this.getFiatTotalTextOverride()}
{...restProps}
/>
)
}
}

@ -0,0 +1,34 @@
import { connect } from 'react-redux'
import ConfirmTokenTransactionBase from './confirm-token-transaction-base.component'
import {
tokenAmountAndToAddressSelector,
contractExchangeRateSelector,
} from '../../../selectors/confirm-transaction'
const mapStateToProps = (state, ownProps) => {
const { tokenAmount: ownTokenAmount } = ownProps
const { confirmTransaction, metamask: { currentCurrency, conversionRate } } = state
const {
txData: { txParams: { to: tokenAddress } = {} } = {},
tokenProps: { tokenSymbol } = {},
fiatTransactionTotal,
ethTransactionTotal,
} = confirmTransaction
const { tokenAmount, toAddress } = tokenAmountAndToAddressSelector(state)
const contractExchangeRate = contractExchangeRateSelector(state)
return {
toAddress,
tokenAddress,
tokenAmount: typeof ownTokenAmount !== 'undefined' ? ownTokenAmount : tokenAmount,
tokenSymbol,
currentCurrency,
conversionRate,
contractExchangeRate,
fiatTransactionTotal,
ethTransactionTotal,
}
}
export default connect(mapStateToProps)(ConfirmTokenTransactionBase)

@ -0,0 +1,2 @@
export { default } from './confirm-token-transaction-base.container'
export { default as ConfirmTokenTransactionBase } from './confirm-token-transaction-base.component'

@ -54,6 +54,8 @@ export default class ConfirmTransactionBase extends Component {
detailsComponent: PropTypes.node, detailsComponent: PropTypes.node,
errorKey: PropTypes.string, errorKey: PropTypes.string,
errorMessage: PropTypes.string, errorMessage: PropTypes.string,
ethTotalTextOverride: PropTypes.string,
fiatTotalTextOverride: PropTypes.string,
hideData: PropTypes.bool, hideData: PropTypes.bool,
hideDetails: PropTypes.bool, hideDetails: PropTypes.bool,
hideSubtitle: PropTypes.bool, hideSubtitle: PropTypes.bool,
@ -146,6 +148,8 @@ export default class ConfirmTransactionBase extends Component {
currentCurrency, currentCurrency,
fiatTransactionTotal, fiatTransactionTotal,
ethTransactionTotal, ethTransactionTotal,
fiatTotalTextOverride,
ethTotalTextOverride,
hideDetails, hideDetails,
} = this.props } = this.props
@ -153,14 +157,16 @@ export default class ConfirmTransactionBase extends Component {
return null return null
} }
const formattedCurrency = formatCurrency(fiatTransactionTotal, currentCurrency)
return ( return (
detailsComponent || ( detailsComponent || (
<div className="confirm-page-container-content__details"> <div className="confirm-page-container-content__details">
<div className="confirm-page-container-content__gas-fee"> <div className="confirm-page-container-content__gas-fee">
<ConfirmDetailRow <ConfirmDetailRow
label="Gas Fee" label="Gas Fee"
fiatFee={formatCurrency(fiatTransactionFee, currentCurrency)} fiatText={formatCurrency(fiatTransactionFee, currentCurrency)}
ethFee={ethTransactionFee} ethText={`\u2666 ${ethTransactionFee}`}
headerText="Edit" headerText="Edit"
headerTextClassName="confirm-detail-row__header-text--edit" headerTextClassName="confirm-detail-row__header-text--edit"
onHeaderClick={() => this.handleEditGas()} onHeaderClick={() => this.handleEditGas()}
@ -169,11 +175,11 @@ export default class ConfirmTransactionBase extends Component {
<div> <div>
<ConfirmDetailRow <ConfirmDetailRow
label="Total" label="Total"
fiatFee={formatCurrency(fiatTransactionTotal, currentCurrency)} fiatText={fiatTotalTextOverride || formattedCurrency}
ethFee={ethTransactionTotal} ethText={ethTotalTextOverride || `\u2666 ${ethTransactionTotal}`}
headerText="Amount + Gas Fee" headerText="Amount + Gas Fee"
headerTextClassName="confirm-detail-row__header-text--total" headerTextClassName="confirm-detail-row__header-text--total"
fiatFeeColor="#2f9ae0" fiatTextColor="#2f9ae0"
/> />
</div> </div>
</div> </div>
@ -206,17 +212,21 @@ export default class ConfirmTransactionBase extends Component {
<div className="confirm-page-container-content__data-box-label"> <div className="confirm-page-container-content__data-box-label">
{`${t('functionType')}:`} {`${t('functionType')}:`}
<span className="confirm-page-container-content__function-type"> <span className="confirm-page-container-content__function-type">
{ name } { name || t('notFound') }
</span> </span>
</div> </div>
<div className="confirm-page-container-content__data-box"> {
<div className="confirm-page-container-content__data-field-label"> params && (
{ `${t('parameters')}:` } <div className="confirm-page-container-content__data-box">
</div> <div className="confirm-page-container-content__data-field-label">
<div> { `${t('parameters')}:` }
<pre>{ JSON.stringify(params, null, 2) }</pre> </div>
</div> <div>
</div> <pre>{ JSON.stringify(params, null, 2) }</pre>
</div>
</div>
)
}
<div className="confirm-page-container-content__data-box-label"> <div className="confirm-page-container-content__data-box-label">
{`${t('hexData')}:`} {`${t('hexData')}:`}
</div> </div>
@ -297,7 +307,7 @@ export default class ConfirmTransactionBase extends Component {
toName={toName} toName={toName}
toAddress={toAddress} toAddress={toAddress}
showEdit={onEdit && !isTxReprice} showEdit={onEdit && !isTxReprice}
action={action || name} action={action || name || this.context.t('unknownFunction')}
title={title || `${fiatConvertedAmount} ${currentCurrency.toUpperCase()}`} title={title || `${fiatConvertedAmount} ${currentCurrency.toUpperCase()}`}
subtitle={subtitle || `\u2666 ${ethTransactionAmount}`} subtitle={subtitle || `\u2666 ${ethTransactionAmount}`}
hideSubtitle={hideSubtitle} hideSubtitle={hideSubtitle}

@ -8,11 +8,16 @@ import {
CONFIRM_SEND_ETHER_PATH, CONFIRM_SEND_ETHER_PATH,
CONFIRM_SEND_TOKEN_PATH, CONFIRM_SEND_TOKEN_PATH,
CONFIRM_APPROVE_PATH, CONFIRM_APPROVE_PATH,
CONFIRM_TRANSFER_FROM_PATH,
CONFIRM_TOKEN_METHOD_PATH, CONFIRM_TOKEN_METHOD_PATH,
SIGNATURE_REQUEST_PATH, SIGNATURE_REQUEST_PATH,
} from '../../../routes' } from '../../../routes'
import { isConfirmDeployContract } from './confirm-transaction-switch.util' import { isConfirmDeployContract } from './confirm-transaction-switch.util'
import { TOKEN_METHOD_TRANSFER, TOKEN_METHOD_APPROVE } from './confirm-transaction-switch.constants' import {
TOKEN_METHOD_TRANSFER,
TOKEN_METHOD_APPROVE,
TOKEN_METHOD_TRANSFER_FROM,
} from './confirm-transaction-switch.constants'
export default class ConfirmTransactionSwitch extends Component { export default class ConfirmTransactionSwitch extends Component {
static propTypes = { static propTypes = {
@ -27,8 +32,7 @@ export default class ConfirmTransactionSwitch extends Component {
methodData: { name }, methodData: { name },
fetchingMethodData, fetchingMethodData,
} = this.props } = this.props
const { id } = txData const { id, txParams: { data } = {} } = txData
if (isConfirmDeployContract(txData)) { if (isConfirmDeployContract(txData)) {
const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_DEPLOY_CONTRACT_PATH}` const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_DEPLOY_CONTRACT_PATH}`
@ -39,10 +43,10 @@ export default class ConfirmTransactionSwitch extends Component {
return <Loading /> return <Loading />
} }
if (name) { if (data) {
const methodName = name.toLowerCase() const methodName = name && name.toLowerCase()
switch (methodName.toLowerCase()) { switch (methodName) {
case TOKEN_METHOD_TRANSFER: { case TOKEN_METHOD_TRANSFER: {
const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_SEND_TOKEN_PATH}` const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_SEND_TOKEN_PATH}`
return <Redirect to={{ pathname }} /> return <Redirect to={{ pathname }} />
@ -51,6 +55,10 @@ export default class ConfirmTransactionSwitch extends Component {
const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_APPROVE_PATH}` const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_APPROVE_PATH}`
return <Redirect to={{ pathname }} /> return <Redirect to={{ pathname }} />
} }
case TOKEN_METHOD_TRANSFER_FROM: {
const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_TRANSFER_FROM_PATH}`
return <Redirect to={{ pathname }} />
}
default: { default: {
const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_TOKEN_METHOD_PATH}` const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_TOKEN_METHOD_PATH}`
return <Redirect to={{ pathname }} /> return <Redirect to={{ pathname }} />

@ -1,2 +1,3 @@
export const TOKEN_METHOD_TRANSFER = 'transfer' export const TOKEN_METHOD_TRANSFER = 'transfer'
export const TOKEN_METHOD_APPROVE = 'approve' export const TOKEN_METHOD_APPROVE = 'approve'
export const TOKEN_METHOD_TRANSFER_FROM = 'transferfrom'

@ -8,6 +8,7 @@ import ConfirmSendEther from '../confirm-send-ether'
import ConfirmSendToken from '../confirm-send-token' import ConfirmSendToken from '../confirm-send-token'
import ConfirmDeployContract from '../confirm-deploy-contract' import ConfirmDeployContract from '../confirm-deploy-contract'
import ConfirmApprove from '../confirm-approve' import ConfirmApprove from '../confirm-approve'
import ConfirmTokenTransactionBase from '../confirm-token-transaction-base'
import ConfTx from '../../../conf-tx' import ConfTx from '../../../conf-tx'
import { import {
DEFAULT_ROUTE, DEFAULT_ROUTE,
@ -16,6 +17,7 @@ import {
CONFIRM_SEND_ETHER_PATH, CONFIRM_SEND_ETHER_PATH,
CONFIRM_SEND_TOKEN_PATH, CONFIRM_SEND_TOKEN_PATH,
CONFIRM_APPROVE_PATH, CONFIRM_APPROVE_PATH,
CONFIRM_TRANSFER_FROM_PATH,
CONFIRM_TOKEN_METHOD_PATH, CONFIRM_TOKEN_METHOD_PATH,
SIGNATURE_REQUEST_PATH, SIGNATURE_REQUEST_PATH,
} from '../../../routes' } from '../../../routes'
@ -137,6 +139,11 @@ export default class ConfirmTransaction extends Component {
path={`${CONFIRM_TRANSACTION_ROUTE}/:id?${CONFIRM_APPROVE_PATH}`} path={`${CONFIRM_TRANSACTION_ROUTE}/:id?${CONFIRM_APPROVE_PATH}`}
component={ConfirmApprove} component={ConfirmApprove}
/> />
<Route
exact
path={`${CONFIRM_TRANSACTION_ROUTE}/:id?${CONFIRM_TRANSFER_FROM_PATH}`}
component={ConfirmTokenTransactionBase}
/>
<Route <Route
exact exact
path={`${CONFIRM_TRANSACTION_ROUTE}/:id?${SIGNATURE_REQUEST_PATH}`} path={`${CONFIRM_TRANSACTION_ROUTE}/:id?${SIGNATURE_REQUEST_PATH}`}

@ -114,3 +114,20 @@ export function formatCurrency (value, currencyCode) {
? currencyFormatter.format(Number(value), { code: upperCaseCurrencyCode }) ? currencyFormatter.format(Number(value), { code: upperCaseCurrencyCode })
: value : value
} }
export function convertTokenToFiat ({
value,
toCurrency,
conversionRate,
contractExchangeRate,
}) {
const totalExchangeRate = conversionRate * contractExchangeRate
return conversionUtil(value, {
fromNumericBase: 'dec',
toNumericBase: 'dec',
toCurrency,
numberOfDecimals: 2,
conversionRate: totalExchangeRate,
})
}

@ -26,6 +26,7 @@ const CONFIRM_SEND_ETHER_PATH = '/send-ether'
const CONFIRM_SEND_TOKEN_PATH = '/send-token' const CONFIRM_SEND_TOKEN_PATH = '/send-token'
const CONFIRM_DEPLOY_CONTRACT_PATH = '/deploy-contract' const CONFIRM_DEPLOY_CONTRACT_PATH = '/deploy-contract'
const CONFIRM_APPROVE_PATH = '/approve' const CONFIRM_APPROVE_PATH = '/approve'
const CONFIRM_TRANSFER_FROM_PATH = '/transfer-from'
const CONFIRM_TOKEN_METHOD_PATH = '/token-method' const CONFIRM_TOKEN_METHOD_PATH = '/token-method'
const SIGNATURE_REQUEST_PATH = '/signature-request' const SIGNATURE_REQUEST_PATH = '/signature-request'
@ -57,6 +58,7 @@ module.exports = {
CONFIRM_SEND_TOKEN_PATH, CONFIRM_SEND_TOKEN_PATH,
CONFIRM_DEPLOY_CONTRACT_PATH, CONFIRM_DEPLOY_CONTRACT_PATH,
CONFIRM_APPROVE_PATH, CONFIRM_APPROVE_PATH,
CONFIRM_TRANSFER_FROM_PATH,
CONFIRM_TOKEN_METHOD_PATH, CONFIRM_TOKEN_METHOD_PATH,
SIGNATURE_REQUEST_PATH, SIGNATURE_REQUEST_PATH,
} }

@ -1,5 +1,6 @@
import { createSelector } from 'reselect' import { createSelector } from 'reselect'
import txHelper from '../../lib/tx-helper' import txHelper from '../../lib/tx-helper'
import { calcTokenAmount } from '../token-util'
const unapprovedTxsSelector = state => state.metamask.unapprovedTxs const unapprovedTxsSelector = state => state.metamask.unapprovedTxs
const unapprovedMsgsSelector = state => state.metamask.unapprovedMsgs const unapprovedMsgsSelector = state => state.metamask.unapprovedMsgs
@ -63,3 +64,101 @@ export const unconfirmedTransactionsHashSelector = createSelector(
export const currentCurrencySelector = state => state.metamask.currentCurrency export const currentCurrencySelector = state => state.metamask.currentCurrency
export const conversionRateSelector = state => state.metamask.conversionRate export const conversionRateSelector = state => state.metamask.conversionRate
const txDataSelector = state => state.confirmTransaction.txData
const tokenDataSelector = state => state.confirmTransaction.tokenData
const tokenPropsSelector = state => state.confirmTransaction.tokenProps
const contractExchangeRatesSelector = state => state.metamask.contractExchangeRates
const tokenDecimalsSelector = createSelector(
tokenPropsSelector,
tokenProps => tokenProps && tokenProps.tokenDecimals
)
const tokenDataParamsSelector = createSelector(
tokenDataSelector,
tokenData => tokenData && tokenData.params || []
)
const txParamsSelector = createSelector(
txDataSelector,
txData => txData && txData.txParams || {}
)
export const tokenAddressSelector = createSelector(
txParamsSelector,
txParams => txParams && txParams.to
)
const TOKEN_PARAM_SPENDER = '_spender'
const TOKEN_PARAM_TO = '_to'
const TOKEN_PARAM_VALUE = '_value'
export const tokenAmountAndToAddressSelector = createSelector(
tokenDataParamsSelector,
params => {
let toAddress = ''
let tokenAmount = 0
if (params && params.length) {
const toParam = params.find(param => param.name === TOKEN_PARAM_TO)
const valueParam = params.find(param => param.name === TOKEN_PARAM_VALUE)
toAddress = toParam ? toParam.value : params[0].value
tokenAmount = valueParam ? +valueParam.value : +params[1].value
}
return {
toAddress,
tokenAmount,
}
}
)
export const approveTokenAmountAndToAddressSelector = createSelector(
tokenDataParamsSelector,
params => {
let toAddress = ''
let tokenAmount = 0
if (params && params.length) {
toAddress = params.find(param => param.name === TOKEN_PARAM_SPENDER).value
tokenAmount = +params.find(param => param.name === TOKEN_PARAM_VALUE).value
}
return {
toAddress,
tokenAmount,
}
}
)
export const sendTokenTokenAmountAndToAddressSelector = createSelector(
tokenDataParamsSelector,
tokenDecimalsSelector,
(params, tokenDecimals) => {
let toAddress = ''
let tokenAmount = 0
if (params && params.length) {
toAddress = params.find(param => param.name === TOKEN_PARAM_TO).value
tokenAmount = +params.find(param => param.name === TOKEN_PARAM_VALUE).value
if (tokenDecimals) {
tokenAmount = calcTokenAmount(tokenAmount, tokenDecimals)
}
}
return {
toAddress,
tokenAmount,
}
}
)
export const contractExchangeRateSelector = createSelector(
contractExchangeRatesSelector,
tokenAddressSelector,
(contractExchangeRates, tokenAddress) => contractExchangeRates[tokenAddress]
)

Loading…
Cancel
Save