on master help sign in
Move batch logic into /lib/txn
bc552c8Fang
src/lib/invite.js+2−12
@@ -9,7 +9,7 @@ import * as tank from './tank';
9import JSZip from 'jszip';
9import JSZip from 'jszip';
10import saveAs from 'file-saver';
10import saveAs from 'file-saver';
11
11
12−import { sendSignedTransaction, hexify } from './txn';
12+import { sendAndAwaitAll, hexify } from './txn';
13import { attemptNetworkSeedDerivation } from './keys';
13import { attemptNetworkSeedDerivation } from './keys';
14import { addHexPrefix, WALLET_TYPES } from './wallet';
14import { addHexPrefix, WALLET_TYPES } from './wallet';
15import { GAS_LIMITS } from './constants';
15import { GAS_LIMITS } from './constants';
@@ -258,7 +258,7 @@ async function claimPointFromInvite({
258
258
259 progress(TRANSACTION_STATES.CLAIMING);
259 progress(TRANSACTION_STATES.CLAIMING);
260
260
261− await sendAndAwaitConfirm(web3, txPairs.map(p => Just(p.signed)), usedTank);
261+ await sendAndAwaitAll(web3, txPairs.map(p => Just(p.signed)), usedTank);
262
262
263 //
263 //
264 // move leftover eth
264 // move leftover eth
@@ -291,16 +291,6 @@ async function claimPointFromInvite({
291 progress(TRANSACTION_STATES.DONE);
291 progress(TRANSACTION_STATES.DONE);
292}
292}
293
293
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−
304export {
294export {
305 generateWallet,
295 generateWallet,
306 downloadWallet,
296 downloadWallet,
src/lib/txn.js+11−5
@@ -191,10 +191,16 @@ const waitForTransactionConfirm = (web3, txHash) => {
191 });
191 });
192};
192};
193
193
194−const isTransactionConfirmed = async (web3, txHash) => {
194+const sendAndAwaitAll = async (web3, stxs, doubtNonceError) => {
195− const receipt = await web3.eth.getTransactionReceipt(txHash);
195+ await Promise.all(
196− console.log('got confirm state', receipt !== null, receipt.confirmations);
196+ stxs.map(tx => {
197− return receipt !== null;
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+ );
198};
204};
199
205
200const hexify = val => addHexPrefix(val.toString('hex'));
206const hexify = val => addHexPrefix(val.toString('hex'));
@@ -231,7 +237,7 @@ export {
231 signTransaction,
237 signTransaction,
232 sendSignedTransaction,
238 sendSignedTransaction,
233 waitForTransactionConfirm,
239 waitForTransactionConfirm,
234− isTransactionConfirmed,
240+ sendAndAwaitAll,
235 TXN_PURPOSE,
241 TXN_PURPOSE,
236 getTxnInfo,
242 getTxnInfo,
237 renderTxnPurpose,
243 renderTxnPurpose,