1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 11:22:43 +02:00

Identify token transactions by method names token data, and not just whether they've been add via metamask.

This commit is contained in:
Dan 2018-03-20 09:07:23 -02:30
parent 424e98f6a8
commit dc92b56f18
3 changed files with 13 additions and 5 deletions

View File

@ -86,6 +86,7 @@ function mapDispatchToProps (dispatch, ownProps) {
amount: tokenAmountInHex,
errors: { to: null, amount: null },
editingTransactionId: id,
token: ownProps.token,
}))
dispatch(actions.showSendTokenPage())
},

View File

@ -63,14 +63,17 @@ PendingTx.prototype.componentWillMount = async function () {
isFetching: false,
})
}
const tokenData = txParams && abiDecoder.decodeMethod(txParams.data)
const { name: tokenMethodName } = tokenData || {}
const isTokenTransaction = ['transfer', 'approve', 'transferFrom']
.find(possibleName => tokenMethodName === possibleName)
try {
if (isTokenTransaction) {
const token = util.getContractAtAddress(txParams.to)
const results = await Promise.all([
token.symbol(),
token.decimals(),
])
const [ symbol, decimals ] = results
if (symbol[0] && decimals[0]) {
@ -83,11 +86,14 @@ PendingTx.prototype.componentWillMount = async function () {
})
} else {
this.setState({
transactionType: TX_TYPES.SEND_ETHER,
transactionType: TX_TYPES.SEND_TOKEN,
tokenAddress: txParams.to,
tokenSymbol: null,
tokenDecimals: null,
isFetching: false,
})
}
} catch (e) {
} else {
this.setState({
transactionType: TX_TYPES.SEND_ETHER,
isFetching: false,

View File

@ -55,8 +55,9 @@ function getSelectedToken (state) {
const tokens = state.metamask.tokens || []
const selectedTokenAddress = state.metamask.selectedTokenAddress
const selectedToken = tokens.filter(({ address }) => address === selectedTokenAddress)[0]
const sendToken = state.metamask.send.token
return selectedToken || null
return selectedToken || sendToken || null
}
function getSelectedTokenExchangeRate (state) {