Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rolznz committed Jan 6, 2024
1 parent 2bac9d3 commit 3820988
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
PopiconsLeftSidebarTopNavDuotone,
PopiconsLogoutDuotone,
} from "@popicons/react";
import { localStorageKeys } from "../constants";

export function Navbar() {
return (
Expand All @@ -29,7 +30,7 @@ export function Navbar() {
<Link
to="/"
onClick={() => {
window.localStorage.removeItem("pos:nwcUrl");
window.localStorage.removeItem(localStorageKeys.nwcUrl);
}}
>
<PopiconsLogoutDuotone className="w-4 h-4" /> Log out
Expand Down
3 changes: 3 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const localStorageKeys = {
nwcUrl: "pos:nwcUrl",
};
3 changes: 2 additions & 1 deletion src/pages/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import {
import React from "react";
import { useNavigate } from "react-router-dom";
import { BuzzPay } from "../components/icons/BuzzPay";
import { localStorageKeys } from "../constants";

export function Home() {
const navigate = useNavigate();
React.useEffect(() => {
const nwcUrl = window.localStorage.getItem("pos:nwcUrl");
const nwcUrl = window.localStorage.getItem(localStorageKeys.nwcUrl);
if (nwcUrl) {
console.log("Restoring wallet URL", nwcUrl);
navigate(`/wallet/${encodeURIComponent(nwcUrl)}/new`);
Expand Down
5 changes: 4 additions & 1 deletion src/pages/Wallet.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { webln } from "@getalby/sdk";
import React from "react";
import { Outlet, useNavigate, useParams } from "react-router-dom";
import { localStorageKeys } from "../constants";

export function Wallet() {
const { nwcUrl } = useParams();
Expand All @@ -21,7 +22,9 @@ export function Wallet() {

await _provider.enable();
setProvider(_provider);
window.localStorage.setItem("pos:nwcUrl", nwcUrl);

// store the wallet URL so PWA can restore it (PWA always loads on the homepage)
window.localStorage.setItem(localStorageKeys.nwcUrl, nwcUrl);
} catch (error) {
console.error(error);
alert("Failed to load wallet: " + error);
Expand Down

0 comments on commit 3820988

Please sign in to comment.