Skip to content

Commit

Permalink
Fixed bug when passing in hex string to formatEther.
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Aug 5, 2016
1 parent 7a37dd6 commit 0e9df5c
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,14 @@ 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') {
// @TODO: Warn if truncation will occur?
wei = new utils.BN(wei);
} else if (utils.isHexString(wei)) {
wei = new utils.BN(wei.substring(2));
wei = new utils.BN(wei.substring(2), 16);
}

if (!options) { options = {}; }

if (!(wei instanceof utils.BN)) { throw new Error('invalid wei'); }
Expand Down

0 comments on commit 0e9df5c

Please sign in to comment.