@@ -42,7 +42,9 @@ const fundTransactions = signedTxs => {
42// returns true if gas tank was used, false otherwise
42// returns true if gas tank was used, false otherwise
43// askForFunding: callback that takes (address, requiredBalance, currentBalance)
43// askForFunding: callback that takes (address, requiredBalance, currentBalance)
44// and tells the user to get that address the required balance
44// and tells the user to get that address the required balance
45+// gotFunding: optional callback that stops telling the user to go get funding
45−const ensureFundsFor = async (web3, point, address, cost, signedTxs, askForFunding) => {
46+const ensureFundsFor = async (web3, point, address, cost, signedTxs,
47+ askForFunding, gotFunding) => {
46 let balance = await web3.eth.getBalance(address);
48 let balance = await web3.eth.getBalance(address);
48 if (cost > balance) {
50 if (cost > balance) {
@@ -74,7 +76,7 @@ const ensureFundsFor = async (web3, point, address, cost, signedTxs, askForFundi
74 } catch (e) {
76 } catch (e) {
76 console.log('tank: funding failed', e);
78 console.log('tank: funding failed', e);
77− await waitForBalance(web3, address, cost, askForFunding);
79+ await waitForBalance(web3, address, cost, askForFunding, gotFunding);
@@ -87,13 +89,18 @@ const ensureFundsFor = async (web3, point, address, cost, signedTxs, askForFundi
87// resolves when address has at least minBalance
89// resolves when address has at least minBalance
89//TODO should maybe do a "we got it" callback also, so clients can hide msg?
91//TODO should maybe do a "we got it" callback also, so clients can hide msg?
90−async function waitForBalance(web3, address, minBalance, askForFunding) {
92+async function waitForBalance(web3, address, minBalance,
93+ askForFunding, gotFunding) {
91 console.log('tank: awaiting balance', address, minBalance);
94 console.log('tank: awaiting balance', address, minBalance);
92 return new Promise((resolve, reject) => {
95 return new Promise((resolve, reject) => {
93 let oldBalance = null;
96 let oldBalance = null;
94 const checkForBalance = async () => {
97 const checkForBalance = async () => {
95 const balance = await web3.eth.getBalance(address);
98 const balance = await web3.eth.getBalance(address);
96 if (balance >= minBalance) {
99 if (balance >= minBalance) {
100+ // if we ever asked for funding, retract that request now
101+ if (gotFunding && (oldBalance !== null)) {
97 resolve();
104 resolve();
99 if (balance !== oldBalance) {
106 if (balance !== oldBalance) {