Skip to content

Commit

Permalink
fix: check if tx is eligible for translation
Browse files Browse the repository at this point in the history
  • Loading branch information
lrnt committed Jan 17, 2023
1 parent f4de141 commit 9b37cca
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 5 additions & 1 deletion extension/src/transactionTranslations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
10 changes: 6 additions & 4 deletions extension/src/transactionTranslations/uniswapMulticall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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

0 comments on commit 9b37cca

Please sign in to comment.