1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-12 12:47:14 +01:00
metamask-extension/app/scripts/controllers/network/util.js

50 lines
1.2 KiB
JavaScript
Raw Normal View History

import { NETWORK_TO_NAME_MAP } from '../../../../shared/constants/network';
import { TRANSACTION_ENVELOPE_TYPES } from '../../../../shared/constants/transaction';
2018-04-12 23:17:36 +02:00
export const getNetworkDisplayName = (key) => NETWORK_TO_NAME_MAP[key];
2018-04-12 23:17:36 +02:00
2020-11-03 00:41:28 +01:00
export function formatTxMetaForRpcResult(txMeta) {
const { r, s, v, hash, txReceipt, txParams } = txMeta;
const {
to,
data,
nonce,
gas,
from,
value,
gasPrice,
accessList,
maxFeePerGas,
maxPriorityFeePerGas,
} = txParams;
const formattedTxMeta = {
v,
r,
s,
to,
gas,
from,
hash,
nonce,
input: data || '0x',
value: value || '0x0',
accessList: accessList || null,
blockHash: txReceipt?.blockHash || null,
blockNumber: txReceipt?.blockNumber || null,
transactionIndex: txReceipt?.transactionIndex || null,
};
if (maxFeePerGas && maxPriorityFeePerGas) {
formattedTxMeta.gasPrice = maxFeePerGas;
formattedTxMeta.maxFeePerGas = maxFeePerGas;
formattedTxMeta.maxPriorityFeePerGas = maxPriorityFeePerGas;
formattedTxMeta.type = TRANSACTION_ENVELOPE_TYPES.FEE_MARKET;
} else {
formattedTxMeta.gasPrice = gasPrice;
formattedTxMeta.type = TRANSACTION_ENVELOPE_TYPES.LEGACY;
}
return formattedTxMeta;
}