Skip to content

Commit

Permalink
Merge pull request #17 from thebitparticle/main
Browse files Browse the repository at this point in the history
cookies fix
  • Loading branch information
thebitparticle authored Oct 5, 2023
2 parents 11ac424 + cb25d22 commit 682f19d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
24 changes: 10 additions & 14 deletions src/pages/dapp/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -585,15 +585,12 @@ function DappList({ dApp, history }) {
viewLink = `${BASE_URL}/o/view/${dApp.dappId}?userId=anonymous_meroku_explorer`;
}

const [dApps, setDApps] = useState(history);

useEffect(() => {
localStorage.setItem("dApps", JSON.stringify(dApps));
}, [dApps]);

function handleAddToHistory() {
setDApps(Object.assign({}, dApps, { [app.dappId]: app }));
}
const history = localStorage?.getItem("dApps");
const previousDapps = history ? JSON.parse(history as string) : {};
const newHistory = { [dApp.dappId]: dApp, ...previousDapps, };
localStorage.setItem("dApps", JSON.stringify(newHistory));
}, [dApp]);

const onClaimButtonClick = () => {
window.gtag("event", "claim-app", {
Expand Down Expand Up @@ -845,19 +842,18 @@ export async function getServerSideProps({ query, req, res }) {

const dApp = response[0];

const history = JSON.parse(req.cookies.dApps ?? "{}");
const updatedHistory = Object.assign({}, history, { [dApp.dappId]: dApp });
// const history = JSON.parse(req.cookies.dApps ?? "{}");
// const updatedHistory = Object.assign({}, history, { [dApp.dappId]: dApp });

const cookieValue = JSON.stringify(updatedHistory);
const encodedCookieValue = encodeURIComponent(cookieValue);
res.setHeader("Set-Cookie", `dApps=${encodedCookieValue}`);
// const cookieValue = JSON.stringify(updatedHistory);
// const encodedCookieValue = encodeURIComponent(cookieValue);
// res.setHeader("Set-Cookie", `dApps=${encodedCookieValue}`);

// res.setHeader("Set-Cookie", `dApps=${JSON.stringify(updatedHistory)}`);

return {
props: {
dApp,
history: updatedHistory,
},
};
}
1 change: 0 additions & 1 deletion src/pages/history/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export default function HistoryPage(props) {
if (text) {
setHistory(JSON.parse(text));
}
console.log(history);
}, []);
return (
<PageLayout>
Expand Down

0 comments on commit 682f19d

Please sign in to comment.