From 382098875b82ff0bfc97b1f64fba0441c758a246 Mon Sep 17 00:00:00 2001 From: Roland Bewick Date: Sat, 6 Jan 2024 18:16:06 +0700 Subject: [PATCH] chore: cleanup --- src/components/Navbar.tsx | 3 ++- src/constants.ts | 3 +++ src/pages/Home.tsx | 3 ++- src/pages/Wallet.tsx | 5 ++++- 4 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 src/constants.ts diff --git a/src/components/Navbar.tsx b/src/components/Navbar.tsx index 2724b8b..950cd84 100644 --- a/src/components/Navbar.tsx +++ b/src/components/Navbar.tsx @@ -6,6 +6,7 @@ import { PopiconsLeftSidebarTopNavDuotone, PopiconsLogoutDuotone, } from "@popicons/react"; +import { localStorageKeys } from "../constants"; export function Navbar() { return ( @@ -29,7 +30,7 @@ export function Navbar() { { - window.localStorage.removeItem("pos:nwcUrl"); + window.localStorage.removeItem(localStorageKeys.nwcUrl); }} > Log out diff --git a/src/constants.ts b/src/constants.ts new file mode 100644 index 0000000..bf7077a --- /dev/null +++ b/src/constants.ts @@ -0,0 +1,3 @@ +export const localStorageKeys = { + nwcUrl: "pos:nwcUrl", +}; diff --git a/src/pages/Home.tsx b/src/pages/Home.tsx index d8fc797..41efcb2 100644 --- a/src/pages/Home.tsx +++ b/src/pages/Home.tsx @@ -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`); diff --git a/src/pages/Wallet.tsx b/src/pages/Wallet.tsx index bef4475..afff0f4 100644 --- a/src/pages/Wallet.tsx +++ b/src/pages/Wallet.tsx @@ -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(); @@ -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);