mirror of https://github.com/status-im/web3.js.git
Removed circular dependencies
This commit is contained in:
parent
188e9e5325
commit
ce141d8ec3
|
@ -1441,6 +1441,10 @@ module.exports = {
|
|||
|
||||
var c = require('./const');
|
||||
|
||||
if ("build" !== 'build') {/*
|
||||
var BigNumber = require('bignumber.js'); // jshint ignore:line
|
||||
*/}
|
||||
|
||||
/// Finds first index of array element matching pattern
|
||||
/// @param array
|
||||
/// @param callback pattern
|
||||
|
@ -1551,6 +1555,11 @@ var toEth = function (str) {
|
|||
return s + ' ' + units[unit];
|
||||
};
|
||||
|
||||
var toDecimal = function (val) {
|
||||
// remove 0x and place 0, if it's required
|
||||
val = val.length > 2 ? val.substring(2) : "0";
|
||||
return (new BigNumber(val, 16).toString(10));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
|
@ -1581,7 +1590,7 @@ var fromWei = function(number, unit) {
|
|||
return number;
|
||||
|
||||
if(typeof number === 'string' && number.indexOf('0x') === 0)
|
||||
number = web3.toDecimal(number);
|
||||
number = toDecimal(number);
|
||||
|
||||
if(!(number instanceof BigNumber)) {
|
||||
isBigNumber = false;
|
||||
|
@ -1660,7 +1669,7 @@ var toWei = function(number, unit) {
|
|||
return number;
|
||||
|
||||
if(typeof number === 'string' && number.indexOf('0x') === 0)
|
||||
number = web3.toDecimal(number);
|
||||
number = toDecimal(number);
|
||||
|
||||
if(!(number instanceof BigNumber)) {
|
||||
isBigNumber = false;
|
||||
|
@ -1731,6 +1740,7 @@ var isAddress = function(address) {
|
|||
|
||||
module.exports = {
|
||||
findIndex: findIndex,
|
||||
toDecimal: toDecimal,
|
||||
toAscii: toAscii,
|
||||
fromAscii: fromAscii,
|
||||
extractDisplayName: extractDisplayName,
|
||||
|
@ -1950,11 +1960,7 @@ var web3 = {
|
|||
fromAscii: utils.fromAscii,
|
||||
|
||||
/// @returns decimal representaton of hex value prefixed by 0x
|
||||
toDecimal: function (val) {
|
||||
// remove 0x and place 0, if it's required
|
||||
val = val.length > 2 ? val.substring(2) : "0";
|
||||
return (new BigNumber(val, 16).toString(10));
|
||||
},
|
||||
toDecimal: utils.toDecimal,
|
||||
|
||||
/// @returns hex representation (prefixed by 0x) of decimal value
|
||||
fromDecimal: function (val) {
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
14
lib/utils.js
14
lib/utils.js
|
@ -22,6 +22,10 @@
|
|||
|
||||
var c = require('./const');
|
||||
|
||||
if (process.env.NODE_ENV !== 'build') {
|
||||
var BigNumber = require('bignumber.js'); // jshint ignore:line
|
||||
}
|
||||
|
||||
/// Finds first index of array element matching pattern
|
||||
/// @param array
|
||||
/// @param callback pattern
|
||||
|
@ -132,6 +136,11 @@ var toEth = function (str) {
|
|||
return s + ' ' + units[unit];
|
||||
};
|
||||
|
||||
var toDecimal = function (val) {
|
||||
// remove 0x and place 0, if it's required
|
||||
val = val.length > 2 ? val.substring(2) : "0";
|
||||
return (new BigNumber(val, 16).toString(10));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
|
@ -162,7 +171,7 @@ var fromWei = function(number, unit) {
|
|||
return number;
|
||||
|
||||
if(typeof number === 'string' && number.indexOf('0x') === 0)
|
||||
number = web3.toDecimal(number);
|
||||
number = toDecimal(number);
|
||||
|
||||
if(!(number instanceof BigNumber)) {
|
||||
isBigNumber = false;
|
||||
|
@ -241,7 +250,7 @@ var toWei = function(number, unit) {
|
|||
return number;
|
||||
|
||||
if(typeof number === 'string' && number.indexOf('0x') === 0)
|
||||
number = web3.toDecimal(number);
|
||||
number = toDecimal(number);
|
||||
|
||||
if(!(number instanceof BigNumber)) {
|
||||
isBigNumber = false;
|
||||
|
@ -312,6 +321,7 @@ var isAddress = function(address) {
|
|||
|
||||
module.exports = {
|
||||
findIndex: findIndex,
|
||||
toDecimal: toDecimal,
|
||||
toAscii: toAscii,
|
||||
fromAscii: fromAscii,
|
||||
extractDisplayName: extractDisplayName,
|
||||
|
|
|
@ -152,11 +152,7 @@ var web3 = {
|
|||
fromAscii: utils.fromAscii,
|
||||
|
||||
/// @returns decimal representaton of hex value prefixed by 0x
|
||||
toDecimal: function (val) {
|
||||
// remove 0x and place 0, if it's required
|
||||
val = val.length > 2 ? val.substring(2) : "0";
|
||||
return (new BigNumber(val, 16).toString(10));
|
||||
},
|
||||
toDecimal: utils.toDecimal,
|
||||
|
||||
/// @returns hex representation (prefixed by 0x) of decimal value
|
||||
fromDecimal: function (val) {
|
||||
|
|
Loading…
Reference in New Issue