on master help sign in
Add gotFunding callback to ensureFundsFor

aka "stopAskForFunding", undoing/hiding whatever askForFunding did.

commit201d3ec599787041a23a47f9bca0bf9a9ecf13c7 authorFang <git@fang.io> dateFri 7 Jun 2019, 00:18 (7 years ago) parent231316e
2 files changed+12−5
src/bridge/lib/tank.js+10−3 src/bridge/views/InvitesSend.js+2−2
src/bridge/lib/tank.js+10−3
@@ -42,7 +42,9 @@ const fundTransactions = signedTxs => {
4242// returns true if gas tank was used, false otherwise
4343// askForFunding: callback that takes (address, requiredBalance, currentBalance)
4444// and tells the user to get that address the required balance
45−const ensureFundsFor = async (web3, point, address, cost, signedTxs, askForFunding) => {
45+// gotFunding: optional callback that stops telling the user to go get funding
46+const ensureFundsFor = async (web3, point, address, cost, signedTxs,
47+ askForFunding, gotFunding) => {
4648 let balance = await web3.eth.getBalance(address);
4749
4850 if (cost > balance) {
@@ -74,7 +76,7 @@ const ensureFundsFor = async (web3, point, address, cost, signedTxs, askForFundi
7476 } catch (e) {
7577
7678 console.log('tank: funding failed', e);
77− await waitForBalance(web3, address, cost, askForFunding);
79+ await waitForBalance(web3, address, cost, askForFunding, gotFunding);
7880
7981 }
8082
@@ -87,13 +89,18 @@ const ensureFundsFor = async (web3, point, address, cost, signedTxs, askForFundi
8789// resolves when address has at least minBalance
8890//
8991//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) {
9194 console.log('tank: awaiting balance', address, minBalance);
9295 return new Promise((resolve, reject) => {
9396 let oldBalance = null;
9497 const checkForBalance = async () => {
9598 const balance = await web3.eth.getBalance(address);
9699 if (balance >= minBalance) {
100+ // if we ever asked for funding, retract that request now
101+ if (gotFunding && (oldBalance !== null)) {
102+ gotFunding();
103+ }
97104 resolve();
98105 } else {
99106 if (balance !== oldBalance) {
src/bridge/views/InvitesSend.js+2−2
@@ -192,9 +192,9 @@ class InvitesSend extends React.Component {
192192 const tankWasUsed = await tank.ensureFundsFor(
193193 web3, this.point, this.address,
194194 (INVITE_COST * invites.length),
195− invites.map(i => i.rawTx), this.askForFunding
195+ invites.map(i => i.rawTx), this.askForFunding,
196+ () => { this.setState({ fundingMessage: Nothing() }); }
196197 );
197− this.setState({ fundingMessage: Nothing() }); //TODO see /lib/tank waitForBalance
198198
199199 this.setState({ status: STATUS.SENDING });
200200