@@ -46,13 +46,28 @@ const INITIAL_STATE = {
4646export class App extends PureComponent {
4747 state = INITIAL_STATE ;
4848
49- clearInvoiceDetails = ( ) => this . setState ( ( ) => ( {
50- ...INITIAL_STATE ,
51- } ) ) ;
49+ componentDidMount ( ) {
50+ const invoiceOnURLParam = window . location . pathname ;
51+
52+ // Remove first `/` from pathname
53+ const cleanInvoice = invoiceOnURLParam . split ( '/' ) [ 1 ] ;
54+ if ( cleanInvoice && cleanInvoice !== '' ) {
55+ this . setState ( ( ) => ( { text : cleanInvoice } ) ) ;
56+ this . getInvoiceDetails ( cleanInvoice ) ;
57+ }
58+ }
5259
53- getInvoiceDetails = async ( text ) => {
54- console . log ( { text } ) ;
60+ clearInvoiceDetails = ( ) => {
61+ // Reset URL address
62+ const currentOrigin = window . location . origin ;
63+ window . history . pushState ( { } , null , `${ currentOrigin } ` ) ;
64+
65+ this . setState ( ( ) => ( {
66+ ...INITIAL_STATE ,
67+ } ) ) ;
68+ } ;
5569
70+ getInvoiceDetails = async ( text ) => {
5671 try {
5772 let response ;
5873 const { isLNURL, data } = await parseInvoice ( text ) ;
@@ -64,6 +79,21 @@ export class App extends PureComponent {
6479 }
6580
6681 if ( response ) {
82+ // On successful response, set the request content on the addressbar
83+ // if there isn't one already in there from before (user-entered)
84+ const currentUrl = window . location ;
85+ const currentOrigin = window . location . origin ;
86+ const currentPathname = window . location . pathname ;
87+ const hasPathnameAlready = currentPathname && currentPathname !== '' ;
88+
89+ // If there's a pathname already, we can just remove it and let the
90+ // new pathname be entered
91+ if ( hasPathnameAlready ) {
92+ window . history . pushState ( { } , null , `${ currentOrigin } ` ) ;
93+ }
94+
95+ window . history . pushState ( { } , null , `${ currentUrl } ${ text } ` ) ;
96+
6797 this . setState ( ( ) => ( {
6898 isLNURL,
6999 error : { } ,
0 commit comments