From 6a77dc36ed4f6385b292662be80b22998ba37d86 Mon Sep 17 00:00:00 2001 From: aboutmydreams Date: Fri, 2 Sep 2022 21:31:17 +0800 Subject: [PATCH] fix: constList.params[0].data is undefined --- .../ProxyEthereum.jsx | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/content-scripts-proxy-ethereum/ProxyEthereum.jsx b/src/content-scripts-proxy-ethereum/ProxyEthereum.jsx index 126175f..c7bdff8 100644 --- a/src/content-scripts-proxy-ethereum/ProxyEthereum.jsx +++ b/src/content-scripts-proxy-ethereum/ProxyEthereum.jsx @@ -26,16 +26,31 @@ export default class ProxyEthereum { isNotableAction(constList) { // 检查是否为关注的交易 - const notableActionList = ['approve', 'setApprovalForAll', 'transfer', 'safeTransferFrom', 'safeTransferFrom1']; - if (typeof constList.method !== 'undefined') { - if (constList.method === 'eth_sendTransaction') { - const functionName = dictionary[constList.params[0].data.substring(0, 10)]; - if (notableActionList.includes(functionName)) { - return { result: true, action: functionName }; + try { + const notableActionList = ['approve', 'setApprovalForAll', 'transfer', 'safeTransferFrom', 'safeTransferFrom1']; + if (typeof constList.method !== 'undefined') { + if (constList.method === 'eth_sendTransaction') { + let functionName; + + // 当 params 长度为 0 或 params[0].data 为 undefined 时 + if (constList.params.length === 0) { + functionName = 'transfer'; + } else if (constList.params[0].data === undefined) { + functionName = 'transfer'; + } else { + functionName = dictionary[constList.params[0].data.substring(0, 10)]; + } + + if (notableActionList.includes(functionName)) { + return { result: true, action: functionName }; + } } } + return { result: false }; + + } catch (error) { + return { result: false }; } - return { result: false }; } getDrawerType(domainVerificationData) {