diff options
author | Alexander Tseung <alextsg@gmail.com> | 2018-07-15 04:47:07 +0800 |
---|---|---|
committer | Alexander Tseung <alextsg@gmail.com> | 2018-07-18 04:38:14 +0800 |
commit | d19c42fcaeea933793ed459ab5248b42811a0498 (patch) | |
tree | 345394ef9704fa0afd0d713e4d9ef052bcc943fc /ui/app/selectors | |
parent | e9a8c24cc4d26e33380a33e87e80952918339ad7 (diff) | |
download | tangerine-wallet-browser-d19c42fcaeea933793ed459ab5248b42811a0498.tar tangerine-wallet-browser-d19c42fcaeea933793ed459ab5248b42811a0498.tar.gz tangerine-wallet-browser-d19c42fcaeea933793ed459ab5248b42811a0498.tar.bz2 tangerine-wallet-browser-d19c42fcaeea933793ed459ab5248b42811a0498.tar.lz tangerine-wallet-browser-d19c42fcaeea933793ed459ab5248b42811a0498.tar.xz tangerine-wallet-browser-d19c42fcaeea933793ed459ab5248b42811a0498.tar.zst tangerine-wallet-browser-d19c42fcaeea933793ed459ab5248b42811a0498.zip |
Add fallback when no function found, fix network colors, add fiat values for tokens with contract exchange rates
Diffstat (limited to 'ui/app/selectors')
-rw-r--r-- | ui/app/selectors/confirm-transaction.js | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/ui/app/selectors/confirm-transaction.js b/ui/app/selectors/confirm-transaction.js index cde83804d..5f1ae225c 100644 --- a/ui/app/selectors/confirm-transaction.js +++ b/ui/app/selectors/confirm-transaction.js @@ -1,5 +1,6 @@ import { createSelector } from 'reselect' import txHelper from '../../lib/tx-helper' +import { calcTokenAmount } from '../token-util' const unapprovedTxsSelector = state => state.metamask.unapprovedTxs const unapprovedMsgsSelector = state => state.metamask.unapprovedMsgs @@ -63,3 +64,101 @@ export const unconfirmedTransactionsHashSelector = createSelector( export const currentCurrencySelector = state => state.metamask.currentCurrency 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] +) |