aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/send/send-v2-container.js
blob: 5935a8feebc53debaa186937c70c7eef9a70d41f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const connect = require('react-redux').connect
const actions = require('../../actions')
const abi = require('ethereumjs-abi')
const SendEther = require('../../send-v2')

const { multiplyCurrencies } = require('../../conversion-util')

const {
  accountsWithSendEtherInfoSelector,
  getCurrentAccountWithSendEtherInfo,
  conversionRateSelector,
  getSelectedToken,
  getSelectedTokenExchangeRate,
  getSelectedAddress,
  getGasPrice,
  getGasLimit,
} = require('../../selectors')

module.exports = connect(mapStateToProps, mapDispatchToProps)(SendEther)

function mapStateToProps (state) {
  const selectedAddress = getSelectedAddress(state);
  const selectedToken = getSelectedToken(state);
  const tokenExchangeRates = state.metamask.tokenExchangeRates
  const selectedTokenExchangeRate = getSelectedTokenExchangeRate(state)
  const conversionRate = conversionRateSelector(state)

  let data;
  let primaryCurrency;
  let tokenToUSDRate;
  if (selectedToken) {
    data = Array.prototype.map.call(
      abi.rawEncode(['address', 'uint256'], [selectedAddress, '0x0']),
      x => ('00' + x.toString(16)).slice(-2)
    ).join('')

    primaryCurrency = selectedToken.symbol

    tokenToUSDRate = multiplyCurrencies(
      conversionRate,
      selectedTokenExchangeRate,
      { toNumericBase: 'dec' }
    )
  }

  return {
    selectedAccount: getCurrentAccountWithSendEtherInfo(state),
    accounts: accountsWithSendEtherInfoSelector(state),
    conversionRate,
    selectedToken,
    primaryCurrency,
    data,
    tokenToUSDRate,
    gasPrice: getGasPrice(state),
    gasLimit: getGasLimit(state),
  }
}

function mapDispatchToProps (dispatch) {
  return {
    showCustomizeGasModal: () => dispatch(actions.showModal({ name: 'CUSTOMIZE_GAS' })),
    estimateGas: params => dispatch(actions.estimateGas(params)),
    getGasPrice: () => dispatch(actions.getGasPrice()),
    updateTokenExchangeRate: token => dispatch(actions.updateTokenExchangeRate(token)),
    signTokenTx: (tokenAddress, toAddress, amount, txData) => (
      dispatch(actions.signTokenTx(tokenAddress, toAddress, amount, txData))
    ),
    signTx: txParams => dispatch(actions.signTx(txParams)),
    setSelectedAddress: address => dispatch(actions.setSelectedAddress(address))
  }
}