@@ -9,10 +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'
12−import {
12+import { sendSignedTransaction } from './txn'
13− waitForTransactionConfirm,
14− isTransactionConfirmed
16import { BRIDGE_ERROR } from '../lib/error'
13import { BRIDGE_ERROR } from '../lib/error'
17import { attemptSeedDerivation } from './keys'
14import { attemptSeedDerivation } from './keys'
18import { addHexPrefix, WALLET_NAMES } from './wallet'
15import { addHexPrefix, WALLET_NAMES } from './wallet'
@@ -168,7 +165,9 @@ async function startTransactions(args) {
168 type: "progress",
165 type: "progress",
169 value: TRANSACTION_STATES.FUNDING_INVITE
166 value: TRANSACTION_STATES.FUNDING_INVITE
168+ let usedTank = await tank.ensureFundsFor(
171− await tank.ensureFundsFor(web3, point, inviteAddress, transferCost, [rawTransferStx], askForFunding);
169+ web3, point, inviteAddress, transferCost, [rawTransferStx], askForFunding
173 updateProgress({
172 updateProgress({
174 type: "progress",
173 type: "progress",
@@ -176,7 +175,7 @@ async function startTransactions(args) {
178 // send transaction
177 // send transaction
179− await sendAndAwaitConfirm(web3, [rawTransferStx]);
178+ await sendAndAwaitConfirm(web3, [rawTransferStx], usedTank);
182 // we're gonna be operating as the new wallet from here on out, so change
181 // we're gonna be operating as the new wallet from here on out, so change
@@ -236,14 +235,16 @@ async function startTransactions(args) {
236 type: "progress",
235 type: "progress",
237 value: TRANSACTION_STATES.FUNDING_RECIPIENT
236 value: TRANSACTION_STATES.FUNDING_RECIPIENT
238+ usedTank = await tank.ensureFundsFor(
239− await tank.ensureFundsFor(web3, point, newAddress, totalCost, rawStxs, askForFunding);
239+ web3, point, newAddress, totalCost, rawStxs, askForFunding
241 updateProgress({
242 updateProgress({
242 type: "progress",
243 type: "progress",
243 value: TRANSACTION_STATES.CONFIGURING
244 value: TRANSACTION_STATES.CONFIGURING
246− await sendAndAwaitConfirm(web3, rawStxs);
247+ await sendAndAwaitConfirm(web3, rawStxs, usedTank);
248 updateProgress({
249 updateProgress({
249 type: "progress",
250 type: "progress",
@@ -283,34 +284,10 @@ async function startTransactions(args) {
283 setUrbitWallet(Just(realWallet));
284 setUrbitWallet(Just(realWallet));
286−//TODO replace with txn.sendSignedTransaction? it can doubt nonce errors too
287−async function sendAndAwaitConfirm(web3, signedTxs) {
287+async function sendAndAwaitConfirm(web3, signedTxs, usedTank) {
288 await Promise.all(signedTxs.map(tx => {
288 await Promise.all(signedTxs.map(tx => {
289− console.log('sending...');
290 return new Promise((resolve, reject) => {
289 return new Promise((resolve, reject) => {
291− web3.eth.sendSignedTransaction(tx).then(res => {
290+ sendSignedTransaction(web3, tx, usedTank, resolve);
292− console.log('sent, now waiting for confirm!', res.transactionHash);
293− waitForTransactionConfirm(web3, res.transactionHash)
295− }).catch(async err => {
296− // if there's an error, check if it's because the transaction was
297− // already confirmed prior to sending.
298− // this is really only the case in local dev environments.
299− const txHash = web3.utils.keccak256(tx);
300− console.log(err.message);
301− if (err.message.includes("the tx doesn't have the correct nonce.")) {
302− console.log('nonce error, awaiting confirm', err.message.slice(55));
303− //TODO max wait time before assume failure?
304− let res = await waitForTransactionConfirm(web3, txHash);
306− else reject(new Error('Unexpected tx failure'));
308− const confirmed = await isTransactionConfirmed(web3, txHash);
309− console.log('error, but maybe confirmed:', confirmed);
310− if (confirmed) resolve();