mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
3732c5f71e
ESLint rules have been added to enforce our JSDoc conventions. These rules were introduced by updating `@metamask/eslint-config` to v9. Some of the rules have been disabled because the effort to fix all lint errors was too high. It might be easiest to enable these rules one directory at a time, or one rule at a time. Most of the changes in this PR were a result of running `yarn lint:fix`. There were a handful of manual changes that seemed obvious and simple to make. Anything beyond that and the rule was left disabled.
64 lines
2.3 KiB
JavaScript
64 lines
2.3 KiB
JavaScript
import { isHexString } from 'ethereumjs-util';
|
|
|
|
export function transactionMatchesNetwork(transaction, chainId, networkId) {
|
|
if (typeof transaction.chainId !== 'undefined') {
|
|
return transaction.chainId === chainId;
|
|
}
|
|
return transaction.metamaskNetworkId === networkId;
|
|
}
|
|
|
|
/**
|
|
* Determines if the maxFeePerGas and maxPriorityFeePerGas fields are supplied
|
|
* and valid inputs. This will return false for non hex string inputs.
|
|
*
|
|
* @param {import("../constants/transaction").TransactionMeta} transaction -
|
|
* the transaction to check
|
|
* @returns {boolean} true if transaction uses valid EIP1559 fields
|
|
*/
|
|
export function isEIP1559Transaction(transaction) {
|
|
return (
|
|
isHexString(transaction?.txParams?.maxFeePerGas) &&
|
|
isHexString(transaction?.txParams?.maxPriorityFeePerGas)
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Determine if the maxFeePerGas and maxPriorityFeePerGas fields are not
|
|
* supplied and that the gasPrice field is valid if it is provided. This will
|
|
* return false if gasPrice is a non hex string.
|
|
*
|
|
* @param {import("../constants/transaction").TransactionMeta} transaction -
|
|
* the transaction to check
|
|
* @returns {boolean} true if transaction uses valid Legacy fields OR lacks
|
|
* EIP1559 fields
|
|
*/
|
|
export function isLegacyTransaction(transaction) {
|
|
return (
|
|
typeof transaction.txParams.maxFeePerGas === 'undefined' &&
|
|
typeof transaction.txParams.maxPriorityFeePerGas === 'undefined' &&
|
|
(typeof transaction.txParams.gasPrice === 'undefined' ||
|
|
isHexString(transaction.txParams.gasPrice))
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Determine if a transactions gas fees in txParams match those in its dappSuggestedGasFees property
|
|
*
|
|
* @param {import("../constants/transaction").TransactionMeta} transaction -
|
|
* the transaction to check
|
|
* @returns {boolean} true if both the txParams and dappSuggestedGasFees are objects with truthy gas fee properties,
|
|
* and those properties are strictly equal
|
|
*/
|
|
export function txParamsAreDappSuggested(transaction) {
|
|
const { gasPrice, maxPriorityFeePerGas, maxFeePerGas } =
|
|
transaction?.txParams || {};
|
|
return (
|
|
(gasPrice && gasPrice === transaction?.dappSuggestedGasFees?.gasPrice) ||
|
|
(maxPriorityFeePerGas &&
|
|
maxFeePerGas &&
|
|
transaction?.dappSuggestedGasFees?.maxPriorityFeePerGas ===
|
|
maxPriorityFeePerGas &&
|
|
transaction?.dappSuggestedGasFees?.maxFeePerGas === maxFeePerGas)
|
|
);
|
|
}
|