Skip to content

Commit

Permalink
feat(deploy-web): add localstorage export page
Browse files Browse the repository at this point in the history
  • Loading branch information
Redm4x committed May 14, 2024
1 parent 5863ac8 commit cfffc7f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
7 changes: 6 additions & 1 deletion deploy-web/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Router.events.on("routeChangeError", () => NProgress.done());
// Client-side cache, shared for the whole session of the user in the browser.
const clientSideEmotionCache = createEmotionCache();

const App: React.FunctionComponent<Props> = ({ Component, pageProps, emotionCache = clientSideEmotionCache }) => {
const App: React.FunctionComponent<Props> = ({ Component, pageProps, emotionCache = clientSideEmotionCache, router }) => {
usePreviousRoute();

useEffect(() => {
Expand All @@ -63,6 +63,11 @@ const App: React.FunctionComponent<Props> = ({ Component, pageProps, emotionCach
};
}, []);

// Do not wrap with layout if standalone page
if (router.pathname.startsWith("/standalone/")) {
return <Component {...pageProps} />;
}

return (
<>
<PageHead />
Expand Down
30 changes: 30 additions & 0 deletions deploy-web/src/pages/standalone/localstorage-export.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"use client";

import { extractLocalStorageData } from "@src/utils/localStorage";
import { useEffect } from "react";

const validExternalDomain = "https://console.akash.network";

export default function Page() {
useEffect(() => {
exportLocalStorageData();
}, []);

function exportLocalStorageData() {
if (window.parent === window) {
console.log(`${window.location.origin} => No parent window found`);
return;
}

const data = extractLocalStorageData();

console.log(`${window.location.origin} => Sending localstorage data to ${validExternalDomain}`);
window.parent.postMessage(data, { targetOrigin: validExternalDomain });
}

return (
<div>
<p>Exporting local storage data to {validExternalDomain}</p>
</div>
);
}
11 changes: 10 additions & 1 deletion deploy-web/src/utils/localStorage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import getConfig from "next/config";
import { gt, neq } from "semver";
import { mainnetId } from "./constants";
import { mainnetId, sandboxId, testnetId } from "./constants";
const { publicRuntimeConfig } = getConfig();

const migrations = {
Expand Down Expand Up @@ -44,3 +44,12 @@ export const migrateLocalStorage = () => {
// Update the latestUpdatedVersion
localStorage.setItem("latestUpdatedVersion", currentVersion);
};

export function extractLocalStorageData() {
const networks = [mainnetId, testnetId, sandboxId];

const allKeys = Object.keys(localStorage);
const filteredKeys = allKeys.filter(key => networks.some(network => key.startsWith(network + "/")));

return filteredKeys.reduce((acc, key) => ({ ...acc, [key]: localStorage.getItem(key) }), {} as { [key: string]: string });
}

0 comments on commit cfffc7f

Please sign in to comment.