Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.

Conversation

@valentinewallace
Copy link
Contributor

Closes #431

@valentinewallace valentinewallace requested a review from tanx July 11, 2018 02:41
await this._transaction.update();
}

async getFeeEstimate(destination, satAmt) {
Copy link
Contributor

@tanx tanx Jul 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably rename this to estimateLightningFee as we will also have an o-chain estimateFee:
https://github.com/lightninglabs/lightning-app/pull/318/files

Also, all actions use paramter destructuring e.g. ({ param }) for all function. This makes it easier to read the code consuming the api and also has some other benefits. See:
http://2ality.com/2015/01/es6-destructuring.html#simulating-named-parameters-in-javascript

expect(isValid, 'to be', true);
expect(store.payment.amount, 'to match', /^0[,.]0{4}1{1}7{1}$/);
expect(store.payment.note, 'to be', 'foo');
expect(store.payment.fee, 'to match', /^0[,.]0{5}1{1}$/);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to the unit test, we should also add integration test.

@valentinewallace valentinewallace force-pushed the show-tx-fee branch 4 times, most recently from 1813542 to 4bc7125 Compare July 13, 2018 03:14
payment.amount = toAmount(parseSat(request.num_satoshis), settings.unit);
payment.note = request.description;
payment.fee = toAmount(parseSat(fee), settings.unit);
return true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would freeze the UI if queryRoutes takes a few seconds. Have you tested this with Yalls and Starblocks?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya that's a good point, I did test with Yalls and Starblocks and it was fine but I'm adding a wait screen if queryRoutes takes more than 500ms.

const isValid = await payments1.decodeInvoice({
invoice: store2.invoice.uri,
});
expect(parseInt(store1.payment.fee), 'to be greater than or equal to', 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heads up payment.fee is a string formatted float that is in the selected unit (BTC in this case). You'll wanna call parseFloat(store1.payment.fee) in this case.

@valentinewallace valentinewallace force-pushed the show-tx-fee branch 2 times, most recently from 92d6c34 to 72d8462 Compare July 17, 2018 22:40

async decodeInvoice({ invoice }) {
try {
const timer = setTimeout(() => this._nav.goWait(), WAIT_DELAY);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The user shouldn't need to wait to decode an invoice...

});
payment.amount = toAmount(parseSat(request.num_satoshis), settings.unit);
payment.note = request.description;
payment.fee = toAmount(parseSat(fee), settings.unit);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function just decodes the invoice and returns a boolean.

I'd set store.payment.fee in estimateLightningFee itself and call it after this._nav.goPayLightningConfirm() here https://github.com/lightninglabs/lightning-app/pull/448/files#diff-c103796afd01e866f6af483b8930cf32R57.

});
return routes[0].total_fees;
} catch (err) {
log.info(`Unable to retrieve fee estimate: ${JSON.stringify(err)}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

err.message should be enough here.

Copy link
Contributor

@tanx tanx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I refactored the code a bit. Turns out the queryRoute request is just as fast as decoding the invoice so we don't need to display the wait screen for now. Also added some missing unit tests ;)

Please take a look. Ready to merge from my side.

@tanx
Copy link
Contributor

tanx commented Jul 24, 2018

@valentinewallace also a heads up... I rebased this onto the current master.

@valentinewallace
Copy link
Contributor Author

valentinewallace commented Jul 24, 2018

@tanx Lol omg I was almost ready to submit my (similar) updates on this one xD might have missed something, otherwise is there a way to avoid in the future?

Looks good to me though 👌 Thanks for adding the tests I missed :) I ran it in the packaged app and it worked great. Merging

@valentinewallace valentinewallace merged commit 762a801 into master Jul 24, 2018
@valentinewallace valentinewallace deleted the show-tx-fee branch July 24, 2018 23:14
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants