This repository was archived by the owner on Feb 23, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +10
-15
lines changed Expand file tree Collapse file tree 2 files changed +10
-15
lines changed Original file line number Diff line number Diff line change @@ -170,34 +170,28 @@ class PaymentAction {
170170 * @return {Promise<undefined> }
171171 */
172172 async payLightning ( ) {
173+ const to = setTimeout ( ( ) => this . _nav . goPaymentFailed ( ) , PAYMENT_TIMEOUT ) ;
173174 try {
174175 this . _nav . goWait ( ) ;
175176 const invoice = this . _store . payment . address . replace ( PREFIX_URI , '' ) ;
176177 const stream = this . _grpc . sendStreamCommand ( 'sendPayment' ) ;
177- const success = await new Promise ( ( resolve , reject ) => {
178- const timeout = setTimeout ( ( ) => resolve ( false ) , PAYMENT_TIMEOUT ) ;
178+ await new Promise ( ( resolve , reject ) => {
179179 stream . on ( 'data' , data => {
180180 if ( data . payment_error ) {
181- clearTimeout ( timeout ) ;
182181 reject ( new Error ( `Lightning payment error: ${ data . payment_error } ` ) ) ;
183182 } else {
184- clearTimeout ( timeout ) ;
185- resolve ( true ) ;
183+ resolve ( ) ;
186184 }
187185 } ) ;
188- stream . on ( 'error' , ( ) => {
189- clearTimeout ( timeout ) ;
190- reject ( ) ;
191- } ) ;
186+ stream . on ( 'error' , reject ) ;
192187 stream . write ( JSON . stringify ( { payment_request : invoice } ) , 'utf8' ) ;
193188 } ) ;
194- if ( ! success ) {
195- this . _nav . goPaymentFailed ( ) ;
196- }
197189 this . _nav . goPayLightningDone ( ) ;
198190 } catch ( err ) {
199191 this . _nav . goPayLightningConfirm ( ) ;
200192 this . _notification . display ( { msg : 'Lightning payment failed!' , err } ) ;
193+ } finally {
194+ clearTimeout ( to ) ;
201195 }
202196 }
203197}
Original file line number Diff line number Diff line change @@ -22,7 +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 ;
25+ require ( '../../../src/config' ) . PAYMENT_TIMEOUT = 10 ;
2626 grpc = sinon . createStubInstance ( GrpcAction ) ;
2727 notification = sinon . createStubInstance ( NotificationAction ) ;
2828 nav = sinon . createStubInstance ( NavAction ) ;
@@ -243,9 +243,10 @@ describe('Action Payments Unit Tests', () => {
243243 } ) ;
244244
245245 it ( 'should go to error page on timeout' , async ( ) => {
246- await payment . payLightning ( { invoice : 'some-invoice' } ) ;
246+ payment . payLightning ( { invoice : 'some-invoice' } ) ;
247+ await nap ( 100 ) ;
247248 expect ( nav . goPaymentFailed , 'was called once' ) ;
248- expect ( nav . goPayLightningConfirm , 'was not called' ) ;
249+ expect ( nav . goPayLightningDone , 'was not called' ) ;
249250 } ) ;
250251 } ) ;
251252} ) ;
You can’t perform that action at this time.
0 commit comments