@@ -38,6 +38,10 @@ const fundTransactions = signedTxs => {
3838 return sendRequest('/request', {txs:signedTxs});
3939};
4040
41+// resolves when address has at least cost balance
42+// returns true if gas tank was used, false otherwise
43+// askForFunding: callback that takes (address, requiredBalance, currentBalance)
44+// and tells the user to get that address the required balance
4145const ensureFundsFor = async (web3, point, address, cost, signedTxs, askForFunding) => {
4246 let balance = await web3.eth.getBalance(address);
4347
@@ -45,9 +49,16 @@ const ensureFundsFor = async (web3, point, address, cost, signedTxs, askForFundi
4549
4650 try {
4751
48− const fundsRemaining = await remainingTransactions(point);
49− if (fundsRemaining < signedTxs.length) {
50− throw new Error('tank: request invalid');
52+ if (point !== null) {
53+ const fundsRemaining = await remainingTransactions(point);
54+ if (fundsRemaining < signedTxs.length) {
55+ throw new Error('tank: request invalid');
56+ }
57+ } else {
58+ console.log('tank: skipping remaining-funds check');
59+ //TODO if we can't always (easily) provide a point, and the
60+ // fundTransactions call is gonna fail anyway, should we maybe
61+ // just not bother doing this check in the first place?
5162 }
5263
5364 const res = await fundTransactions(signedTxs);
@@ -57,6 +68,7 @@ const ensureFundsFor = async (web3, point, address, cost, signedTxs, askForFundi
5768 await waitForTransactionConfirm(web3, res.txHash);
5869 let newBalance = await web3.eth.getBalance(address);
5970 console.log('tank: funds have confirmed', balance >= cost, balance, newBalance);
71+ return true;
6072 }
6173
6274 } catch (e) {
@@ -69,12 +81,12 @@ const ensureFundsFor = async (web3, point, address, cost, signedTxs, askForFundi
6981 } else {
7082 console.log('tank: already have sufficient funds');
7183 }
84+ return false;
7285};
7386
7487// resolves when address has at least minBalance
7588//
76−// askForFunding: callback that takes (address, requiredBalance, currentBalance)
77−// and tells the user to get that address the required balance
89+//TODO should maybe do a "we got it" callback also, so clients can hide msg?
7890async function waitForBalance(web3, address, minBalance, askForFunding) {
7991 console.log('tank: awaiting balance', address, minBalance);
8092 return new Promise((resolve, reject) => {