From 9b37ccae6ddc292a61f1763114195dc9bf6a68c4 Mon Sep 17 00:00:00 2001 From: Laurent De Marez Date: Tue, 17 Jan 2023 15:57:53 +0100 Subject: [PATCH 1/2] fix: check if tx is eligible for translation --- extension/src/transactionTranslations/index.ts | 6 +++++- .../src/transactionTranslations/uniswapMulticall.ts | 10 ++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/extension/src/transactionTranslations/index.ts b/extension/src/transactionTranslations/index.ts index 1b55ba8a..49d21d22 100644 --- a/extension/src/transactionTranslations/index.ts +++ b/extension/src/transactionTranslations/index.ts @@ -9,7 +9,11 @@ export const findApplicableTranslation = ( transaction: MetaTransaction ): TransactionTranslation | undefined => { for (const translation of translations) { - if (translation.translate(transaction)) return translation + try { + if (translation.translate(transaction)) return translation + } catch (e) { + continue + } } return undefined } diff --git a/extension/src/transactionTranslations/uniswapMulticall.ts b/extension/src/transactionTranslations/uniswapMulticall.ts index eb0f263d..fe550db4 100644 --- a/extension/src/transactionTranslations/uniswapMulticall.ts +++ b/extension/src/transactionTranslations/uniswapMulticall.ts @@ -15,7 +15,9 @@ export default { recommendedFor: [KnownContracts.ROLES], translate: (transaction) => { - if (!transaction.data) return [transaction] + if (!transaction.data) { + throw Error("Invalid translation: transaction doesn't have data") + } let functionCalls: string[] = [] for (const fragment of uniswapMulticallInterface.fragments) { @@ -31,10 +33,10 @@ export default { } } - if (functionCalls.length > 0) { - return functionCalls.map((data) => ({ ...transaction, data })) + if (functionCalls.length === 0) { + throw Error("Invalid translation: couldn't decode function data") } - return [transaction] + return functionCalls.map((data) => ({ ...transaction, data })) }, } satisfies TransactionTranslation From 2a6bbe768f2fbf4e05f7d3cc6fbda92cd6c1cade Mon Sep 17 00:00:00 2001 From: Laurent De Marez Date: Tue, 17 Jan 2023 16:19:09 +0100 Subject: [PATCH 2/2] fix: undefined if tx not eligible for translation --- extension/src/transactionTranslations/index.ts | 6 +----- extension/src/transactionTranslations/uniswapMulticall.ts | 4 ++-- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/extension/src/transactionTranslations/index.ts b/extension/src/transactionTranslations/index.ts index 49d21d22..1b55ba8a 100644 --- a/extension/src/transactionTranslations/index.ts +++ b/extension/src/transactionTranslations/index.ts @@ -9,11 +9,7 @@ export const findApplicableTranslation = ( transaction: MetaTransaction ): TransactionTranslation | undefined => { for (const translation of translations) { - try { - if (translation.translate(transaction)) return translation - } catch (e) { - continue - } + if (translation.translate(transaction)) return translation } return undefined } diff --git a/extension/src/transactionTranslations/uniswapMulticall.ts b/extension/src/transactionTranslations/uniswapMulticall.ts index fe550db4..445feee7 100644 --- a/extension/src/transactionTranslations/uniswapMulticall.ts +++ b/extension/src/transactionTranslations/uniswapMulticall.ts @@ -16,7 +16,7 @@ export default { translate: (transaction) => { if (!transaction.data) { - throw Error("Invalid translation: transaction doesn't have data") + return undefined } let functionCalls: string[] = [] @@ -34,7 +34,7 @@ export default { } if (functionCalls.length === 0) { - throw Error("Invalid translation: couldn't decode function data") + return undefined } return functionCalls.map((data) => ({ ...transaction, data }))