1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Use string literals for transaction category localized messages (#10391)

We now use string literals for all transaction category localized
messages. This makes it easier to verify that we have translations for
each of them, and that we aren't leaving any unused translations around.
This commit is contained in:
Mark Stacey 2021-02-08 12:36:58 -03:30 committed by GitHub
parent aadb8ac0ac
commit b93046bdab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 3 deletions

View File

@ -205,3 +205,45 @@ export function getBlockExplorerUrlForTx(networkId, hash, rpcPrefs = {}) {
const prefix = getEtherscanNetworkPrefix(networkId);
return `https://${prefix}etherscan.io/tx/${hash}`;
}
/**
* Returns a title for the given transaction category.
*
* 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
* @returns {string} The transaction category title
*/
export function getTransactionCategoryTitle(t, transactionCategory) {
switch (transactionCategory) {
case TRANSACTION_CATEGORIES.TOKEN_METHOD_TRANSFER: {
return t('transfer');
}
case TRANSACTION_CATEGORIES.TOKEN_METHOD_TRANSFER_FROM: {
return t('transferfrom');
}
case TRANSACTION_CATEGORIES.TOKEN_METHOD_APPROVE: {
return t('approve');
}
case TRANSACTION_CATEGORIES.SENT_ETHER: {
return t('sentEther');
}
case TRANSACTION_CATEGORIES.CONTRACT_INTERACTION: {
return t('contractInteraction');
}
case TRANSACTION_CATEGORIES.DEPLOY_CONTRACT: {
return t('contractDeployment');
}
case TRANSACTION_CATEGORIES.SWAP: {
return t('swap');
}
case TRANSACTION_CATEGORIES.SWAP_APPROVAL: {
return t('swapApproval');
}
default: {
throw new Error(
`Unrecognized transaction category: ${transactionCategory}`,
);
}
}
}

View File

@ -1,6 +1,9 @@
import { useSelector } from 'react-redux';
import { getKnownMethodData } from '../selectors/selectors';
import { getStatusKey } from '../helpers/utils/transactions.util';
import {
getStatusKey,
getTransactionCategoryTitle,
} from '../helpers/utils/transactions.util';
import { camelCaseToCapitalize } from '../helpers/utils/common.util';
import { PRIMARY, SECONDARY } from '../helpers/constants/common';
import { getTokenAddressParam } from '../helpers/utils/token-util';
@ -186,9 +189,13 @@ export function useTransactionDisplayData(transactionGroup) {
transactionCategory === TRANSACTION_CATEGORIES.CONTRACT_INTERACTION
) {
category = TRANSACTION_GROUP_CATEGORIES.INTERACTION;
const transactionCategoryTitle = getTransactionCategoryTitle(
t,
transactionCategory,
);
title =
(methodData?.name && camelCaseToCapitalize(methodData.name)) ||
t(transactionCategory);
transactionCategoryTitle;
subtitle = origin;
subtitleContainsOrigin = true;
} else if (transactionCategory === TRANSACTION_CATEGORIES.INCOMING) {

View File

@ -22,6 +22,7 @@ import {
TRANSACTION_CATEGORIES,
TRANSACTION_STATUSES,
} from '../../../../shared/constants/transaction';
import { getTransactionCategoryTitle } from '../../helpers/utils/transactions.util';
export default class ConfirmTransactionBase extends Component {
static contextTypes = {
@ -690,7 +691,7 @@ export default class ConfirmTransactionBase extends Component {
let functionType = getMethodName(name);
if (!functionType) {
if (transactionCategory) {
functionType = t(transactionCategory) || transactionCategory;
functionType = getTransactionCategoryTitle(t, transactionCategory);
} else {
functionType = t('contractInteraction');
}