Skip to content

Commit

Permalink
Remove default case for getTransactionCategoryTitle
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Gudahtt committed Feb 8, 2021
1 parent b650cf2 commit a8ab8e8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
10 changes: 1 addition & 9 deletions ui/app/helpers/utils/transactions.util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -246,9 +241,6 @@ export function getTransactionCategoryTitle(
return t('swapApproval');
}
default: {
if (defaultTitle) {
return defaultTitle;
}
throw new Error(
`Unrecognized transaction category: ${transactionCategory}`,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit a8ab8e8

Please sign in to comment.