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

Commit 9322725

Browse files
committed
Make subtle dependencies more clear and improve error handling.
1 parent d1c9dfe commit 9322725

File tree

1 file changed

+20
-27
lines changed

1 file changed

+20
-27
lines changed

src/action/payment.js

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ class PaymentAction {
106106
*/
107107
init() {
108108
this._store.payment.address = '';
109+
this._store.payment.destination = '';
109110
this._store.payment.amount = '';
110111
this._store.payment.targetConf = MED_TARGET_CONF;
111112
this._store.payment.fee = '';
@@ -166,7 +167,7 @@ class PaymentAction {
166167
}
167168
if (await this.decodeInvoice({ invoice: this._store.payment.address })) {
168169
if (this._store.payment.amount === '0') {
169-
this._store.payment.amount = null;
170+
this._store.payment.amount = '';
170171
this._nav.goPayLightningSupplyAmount();
171172
} else {
172173
this._nav.goPayLightningConfirm();
@@ -179,14 +180,26 @@ class PaymentAction {
179180
}
180181

181182
/**
182-
* Check If payment amount was supplied and then re-estimate the routing fee
183-
* and go to the confirmation view for lightning payments.
183+
* Check If payment amount was supplied and destination is set. Estimate
184+
* the routing fee and go to the confirmation view for lightning payments.
185+
*
186+
* Note: This function is dependent on that an invoice has already been decoded.
187+
* If payment amount is 0 the function will display a message and return.
184188
*/
185189
async checkAmountSuppliedAndGoPayLightningConfirm() {
186-
if (!this._store.payment.amount) {
187-
return this._notification.display({ msg: 'Enter an invoice or address' });
190+
if (this._store.payment.amount === '0') {
191+
this._notification.display({ msg: 'Enter amount to pay.' });
192+
} else if (
193+
this._store.payment.destination === '' ||
194+
this._store.payment.amount === ''
195+
) {
196+
this._notification.display({ msg: 'Internal Error, try again.' });
197+
this._nav.goHome();
188198
} else {
189-
this.reEstimateLightningFee();
199+
this.estimateLightningFee({
200+
destination: this._store.payment.destination,
201+
satAmt: toSatoshis(this._store.payment.amount, this._store.settings),
202+
});
190203
this._nav.goPayLightningConfirm();
191204
}
192205
}
@@ -206,6 +219,7 @@ class PaymentAction {
206219
});
207220
payment.amount = toAmount(request.numSatoshis, settings);
208221
payment.note = request.description;
222+
payment.destination = request.destination;
209223
this.estimateLightningFee({
210224
destination: request.destination,
211225
satAmt: request.numSatoshis,
@@ -217,27 +231,6 @@ class PaymentAction {
217231
}
218232
}
219233

220-
/**
221-
* Estimate the lightning transaction fee using the queryRoutes grpc api
222-
* after which the fee is set in the store.
223-
* @param {number} options.satAmt The amount to be payed in satoshis
224-
* @return {Promise<undefined>}
225-
*/
226-
async reEstimateLightningFee() {
227-
try {
228-
const request = await this._grpc.sendCommand('decodePayReq', {
229-
payReq: this._store.payment.address,
230-
});
231-
const amount = this._store.payment.amount;
232-
this.estimateLightningFee({
233-
destination: request.destination,
234-
satAmt: toSatoshis(amount, this._store.settings),
235-
});
236-
} catch (err) {
237-
log.info(`Estimating lightning fee failed!`, err);
238-
}
239-
}
240-
241234
/**
242235
* Estimate the lightning transaction fee using the queryRoutes grpc api
243236
* after which the fee is set in the store.

0 commit comments

Comments
 (0)