Skip to content

Commit

Permalink
chore: package upgrades
Browse files Browse the repository at this point in the history
feature: handling invoice parameters on the fly through web address
  • Loading branch information
andrerfneves committed Jul 22, 2021
1 parent ee1d56c commit e5a68e2
Show file tree
Hide file tree
Showing 4 changed files with 314 additions and 205 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"classnames": "^2.2.6",
"coininfo": "https://github.com/cryptocoinjs/coininfo#dc3e6cc59e593ee7dbeb7c993485706e72d32743",
"date-fns": "^2.1.0",
"history": "^5.0.0",
"lightnode-invoice": "^0.3.0",
"lodash": "^4.17.15",
"node-sass": "^4.12.0",
Expand Down
40 changes: 35 additions & 5 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,28 @@ const INITIAL_STATE = {
export class App extends PureComponent {
state = INITIAL_STATE;

clearInvoiceDetails = () => this.setState(() => ({
...INITIAL_STATE,
}));
componentDidMount() {
const invoiceOnURLParam = window.location.pathname;

// Remove first `/` from pathname
const cleanInvoice = invoiceOnURLParam.split('/')[1];
if (cleanInvoice && cleanInvoice !== '') {
this.setState(() => ({ text: cleanInvoice }));
this.getInvoiceDetails(cleanInvoice);
}
}

getInvoiceDetails = async (text) => {
console.log({ text });
clearInvoiceDetails = () => {
// Reset URL address
const currentOrigin = window.location.origin;
window.history.pushState({}, null, `${currentOrigin}`);

this.setState(() => ({
...INITIAL_STATE,
}));
};

getInvoiceDetails = async (text) => {
try {
let response;
const { isLNURL, data } = await parseInvoice(text);
Expand All @@ -64,6 +79,21 @@ export class App extends PureComponent {
}

if (response) {
// On successful response, set the request content on the addressbar
// if there isn't one already in there from before (user-entered)
const currentUrl = window.location;
const currentOrigin = window.location.origin;
const currentPathname = window.location.pathname;
const hasPathnameAlready = currentPathname && currentPathname !== '';

// If there's a pathname already, we can just remove it and let the
// new pathname be entered
if (hasPathnameAlready) {
window.history.pushState({}, null, `${currentOrigin}`);
}

window.history.pushState({}, null, `${currentUrl}${text}`);

this.setState(() => ({
isLNURL,
error: {},
Expand Down
3 changes: 1 addition & 2 deletions src/constants/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
export const APP_NAME = 'Lightning Decoder';
export const APP_TAGLINE = 'Decode Lightning Network Invoices (BOLT11 & LNURL)';
export const APP_INPUT_PLACEHOLDER = 'Enter Invoice';
export const APP_GITHUB = 'https://github.com/andrerfneves/lightning-decoder';
export const DONATION_BTC = '33sFHnYAnNXBteG8jH8HoGU5YgywN2A3tv';
export const APP_GITHUB = 'https://github.com/andrerfneves/lightning-decoder';
Loading

1 comment on commit e5a68e2

@vercel
Copy link

@vercel vercel bot commented on e5a68e2 Jul 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.