mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Remove unused methods from one of the many utils files (#7702)
This commit is contained in:
parent
237d0b4d41
commit
2a8e586142
@ -1,12 +0,0 @@
|
|||||||
const ethUtil = (/** @type {object} */ (require('ethereumjs-util')))
|
|
||||||
const BN = ethUtil.BN
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a [BinaryNumber]{@link BN} representation of the given hex value
|
|
||||||
* @param {string} hex
|
|
||||||
* @return {any}
|
|
||||||
*/
|
|
||||||
module.exports = function hexToBn (hex) {
|
|
||||||
return new BN(ethUtil.stripHexPrefix(hex), 16)
|
|
||||||
}
|
|
||||||
|
|
@ -1,12 +1,7 @@
|
|||||||
const abi = require('human-standard-token-abi')
|
const abi = require('human-standard-token-abi')
|
||||||
const ethUtil = require('ethereumjs-util')
|
const ethUtil = require('ethereumjs-util')
|
||||||
const hexToBn = require('../../../../app/scripts/lib/hex-to-bn')
|
|
||||||
import { DateTime } from 'luxon'
|
import { DateTime } from 'luxon'
|
||||||
|
|
||||||
const MIN_GAS_PRICE_GWEI_BN = new ethUtil.BN(1)
|
|
||||||
const GWEI_FACTOR = new ethUtil.BN(1e9)
|
|
||||||
const MIN_GAS_PRICE_BN = MIN_GAS_PRICE_GWEI_BN.mul(GWEI_FACTOR)
|
|
||||||
|
|
||||||
// formatData :: ( date: <Unix Timestamp> ) -> String
|
// formatData :: ( date: <Unix Timestamp> ) -> String
|
||||||
function formatDate (date, format = 'M/d/y \'at\' T') {
|
function formatDate (date, format = 'M/d/y \'at\' T') {
|
||||||
return DateTime.fromMillis(date).toFormat(format)
|
return DateTime.fromMillis(date).toFormat(format)
|
||||||
@ -33,16 +28,12 @@ for (const currency in valueTable) {
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
valuesFor: valuesFor,
|
valuesFor: valuesFor,
|
||||||
addressSummary: addressSummary,
|
addressSummary: addressSummary,
|
||||||
miniAddressSummary: miniAddressSummary,
|
|
||||||
isAllOneCase: isAllOneCase,
|
|
||||||
isValidAddress: isValidAddress,
|
isValidAddress: isValidAddress,
|
||||||
isValidENSAddress,
|
isValidENSAddress,
|
||||||
numericBalance: numericBalance,
|
numericBalance: numericBalance,
|
||||||
parseBalance: parseBalance,
|
parseBalance: parseBalance,
|
||||||
formatBalance: formatBalance,
|
formatBalance: formatBalance,
|
||||||
generateBalanceObject: generateBalanceObject,
|
generateBalanceObject: generateBalanceObject,
|
||||||
dataSize: dataSize,
|
|
||||||
readableDate: readableDate,
|
|
||||||
normalizeToWei: normalizeToWei,
|
normalizeToWei: normalizeToWei,
|
||||||
normalizeEthStringToWei: normalizeEthStringToWei,
|
normalizeEthStringToWei: normalizeEthStringToWei,
|
||||||
normalizeNumberToWei: normalizeNumberToWei,
|
normalizeNumberToWei: normalizeNumberToWei,
|
||||||
@ -50,13 +41,8 @@ module.exports = {
|
|||||||
bnTable: bnTable,
|
bnTable: bnTable,
|
||||||
isHex: isHex,
|
isHex: isHex,
|
||||||
formatDate,
|
formatDate,
|
||||||
bnMultiplyByFraction,
|
|
||||||
getTxFeeBn,
|
|
||||||
shortenBalance,
|
|
||||||
getContractAtAddress,
|
getContractAtAddress,
|
||||||
exportAsFile: exportAsFile,
|
exportAsFile: exportAsFile,
|
||||||
isInvalidChecksumAddress,
|
|
||||||
allNull,
|
|
||||||
getTokenAddressFromTokenObject,
|
getTokenAddressFromTokenObject,
|
||||||
checksumAddress,
|
checksumAddress,
|
||||||
addressSlicer,
|
addressSlicer,
|
||||||
@ -94,14 +80,6 @@ function addressSummary (address, firstSegLength = 10, lastSegLength = 4, includ
|
|||||||
return checked ? checked.slice(0, firstSegLength) + '...' + checked.slice(checked.length - lastSegLength) : '...'
|
return checked ? checked.slice(0, firstSegLength) + '...' + checked.slice(checked.length - lastSegLength) : '...'
|
||||||
}
|
}
|
||||||
|
|
||||||
function miniAddressSummary (address) {
|
|
||||||
if (!address) {
|
|
||||||
return ''
|
|
||||||
}
|
|
||||||
const checked = checksumAddress(address)
|
|
||||||
return checked ? checked.slice(0, 4) + '...' + checked.slice(-4) : '...'
|
|
||||||
}
|
|
||||||
|
|
||||||
function isValidAddress (address) {
|
function isValidAddress (address) {
|
||||||
const prefixed = ethUtil.addHexPrefix(address)
|
const prefixed = ethUtil.addHexPrefix(address)
|
||||||
if (address === '0x0000000000000000000000000000000000000000') {
|
if (address === '0x0000000000000000000000000000000000000000') {
|
||||||
@ -114,14 +92,6 @@ function isValidENSAddress (address) {
|
|||||||
return address.match(/^.{3,}\.(eth|test|xyz)$/)
|
return address.match(/^.{3,}\.(eth|test|xyz)$/)
|
||||||
}
|
}
|
||||||
|
|
||||||
function isInvalidChecksumAddress (address) {
|
|
||||||
const prefixed = ethUtil.addHexPrefix(address)
|
|
||||||
if (address === '0x0000000000000000000000000000000000000000') {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return !isAllOneCase(prefixed) && !ethUtil.isValidChecksumAddress(prefixed) && ethUtil.isValidAddress(prefixed)
|
|
||||||
}
|
|
||||||
|
|
||||||
function isAllOneCase (address) {
|
function isAllOneCase (address) {
|
||||||
if (!address) {
|
if (!address) {
|
||||||
return true
|
return true
|
||||||
@ -228,11 +198,6 @@ function shortenBalance (balance, decimalsToKeep = 1) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function dataSize (data) {
|
|
||||||
const size = data ? ethUtil.stripHexPrefix(data).length : 0
|
|
||||||
return size + ' bytes'
|
|
||||||
}
|
|
||||||
|
|
||||||
// Takes a BN and an ethereum currency name,
|
// Takes a BN and an ethereum currency name,
|
||||||
// returns a BN in wei
|
// returns a BN in wei
|
||||||
function normalizeToWei (amount, currency) {
|
function normalizeToWei (amount, currency) {
|
||||||
@ -266,38 +231,10 @@ function normalizeNumberToWei (n, currency) {
|
|||||||
return normalizeToWei(amount, currency).div(multiple)
|
return normalizeToWei(amount, currency).div(multiple)
|
||||||
}
|
}
|
||||||
|
|
||||||
function readableDate (ms) {
|
|
||||||
const date = new Date(ms)
|
|
||||||
const month = date.getMonth()
|
|
||||||
const day = date.getDate()
|
|
||||||
const year = date.getFullYear()
|
|
||||||
const hours = date.getHours()
|
|
||||||
const minutes = '0' + date.getMinutes()
|
|
||||||
const seconds = '0' + date.getSeconds()
|
|
||||||
|
|
||||||
const dateStr = `${month}/${day}/${year}`
|
|
||||||
const time = `${hours}:${minutes.substr(-2)}:${seconds.substr(-2)}`
|
|
||||||
return `${dateStr} ${time}`
|
|
||||||
}
|
|
||||||
|
|
||||||
function isHex (str) {
|
function isHex (str) {
|
||||||
return Boolean(str.match(/^(0x)?[0-9a-fA-F]+$/))
|
return Boolean(str.match(/^(0x)?[0-9a-fA-F]+$/))
|
||||||
}
|
}
|
||||||
|
|
||||||
function bnMultiplyByFraction (targetBN, numerator, denominator) {
|
|
||||||
const numBN = new ethUtil.BN(numerator)
|
|
||||||
const denomBN = new ethUtil.BN(denominator)
|
|
||||||
return targetBN.mul(numBN).div(denomBN)
|
|
||||||
}
|
|
||||||
|
|
||||||
function getTxFeeBn (gas, gasPrice = MIN_GAS_PRICE_BN.toString(16)) {
|
|
||||||
const gasBn = hexToBn(gas)
|
|
||||||
const gasPriceBn = hexToBn(gasPrice)
|
|
||||||
const txFeeBn = gasBn.mul(gasPriceBn)
|
|
||||||
|
|
||||||
return txFeeBn.toString(16)
|
|
||||||
}
|
|
||||||
|
|
||||||
function getContractAtAddress (tokenAddress) {
|
function getContractAtAddress (tokenAddress) {
|
||||||
return global.eth.contract(abi).at(tokenAddress)
|
return global.eth.contract(abi).at(tokenAddress)
|
||||||
}
|
}
|
||||||
@ -318,10 +255,6 @@ function exportAsFile (filename, data, type = 'text/csv') {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function allNull (obj) {
|
|
||||||
return Object.entries(obj).every(([_, value]) => value === null)
|
|
||||||
}
|
|
||||||
|
|
||||||
function getTokenAddressFromTokenObject (token) {
|
function getTokenAddressFromTokenObject (token) {
|
||||||
return Object.values(token)[0].address.toLowerCase()
|
return Object.values(token)[0].address.toLowerCase()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user