@@ -29,8 +29,11 @@ import {
2929 TIMESTAMP_STRING_KEY ,
3030 CALLBACK_KEY ,
3131 LNURL_TAG_KEY ,
32+ OFFER_PATHS_KEY ,
33+ OFFER_PATH_HOPS_KEY ,
3234} from './constants/keys' ;
3335
36+ import { LNADDRESS , LNURL , BOLT12 } from './constants/invoices' ;
3437// Styles
3538import './assets/styles/main.scss' ;
3639
@@ -76,7 +79,7 @@ export class App extends PureComponent {
7679 hasError : true ,
7780 decodedInvoice : { } ,
7881 isInvoiceLoaded : false ,
79- error : { message : 'Please enter a valid request or address and try again.' } ,
82+ error : { message : 'Please enter a valid request or address and try again.' } ,
8083 } ) ) ;
8184 }
8285
@@ -90,11 +93,11 @@ export class App extends PureComponent {
9093 hasError : true ,
9194 decodedInvoice : { } ,
9295 isInvoiceLoaded : false ,
93- error : { message : 'Please enter a valid request or address and try again.' } ,
96+ error : { message : 'Please enter a valid request or address and try again.' } ,
9497 } ) ) ;
9598 }
9699
97- const { isLNURL, data, error, isLNAddress } = parsedInvoiceResponse ;
100+ const { isLNURL, data, error, isLNAddress, encodingType } = parsedInvoiceResponse ;
98101
99102 // If an error comes back from a nested operation in parsing it must
100103 // propagate back to the end user
@@ -113,7 +116,7 @@ export class App extends PureComponent {
113116 hasError : true ,
114117 decodedInvoice : { } ,
115118 isInvoiceLoaded : false ,
116- error : { message : 'Could not parse/understand this invoice or request. Please try again.' } ,
119+ error : { message : 'Could not parse/understand this invoice or request. Please try again.' } ,
117120 } ) ) ;
118121 }
119122
@@ -151,12 +154,13 @@ export class App extends PureComponent {
151154 isLNURL,
152155 error : { } ,
153156 isLNAddress,
157+ encodingType,
154158 hasError : false ,
155159 isInvoiceLoaded : true ,
156160 decodedInvoice : response ,
157161 } ) ) ;
158162 }
159- } catch ( error ) {
163+ } catch ( error ) {
160164 this . setState ( ( ) => ( {
161165 error : error ,
162166 hasError : true ,
@@ -302,11 +306,11 @@ export class App extends PureComponent {
302306 { (
303307 ! Array . isArray ( tag . data ) && (
304308 ( typeof tag . data !== 'string' ) || ( typeof tag . data !== 'number' ) )
305- ) && (
306- < >
307- { Object . keys ( tag . data ) . map ( ( label ) => renderNestedItem ( label , tag . data [ label ] ) ) }
308- </ >
309- ) }
309+ ) && (
310+ < >
311+ { Object . keys ( tag . data ) . map ( ( label ) => renderNestedItem ( label , tag . data [ label ] ) ) }
312+ </ >
313+ ) }
310314 </ div >
311315 </ div >
312316 ) ;
@@ -364,6 +368,84 @@ export class App extends PureComponent {
364368 </ div >
365369 ) ;
366370
371+ renderOfferDetails = ( ) => {
372+ const { decodedInvoice, isInvoiceLoaded } = this . state ;
373+ const invoiceContainerClassnames = cx (
374+ 'invoice' ,
375+ { 'invoice--opened' : isInvoiceLoaded } ,
376+ ) ;
377+
378+ const renderInnerObject = ( object , innerKey ) => {
379+ return < div key = { innerKey } className = 'invoice__item invoice__item--nested' >
380+ < div className = 'invoice__item-title' >
381+ { formatDetailsKey ( innerKey ) }
382+ </ div >
383+ < div className = 'invoice__item-value' >
384+ { object [ innerKey ] }
385+ </ div >
386+ </ div >
387+ } ;
388+
389+ const renderHops = ( hops ) => {
390+ const child = hops . map ( ( hop , index ) => {
391+ const hop_child = Object . keys ( hop ) . map ( ( key ) => ( renderInnerObject ( hop , key ) ) ) ;
392+
393+ return < div key = { OFFER_PATH_HOPS_KEY + index } >
394+ < div className = 'invoice__item invoice__item-value' >
395+ < p > { formatDetailsKey ( OFFER_PATH_HOPS_KEY ) + ` ${ index } ` } </ p >
396+ </ div >
397+ { hop_child }
398+ </ div >
399+ } ) ;
400+
401+ return < div key = { OFFER_PATH_HOPS_KEY } >
402+ { child }
403+ </ div >
404+ }
405+
406+ const renderPaths = ( paths ) => {
407+ const child = paths . map ( ( path , index ) => {
408+ const path_child = Object . keys ( path ) . map ( ( key ) => {
409+ switch ( key ) {
410+ case OFFER_PATH_HOPS_KEY :
411+ return renderHops ( path [ key ] ) ;
412+ default :
413+ return renderInnerObject ( path , key ) ;
414+ }
415+ } )
416+
417+ return < div key = { path . offer_path_introduction_node } >
418+ < div className = 'invoice__item invoice__item-value' >
419+ < p > { formatDetailsKey ( OFFER_PATHS_KEY ) + ` ${ index } ` } </ p >
420+ </ div >
421+ { path_child }
422+ </ div >
423+ } ) ;
424+
425+ return < div key = { OFFER_PATHS_KEY } >
426+ { child }
427+ </ div >
428+ }
429+
430+ const invoiceDetails = Object . keys ( decodedInvoice )
431+ . map ( ( key ) => {
432+ switch ( key ) {
433+ case OFFER_PATHS_KEY :
434+ return renderPaths ( decodedInvoice [ key ] ) ;
435+
436+ default :
437+ return this . renderInvoiceItem ( key ) ;
438+ }
439+ } ) ;
440+
441+
442+ return ! isInvoiceLoaded ? null : (
443+ < div className = { invoiceContainerClassnames } >
444+ { invoiceDetails }
445+ </ div >
446+ ) ;
447+ }
448+
367449 renderLNURLDetails = ( ) => {
368450 const { decodedInvoice, isInvoiceLoaded } = this . state ;
369451 const invoiceContainerClassnames = cx (
@@ -377,11 +459,11 @@ export class App extends PureComponent {
377459 < div className = { invoiceContainerClassnames } >
378460 { Object . keys ( requestContents ) . map ( ( key ) => {
379461 let text = decodedInvoice [ key ] ;
380-
462+
381463 if ( typeof decodedInvoice [ key ] === 'object' ) {
382464 return < > </ > ;
383465 }
384-
466+
385467 if ( key === 'status' ) {
386468 return < > </ >
387469 }
@@ -554,7 +636,7 @@ export class App extends PureComponent {
554636 const { isQRCodeOpened, isInvoiceLoaded } = this . state ;
555637
556638 const styleQRWrapper = cx ( {
557- 'qrcode' : true ,
639+ 'qrcode' : true ,
558640 'qrcode--opened' : isQRCodeOpened ,
559641 } ) ;
560642 const styleQRContainer = cx (
@@ -621,7 +703,7 @@ export class App extends PureComponent {
621703 }
622704
623705 render ( ) {
624- const { isLNURL , isInvoiceLoaded , hasError } = this . state ;
706+ const { isInvoiceLoaded , encodingType , hasError } = this . state ;
625707
626708 const appClasses = cx (
627709 'app' ,
@@ -651,7 +733,10 @@ export class App extends PureComponent {
651733 </ div >
652734 </ div >
653735 < div className = { appColumnClasses } >
654- { isLNURL ? this . renderLNURLDetails ( ) : this . renderInvoiceDetails ( ) }
736+ { ( ( encodingType === LNADDRESS || encodingType === LNURL ) && this . renderLNURLDetails ( ) ) ||
737+ ( encodingType === BOLT12 && this . renderOfferDetails ( ) )
738+ || this . renderInvoiceDetails ( )
739+ }
655740 { this . renderErrorDetails ( ) }
656741 </ div >
657742 </ div >
0 commit comments