on master help sign in
Treat gas price during reticket as BN
a6f399fFang
src/lib/reticket.js+9−8
@@ -143,14 +143,15 @@ export async function reticketPointBetweenWallets({
143 progress(TRANSACTION_PROGRESS.SIGNING);
143 progress(TRANSACTION_PROGRESS.SIGNING);
144
144
145 const suggestedGasPrice = await getSuggestedGasPrice(networkType);
145 const suggestedGasPrice = await getSuggestedGasPrice(networkType);
146− const gasPrice = parseInt(toWei(suggestedGasPrice.toFixed(), 'gwei'), 10);
146+ const gasPrice = toWei(suggestedGasPrice.toFixed(), 'gwei');
147+ const gasPriceBN = toBN(gasPrice);
147 let totalCost = toBN(0);
148 let totalCost = toBN(0);
148 let inviteNonce = await web3.eth.getTransactionCount(fromWallet.address);
149 let inviteNonce = await web3.eth.getTransactionCount(fromWallet.address);
149 txs = txs.map(tx => {
150 txs = txs.map(tx => {
150 tx.from = fromWallet.address;
151 tx.from = fromWallet.address;
151 tx.nonce = inviteNonce++;
152 tx.nonce = inviteNonce++;
152− tx.gasPrice = gasPrice;
153+ tx.gasPrice = gasPriceBN;
153− totalCost = totalCost.add(toBN(gasPrice).mul(toBN(tx.gas)));
154+ totalCost = totalCost.add(gasPriceBN.mul(toBN(tx.gas)));
154 return tx;
155 return tx;
155 });
156 });
156
157
@@ -194,15 +195,15 @@ export async function reticketPointBetweenWallets({
194 progress(TRANSACTION_PROGRESS.CLEANING);
195 progress(TRANSACTION_PROGRESS.CLEANING);
195
196
196 // if non-trivial eth left in invite wallet, transfer to new ownership
197 // if non-trivial eth left in invite wallet, transfer to new ownership
197− let balance = await web3.eth.getBalance(fromWallet.address);
198+ let balance = toBN(await web3.eth.getBalance(fromWallet.address));
198 const gasLimit = GAS_LIMITS.SEND_ETH;
199 const gasLimit = GAS_LIMITS.SEND_ETH;
199− const sendEthCost = gasPrice * gasLimit;
200+ const sendEthCost = gasPriceBN.mul(toBN(gasLimit));
200− if (transferEth && balance > sendEthCost) {
201+ if (transferEth && balance.gt(sendEthCost)) {
201− const value = balance - sendEthCost;
202+ const value = balance.sub(sendEthCost);
202 const tx = {
203 const tx = {
203 to: toWallet.ownership.keys.address,
204 to: toWallet.ownership.keys.address,
204 value: value,
205 value: value,
205− gasPrice: gasPrice,
206+ gasPrice: gasPriceBN,
206 gas: gasLimit,
207 gas: gasLimit,
207 nonce: inviteNonce++,
208 nonce: inviteNonce++,
208 };
209 };