Skip to content

Commit

Permalink
add restore/reset functions
Browse files Browse the repository at this point in the history
  • Loading branch information
sirnicolaz committed Sep 20, 2024
1 parent 66b29f4 commit 1cc8313
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 35 deletions.
1 change: 1 addition & 0 deletions web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ function App({ children }: Props) {
<Box
backgroundColor="transparent"
marginTop="20px"
marginBottom="60px"
width={isMobile ? "95%" : "40%"}
>
{children}
Expand Down
69 changes: 65 additions & 4 deletions web/src/Settings.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { Button, Heading, Text, Textarea, VStack } from "@chakra-ui/react";
import {
Button,
Heading,
Text,
Textarea,
useToast,
VStack,
} from "@chakra-ui/react";
import { useBurnerWallet } from "./hooks/useBurnerWallet";
import { useState } from "react";
import { dump, restore } from "./hooks/storage";
import { useEffect, useState } from "react";
import QRCode from "react-qr-code";
import { treasureHuntCreatorAddress } from "./generated";
import { CHAIN_ID } from "./env";
Expand All @@ -13,18 +21,53 @@ function Settings() {
resetMnemonic,
} = useBurnerWallet();

const toast = useToast();

let [temporaryMnemonic, setTemporaryMnemonic] = useState(mnemonic || "");
let [temporaryDump, setTemporaryDump] = useState(dump());

let handleInputChange = (e: any) => {
let inputValue = e.target.value;
setTemporaryMnemonic(inputValue);
};

let handleDumpChange = (e: any) => {
let inputValue = e.target.value;
setTemporaryDump(inputValue);
};

function reset() {
localStorage.clear();
resetMnemonic();
setTemporaryMnemonic(mnemonic);
}

function restoreFromDump() {
if (temporaryDump !== "") {
restore(temporaryDump);
toast({
title: "Success!",
description: `You restored your game!`,
status: "success",
duration: 9000,
isClosable: true,
});
} else {
toast({
title: "No dump",
description: `There is not dump in the text area`,
status: "info",
duration: 9000,
isClosable: true,
});
}
}

useEffect(() => {
if (mnemonic !== "") setTemporaryMnemonic(mnemonic);

setTemporaryDump(dump());
}, [mnemonic]);

return (
<VStack alignItems="flex-start">
<Heading marginBottom="40px">Settings</Heading>
Expand Down Expand Up @@ -67,8 +110,26 @@ function Settings() {
<Heading variant="h2" marginTop="40px">
Reset Game
</Heading>
<Text>Reset the current session, you'll start from Chapter 0 again</Text>
<Text>
Reset the current session, you'll start from Chapter 0 again. You should
make a backup first.
</Text>
<Textarea
value={temporaryDump}
onChange={handleDumpChange}
placeholder="Your dump"
></Textarea>
<Button onClick={() => reset()}>Reset Game</Button>
<Heading variant="h2" marginTop="40px">
Restore
</Heading>
<Text>Restore the game providing a dump</Text>
<Textarea
value={temporaryDump}
onChange={handleDumpChange}
placeholder="Your dump"
></Textarea>
<Button onClick={() => restoreFromDump()}>Restore from dump</Button>
</VStack>
);
}
Expand Down
4 changes: 0 additions & 4 deletions web/src/hooks/keys.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion web/src/hooks/useBurnerWallet.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useState } from "react";
import { MNEMONIC_KEY } from "./keys";
import { MNEMONIC_KEY } from "./storage";
import { english, generateMnemonic } from "viem/accounts";
import useLocalStorage from "use-local-storage";
import { useToast } from "@chakra-ui/react";
Expand Down
2 changes: 1 addition & 1 deletion web/src/hooks/useChapter.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useState } from "react";
import { CURRENT_CHAPTER_PASSWORD_KEY } from "./keys";
import { CURRENT_CHAPTER_PASSWORD_KEY } from "./storage";
import { decrypt } from "../lib";
import { useReadContract } from "wagmi";
import {
Expand Down
29 changes: 4 additions & 25 deletions web/src/theme/fonts.css
Original file line number Diff line number Diff line change
@@ -1,49 +1,28 @@
@font-face {
font-family: "Bundes";
font-weight: 400;
src: url(./fonts/BundesSans-Regular.ttf);
}
@font-face {
font-family: "Bundes";
font-weight: 700;
src: url(./fonts/BundesSans-Regular.ttf);
}
@font-face {
font-family: "Dot";
font-weight: 400;
src: url(./fonts/Dot.ttf);
}
@font-face {
font-family: "Maison Neues";
font-weight: 400;
src: url(./fonts/Maison-Neue-Mono.ttf);
}
@font-face {
font-family: OCR;
font-weight: 700;
src: url(./fonts/OCR-AStd-Regular.ttf);
}
@font-face {
font-family: OCR;
font-weight: 700;
src: url(./fonts/OCR-AStd-Regular.ttf);
}

@font-face {
font-family: Roboto;
font-weight: 400;
src: url(./fonts/Roboto-Regular.ttf);
}

@font-face {
font-family: Roboto;
font-weight: 400;
font-style: italic;
src: url(./fonts/Roboto-Italic.ttf);
}

@font-face {
font-family: Roboto;
font-weight: 700;
src: url(./fonts/Roboto-Bold.ttf);
}

@font-face {
font-family: Roboto;
font-weight: 700;
Expand Down

0 comments on commit 1cc8313

Please sign in to comment.