on master help sign in
Move batch logic into /lib/txn
commitbc552c8934c4820738e61c84f760b2943ab06937 authorFang <git@fang.io> dateTue 16 Jul 2019, 01:34 (7 years ago) parent82287c8
2 files changed+13−17
src/lib/invite.js+2−12 src/lib/txn.js+11−5
src/lib/invite.js+2−12
@@ -9,7 +9,7 @@ import * as tank from './tank';
99import JSZip from 'jszip';
1010import saveAs from 'file-saver';
1111
12−import { sendSignedTransaction, hexify } from './txn';
12+import { sendAndAwaitAll, hexify } from './txn';
1313import { attemptNetworkSeedDerivation } from './keys';
1414import { addHexPrefix, WALLET_TYPES } from './wallet';
1515import { GAS_LIMITS } from './constants';
@@ -258,7 +258,7 @@ async function claimPointFromInvite({
258258
259259 progress(TRANSACTION_STATES.CLAIMING);
260260
261− await sendAndAwaitConfirm(web3, txPairs.map(p => Just(p.signed)), usedTank);
261+ await sendAndAwaitAll(web3, txPairs.map(p => Just(p.signed)), usedTank);
262262
263263 //
264264 // move leftover eth
@@ -291,16 +291,6 @@ async function claimPointFromInvite({
291291 progress(TRANSACTION_STATES.DONE);
292292}
293293
294−async function sendAndAwaitConfirm(web3, signedTxs, usedTank) {
295− await Promise.all(
296− signedTxs.map(tx => {
297− return new Promise((resolve, reject) => {
298− sendSignedTransaction(web3, tx, usedTank, resolve);
299− });
300− })
301− );
302−}
303−
304294export {
305295 generateWallet,
306296 downloadWallet,
src/lib/txn.js+11−5
@@ -191,10 +191,16 @@ const waitForTransactionConfirm = (web3, txHash) => {
191191 });
192192};
193193
194−const isTransactionConfirmed = async (web3, txHash) => {
195− const receipt = await web3.eth.getTransactionReceipt(txHash);
196− console.log('got confirm state', receipt !== null, receipt.confirmations);
197− return receipt !== null;
194+const sendAndAwaitAll = async (web3, stxs, doubtNonceError) => {
195+ await Promise.all(
196+ stxs.map(tx => {
197+ return new Promise(async (resolve, reject) => {
198+ const txHash = await sendSignedTransaction(web3, tx, doubtNonceError);
199+ await waitForTransactionConfirm(web3, txHash);
200+ resolve();
201+ });
202+ })
203+ );
198204};
199205
200206const hexify = val => addHexPrefix(val.toString('hex'));
@@ -231,7 +237,7 @@ export {
231237 signTransaction,
232238 sendSignedTransaction,
233239 waitForTransactionConfirm,
234− isTransactionConfirmed,
240+ sendAndAwaitAll,
235241 TXN_PURPOSE,
236242 getTxnInfo,
237243 renderTxnPurpose,