Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
SEND_TOKEN_ACTION_KEY,
TRANSFER_FROM_ACTION_KEY,
SIGNATURE_REQUEST_KEY,
CONTRACT_INTERACTION_KEY,
CANCEL_ATTEMPT_ACTION_KEY,
} from '../constants/transactions'
import { addCurrencies } from '../conversion-util'
abiDecoder.addABI(abi)
export function getTokenData (data = '') {
return abiDecoder.decodeMethod(data)
}
const registry = new MethodRegistry({ provider: global.ethereumProvider })
/**
* Attempts to return the method data from the MethodRegistry library, if the method exists in the
* registry. Otherwise, returns an empty object.
* @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 {}
}
async function getMethodFrom4Byte (fourBytePrefix) {
const fourByteResponse = (await fetchWithCache(`https://www.4byte.directory/api/v1/signatures/?hex_signature=${fourBytePrefix}`, {
referrerPolicy: 'no-referrer-when-downgrade',
body: null,
method: 'GET',
mode: 'cors',
}))
if (fourByteResponse.count === 1) {
return fourByteResponse.results[0].text_signature
} else {
return null
}
}
const registry = new MethodRegistry({ provider: global.ethereumProvider })
/**
* Attempts to return the method data from the MethodRegistry library, the message registry library and the token abi, in that order of preference
* @param {string} fourBytePrefix - The prefix from the method code associated with the data
* @returns {Object}
*/
export async function getMethodDataAsync (fourBytePrefix) {
try {
const fourByteSig = getMethodFrom4Byte(fourBytePrefix).catch((e) => {
log.error(e)
return null
})
let sig = await registry.lookup(fourBytePrefix)
if (!sig) {