on master help sign in
Always wrap fromWei's first argument in a toBN

See also #302. Should fix all of #306, #310, #316, #318, #319, or at least expose an underlying issue.

commitb44ecedbc92021bcdc3652293c010ea1f9cd39c1 authorFang <git@fang.io> dateTue 29 Oct 2019, 12:48 (7 years ago) parent722f6c2
2 files changed+5−5
src/lib/error.js+3−3 src/lib/txn.js+2−2
src/lib/error.js+3−3
@@ -1,4 +1,4 @@
1−import { fromWei } from 'web3-utils';
1+import { fromWei, toBN } from 'web3-utils';
22
33const BRIDGE_ERROR = {
44 MISSING_WEB3: 'no web3 object found',
@@ -18,13 +18,13 @@ const BRIDGE_ERROR = {
1818const renderTxnError = (web3, msg) => {
1919 const txnCost = (web3, msg) => {
2020 const costWei = msg.match(/upfront cost is: ([0-9]+)/);
21− const costEth = fromWei(costWei[1], 'ether');
21+ const costEth = fromWei(toBN(costWei[1]), 'ether');
2222 return parseFloat(costEth).toFixed(4);
2323 };
2424
2525 const acctBalance = (web3, msg) => {
2626 const balWei = msg.match(/sender's account only has: ([0-9]+)/);
27− const balEth = fromWei(balWei[1], 'ether');
27+ const balEth = fromWei(toBN(balWei[1]), 'ether');
2828 return parseFloat(balEth).toFixed(4);
2929 };
3030
src/lib/txn.js+2−2
@@ -1,5 +1,5 @@
11import Tx from 'ethereumjs-tx';
2−import { toWei, fromWei, toHex } from 'web3-utils';
2+import { toWei, fromWei, toHex, toBN } from 'web3-utils';
33import retry from 'async-retry';
44
55import { NETWORK_TYPES } from './network';
@@ -193,7 +193,7 @@ const getTxnInfo = async (web3, addr) => {
193193 return {
194194 nonce: nonce,
195195 chainId: chainId,
196− gasPrice: fromWei(gasPrice, 'gwei'),
196+ gasPrice: fromWei(toBN(gasPrice), 'gwei'),
197197 };
198198};
199199