From a8ab8e8f99ca273a9117b93f1e9348e7add71952 Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Mon, 8 Feb 2021 09:21:50 -0330 Subject: [PATCH] Remove default case for `getTransactionCategoryTitle` The default case of `getTransactionCategoryTitle` wasn't necessary. I audited all cases where the `transactionCategory` property is assigned, and they all assign it to known transaction categories. So it should be impossible for that to be an unrecognized value. The only real case the fallback was useful for was when `null` or `undefined` was given as the transaction category in the confirm transaction base component. That case was handled there instead. --- ui/app/helpers/utils/transactions.util.js | 10 +--------- .../confirm-transaction-base.component.js | 10 +++++----- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/ui/app/helpers/utils/transactions.util.js b/ui/app/helpers/utils/transactions.util.js index 7eec74e8f89f..06a7a269ee19 100644 --- a/ui/app/helpers/utils/transactions.util.js +++ b/ui/app/helpers/utils/transactions.util.js @@ -212,14 +212,9 @@ export function getBlockExplorerUrlForTx(networkId, hash, rpcPrefs = {}) { * This will throw an error if the transaction category is unrecognized and no default is provided. * @param {function} t - The translation function * @param {TRANSACTION_CATEGORIES[keyof TRANSACTION_CATEGORIES]} transactionCategory - The transaction category constant - * @param {string} [defaultTitle] - The default title to return if the transaction cateogory is not recognized. * @returns {string} The transaction category title */ -export function getTransactionCategoryTitle( - t, - transactionCategory, - defaultTitle, -) { +export function getTransactionCategoryTitle(t, transactionCategory) { switch (transactionCategory) { case TRANSACTION_CATEGORIES.TOKEN_METHOD_TRANSFER: { return t('transfer'); @@ -246,9 +241,6 @@ export function getTransactionCategoryTitle( return t('swapApproval'); } default: { - if (defaultTitle) { - return defaultTitle; - } throw new Error( `Unrecognized transaction category: ${transactionCategory}`, ); diff --git a/ui/app/pages/confirm-transaction-base/confirm-transaction-base.component.js b/ui/app/pages/confirm-transaction-base/confirm-transaction-base.component.js index bdf580921e4d..d1b702df9ec2 100644 --- a/ui/app/pages/confirm-transaction-base/confirm-transaction-base.component.js +++ b/ui/app/pages/confirm-transaction-base/confirm-transaction-base.component.js @@ -690,11 +690,11 @@ export default class ConfirmTransactionBase extends Component { let functionType = getMethodName(name); if (!functionType) { - functionType = getTransactionCategoryTitle( - t, - transactionCategory, - transactionCategory || t('contractInteraction'), - ); + if (transactionCategory) { + functionType = getTransactionCategoryTitle(t, transactionCategory); + } else { + functionType = t('contractInteraction'); + } } return (