Allow wei to be passed in as a hex string.

This commit is contained in:
ricmoo 2016-08-04 21:37:33 -04:00
parent 4b99bb579c
commit 4e7f2fa3d4

View File

@ -236,7 +236,12 @@ var zero = new utils.BN(0);
var negative1 = new utils.BN(-1);
var tenPower18 = new utils.BN('1000000000000000000');
utils.defineProperty(Wallet, 'formatEther', function(wei, options) {
if (typeof(wei) === 'number') { wei = new utils.BN(wei); }
if (typeof(wei) === 'number') {
// @TODO: Warn if truncation will occur?
wei = new utils.BN(wei);
} else if (utils.isHexString(wei)) {
wei = new utils.BN(wei.substring(2));
}
if (!options) { options = {}; }
if (!(wei instanceof utils.BN)) { throw new Error('invalid wei'); }