diff --git a/app/scripts/lib/util.js b/app/scripts/lib/util.js index 126e5c4f6..9c343ecf6 100644 --- a/app/scripts/lib/util.js +++ b/app/scripts/lib/util.js @@ -1,4 +1,3 @@ -import { strict as assert } from 'assert'; import extension from 'extensionizer'; import { stripHexPrefix } from 'ethereumjs-util'; import BN from 'bn.js'; @@ -70,39 +69,6 @@ const getPlatform = (_) => { return PLATFORM_FIREFOX; }; -/** - * Checks whether a given balance of ETH, represented as a hex string, is sufficient to pay a value plus a gas fee - * - * @param {Object} txParams - Contains data about a transaction - * @param {string} txParams.gas - The gas for a transaction - * @param {string} txParams.gasPrice - The price per gas for the transaction - * @param {string} txParams.value - The value of ETH to send - * @param {string} hexBalance - A balance of ETH represented as a hex string - * @returns {boolean} Whether the balance is greater than or equal to the value plus the value of gas times gasPrice - * - */ -function sufficientBalance(txParams, hexBalance) { - // validate hexBalance is a hex string - assert.equal( - typeof hexBalance, - 'string', - 'sufficientBalance - hexBalance is not a hex string', - ); - assert.equal( - hexBalance.slice(0, 2), - '0x', - 'sufficientBalance - hexBalance is not a hex string', - ); - - const balance = hexToBn(hexBalance); - const value = hexToBn(txParams.value); - const gasLimit = hexToBn(txParams.gas); - const gasPrice = hexToBn(txParams.gasPrice); - - const maxCost = value.add(gasLimit.mul(gasPrice)); - return balance.gte(maxCost); -} - /** * Converts a hex string to a BN object * @@ -183,7 +149,6 @@ function bnToHex(inputBn) { export { getPlatform, getEnvironmentType, - sufficientBalance, hexToBn, BnMultiplyByFraction, checkForError, diff --git a/app/scripts/lib/util.test.js b/app/scripts/lib/util.test.js index c2753df56..f21c10d5e 100644 --- a/app/scripts/lib/util.test.js +++ b/app/scripts/lib/util.test.js @@ -7,7 +7,7 @@ import { ENVIRONMENT_TYPE_FULLSCREEN, ENVIRONMENT_TYPE_BACKGROUND, } from '../../../shared/constants/app'; -import { getEnvironmentType, sufficientBalance } from './util'; +import { getEnvironmentType } from './util'; describe('app utils', function () { describe('getEnvironmentType', function () { @@ -68,44 +68,6 @@ describe('app utils', function () { }); }); - describe('SufficientBalance', function () { - it('returns true if max tx cost is equal to balance.', function () { - const tx = { - value: '0x1', - gas: '0x2', - gasPrice: '0x3', - }; - const balance = '0x8'; - - const result = sufficientBalance(tx, balance); - assert.ok(result, 'sufficient balance found.'); - }); - - it('returns true if max tx cost is less than balance.', function () { - const tx = { - value: '0x1', - gas: '0x2', - gasPrice: '0x3', - }; - const balance = '0x9'; - - const result = sufficientBalance(tx, balance); - assert.ok(result, 'sufficient balance found.'); - }); - - it('returns false if max tx cost is more than balance.', function () { - const tx = { - value: '0x1', - gas: '0x2', - gasPrice: '0x3', - }; - const balance = '0x6'; - - const result = sufficientBalance(tx, balance); - assert.ok(!result, 'insufficient balance found.'); - }); - }); - describe('isPrefixedFormattedHexString', function () { it('should return true for valid hex strings', function () { assert.equal(