This repository was archived by the owner on Feb 23, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +21
-4
lines changed Expand file tree Collapse file tree 3 files changed +21
-4
lines changed Original file line number Diff line number Diff line change 33 * call the corresponding GRPC apis for payment management.
44 */
55
6- import { PREFIX_URI } from '../config' ;
6+ import { PREFIX_URI , PAYMENT_TIMEOUT } from '../config' ;
77import {
88 toSatoshis ,
99 toAmount ,
@@ -174,17 +174,26 @@ class PaymentAction {
174174 this . _nav . goWait ( ) ;
175175 const invoice = this . _store . payment . address . replace ( PREFIX_URI , '' ) ;
176176 const stream = this . _grpc . sendStreamCommand ( 'sendPayment' ) ;
177- await new Promise ( ( resolve , reject ) => {
177+ const success = await new Promise ( ( resolve , reject ) => {
178+ const timeout = setTimeout ( ( ) => resolve ( false ) , PAYMENT_TIMEOUT ) ;
178179 stream . on ( 'data' , data => {
179180 if ( data . payment_error ) {
181+ clearTimeout ( timeout ) ;
180182 reject ( new Error ( `Lightning payment error: ${ data . payment_error } ` ) ) ;
181183 } else {
182- resolve ( ) ;
184+ clearTimeout ( timeout ) ;
185+ resolve ( true ) ;
183186 }
184187 } ) ;
185- stream . on ( 'error' , reject ) ;
188+ stream . on ( 'error' , ( ) => {
189+ clearTimeout ( timeout ) ;
190+ reject ( ) ;
191+ } ) ;
186192 stream . write ( JSON . stringify ( { payment_request : invoice } ) , 'utf8' ) ;
187193 } ) ;
194+ if ( ! success ) {
195+ this . _nav . goPaymentFailed ( ) ;
196+ }
188197 this . _nav . goPayLightningDone ( ) ;
189198 } catch ( err ) {
190199 this . _nav . goPayLightningConfirm ( ) ;
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ module.exports.RETRY_DELAY = 1000;
66module . exports . LND_INIT_DELAY = 5000 ;
77module . exports . NOTIFICATION_DELAY = 5000 ;
88module . exports . RATE_DELAY = 15 * 60 * 1000 ;
9+ module . exports . PAYMENT_TIMEOUT = 60 * 1000 ;
910
1011module . exports . LND_PORT = 10006 ;
1112module . exports . LND_PEER_PORT = 10016 ;
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ describe('Action Payments Unit Tests', () => {
2222 store = new Store ( ) ;
2323 store . settings . displayFiat = false ;
2424 require ( '../../../src/config' ) . RETRY_DELAY = 1 ;
25+ require ( '../../../src/config' ) . PAYMENT_TIMEOUT = 500 ;
2526 grpc = sinon . createStubInstance ( GrpcAction ) ;
2627 notification = sinon . createStubInstance ( NotificationAction ) ;
2728 nav = sinon . createStubInstance ( NavAction ) ;
@@ -240,5 +241,11 @@ describe('Action Payments Unit Tests', () => {
240241 expect ( nav . goPayLightningConfirm , 'was called once' ) ;
241242 expect ( notification . display , 'was called once' ) ;
242243 } ) ;
244+
245+ it ( 'should go to error page on timeout' , async ( ) => {
246+ await payment . payLightning ( { invoice : 'some-invoice' } ) ;
247+ expect ( nav . goPaymentFailed , 'was called once' ) ;
248+ expect ( nav . goPayLightningConfirm , 'was not called' ) ;
249+ } ) ;
243250 } ) ;
244251} ) ;
You can’t perform that action at this time.
0 commit comments