Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getMethodData() default to abi decoded method if registry lookup errors #6367

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions ui/app/ducks/confirm-transaction/confirm-transaction.duck.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import log from 'loglevel'
import {
conversionRateSelector,
currentCurrencySelector,
Expand Down Expand Up @@ -369,23 +370,17 @@ export function setTransactionToConfirm (transactionId) {
const { tokens: existingTokens } = state
const { data, to: tokenAddress } = txParams

try {
dispatch(setFetchingData(true))
const methodData = await getMethodData(data)

dispatch(updateMethodData(methodData))
} catch (error) {
dispatch(updateMethodData({}))
dispatch(setFetchingData(false))
}
dispatch(setFetchingData(true))
const methodData = await getMethodData(data)
dispatch(updateMethodData(methodData))

try {
const toSmartContract = await isSmartContractAddress(to)
dispatch(updateToSmartContract(toSmartContract))
dispatch(setFetchingData(false))
} catch (error) {
dispatch(setFetchingData(false))
log.error(error)
}
dispatch(setFetchingData(false))

const tokenData = getTokenData(data)
dispatch(updateTokenData(tokenData))
Expand Down
37 changes: 24 additions & 13 deletions ui/app/helpers/utils/transactions.util.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
CANCEL_ATTEMPT_ACTION_KEY,
} from '../constants/transactions'

import log from 'loglevel'
import { addCurrencies } from './conversion-util'

abiDecoder.addABI(abi)
Expand All @@ -37,21 +38,31 @@ const registry = new MethodRegistry({ provider: global.ethereumProvider })
* @param {string} data - The hex data (@code txParams.data) of a transaction
* @returns {Object}
*/
export async function getMethodData (data = '') {
const prefixedData = ethUtil.addHexPrefix(data)
const fourBytePrefix = prefixedData.slice(0, 10)
const sig = await registry.lookup(fourBytePrefix)

if (!sig) {
return {}
}
export async function getMethodData (data = '') {
const prefixedData = ethUtil.addHexPrefix(data)
const fourBytePrefix = prefixedData.slice(0, 10)

try {
const sig = await registry.lookup(fourBytePrefix)

if (!sig) {
return {}
}

const parsedResult = registry.parse(sig)

return {
name: parsedResult.name,
params: parsedResult.args,
}
} catch (error) {
log.error(error)
const contractData = getTokenData(data)
const { name } = contractData || {}
return { name }
}

const parsedResult = registry.parse(sig)

return {
name: parsedResult.name,
params: parsedResult.args,
}
}

export function isConfirmDeployContract (txData = {}) {
Expand Down