Skip to content

Commit

Permalink
use an array for types
Browse files Browse the repository at this point in the history
  • Loading branch information
brad-decker committed Apr 20, 2022
1 parent 10cfc1e commit ba889b0
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions app/scripts/controllers/transactions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ const SWAP_TRANSACTION_TYPES = [
TRANSACTION_TYPES.SWAP_APPROVAL,
];

// Only certain types of transactions should be allowed to be specified when
// adding a new unapproved transaction.
const VALID_UNAPPROVED_TRANSACTION_TYPES = [
...SWAP_TRANSACTION_TYPES,
TRANSACTION_TYPES.SIMPLE_SEND,
TRANSACTION_TYPES.TOKEN_METHOD_TRANSFER,
TRANSACTION_TYPES.TOKEN_METHOD_TRANSFER_FROM,
];

/**
* @typedef {import('../../../../shared/constants/transaction').TransactionMeta} TransactionMeta
* @typedef {import('../../../../shared/constants/transaction').TransactionMetaMetricsEventString} TransactionMetaMetricsEventString
Expand Down Expand Up @@ -650,12 +659,7 @@ export default class TransactionController extends EventEmitter {
async addUnapprovedTransaction(txParams, origin, transactionType) {
if (
transactionType !== undefined &&
!(
SWAP_TRANSACTION_TYPES.includes(transactionType) ||
transactionType === TRANSACTION_TYPES.SIMPLE_SEND ||
transactionType === TRANSACTION_TYPES.TOKEN_METHOD_TRANSFER ||
transactionType === TRANSACTION_TYPES.TOKEN_METHOD_TRANSFER_FROM
)
!VALID_UNAPPROVED_TRANSACTION_TYPES.includes(transactionType)
) {
throw new Error(
`TransactionController - invalid transactionType value: ${transactionType}`,
Expand Down

0 comments on commit ba889b0

Please sign in to comment.