1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 01:39:44 +01:00

Adds 4byte registry fallback to getMethodData() (#6435)

* Get contract method data from 4byte if we can't get it from eth-method-registry

* Clarify token method name fallback code in getMethodData

* Bugfix: don't attempt to translate falsy actionKeys in confirm-transaction-base.component.js

* Rewrite getMethodFrom4Byte with async-await

* Call four byte and method-registry requests in parallel in getMethodData()
This commit is contained in:
Dan J Miller 2019-04-16 17:07:47 -02:30 committed by GitHub
parent 92c03bdff2
commit 09f2a2a547
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 4 deletions

View File

@ -30,6 +30,21 @@ export function getTokenData (data = '') {
return abiDecoder.decodeMethod(data)
}
async function getMethodFrom4Byte (fourBytePrefix) {
const fourByteResponse = (await fetch(`https://www.4byte.directory/api/v1/signatures/?hex_signature=${fourBytePrefix}`, {
referrerPolicy: 'no-referrer-when-downgrade',
body: null,
method: 'GET',
mode: 'cors',
})).json()
if (fourByteResponse.count === 1) {
return fourByteResponse.results[0].text_signature
} else {
return null
}
}
const registry = new MethodRegistry({ provider: global.ethereumProvider })
/**
@ -43,7 +58,16 @@ const registry = new MethodRegistry({ provider: global.ethereumProvider })
const fourBytePrefix = prefixedData.slice(0, 10)
try {
const sig = await registry.lookup(fourBytePrefix)
const fourByteSig = getMethodFrom4Byte(fourBytePrefix).catch((e) => {
log.error(e)
return null
})
let sig = await registry.lookup(fourBytePrefix)
if (!sig) {
sig = await fourByteSig
}
if (!sig) {
return {}
@ -57,8 +81,8 @@ const registry = new MethodRegistry({ provider: global.ethereumProvider })
}
} catch (error) {
log.error(error)
const contractData = getTokenData(data)
const { name } = contractData || {}
const tokenData = getTokenData(data)
const { name } = tokenData || {}
return { name }
}

View File

@ -543,7 +543,7 @@ export default class ConfirmTransactionBase extends Component {
toName={toName}
toAddress={toAddress}
showEdit={onEdit && !isTxReprice}
action={this.context.t(actionKey) || getMethodName(name) || this.context.t('contractInteraction')}
action={actionKey && this.context.t(actionKey) || getMethodName(name) || this.context.t('contractInteraction')}
title={title}
titleComponent={this.renderTitleComponent()}
subtitle={subtitle}