From 93a290eb3c8bc273772fe6943f152f5e72e4b0bd Mon Sep 17 00:00:00 2001 From: Roman Petriv Date: Mon, 11 Dec 2023 12:14:15 +0200 Subject: [PATCH] fix: ignore parse log errors (#116) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # What ❔ - show logs without parsed event if it fails. ## Why ❔ - currently it shows no logs at all if even one of many logs is failed to parse. This is a quick fix for now. The issue can be reproduced with proxy contracts if there are some events emitted which are defined in the implementation contract. To properly fix it we should use both proxy and implementation ABI. --- packages/app/src/utils/helpers.ts | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/packages/app/src/utils/helpers.ts b/packages/app/src/utils/helpers.ts index ce7a9bbe99..71d2ab80fc 100644 --- a/packages/app/src/utils/helpers.ts +++ b/packages/app/src/utils/helpers.ts @@ -92,20 +92,24 @@ export const mapOrder = (array: any[], order: string[], key: string) => { }); }; -export function decodeLogWithABI(log: TransactionLogEntry, abi: AbiFragment[]): TransactionEvent { +export function decodeLogWithABI(log: TransactionLogEntry, abi: AbiFragment[]): TransactionEvent | undefined { const contractInterface = new utils.Interface(abi); - const decodedLog = contractInterface.parseLog({ - topics: log.topics, - data: log.data, - }); - return { - name: decodedLog.name, - inputs: decodedLog.eventFragment.inputs.map((input) => ({ - name: input.name, - type: input.type as InputType, - value: decodedLog.args[input.name]?.toString(), - })), - }; + try { + const decodedLog = contractInterface.parseLog({ + topics: log.topics, + data: log.data, + }); + return { + name: decodedLog.name, + inputs: decodedLog.eventFragment.inputs.map((input) => ({ + name: input.name, + type: input.type as InputType, + value: decodedLog.args[input.name]?.toString(), + })), + }; + } catch { + return undefined; + } } export function sortTokenTransfers(transfers: TokenTransfer[]): TokenTransfer[] {