Skip to content

Commit

Permalink
Merge branch 'devnet' of https://github.com/Eldar-Finance/hackathon i…
Browse files Browse the repository at this point in the history
…nto devnet
  • Loading branch information
klepi21 committed Oct 13, 2023
2 parents 1bb4ab6 + 6b9a4f9 commit 510adab
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
10 changes: 5 additions & 5 deletions src/views/Home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import Particles from "react-particles";
//import { loadFull } from "tsparticles"; // if you are going to use `loadFull`, install the "tsparticles" package too.
import { loadSlim } from "tsparticles-slim";
import type { Container, Engine } from "tsparticles-engine";
import { useState } from "react";



Expand Down Expand Up @@ -63,11 +64,11 @@ const particlesLoaded = useCallback(async (container: Container | undefined) =>

const {userInfo, isLoadingUserInfo, errorUserInfo} = useGetUserInfo(email, platform);

const [clickedSubmit, setClickedSubmit] = useState(false);

let userExists = false;
let walletExists = false;
if (!isLoadingUserInfo && session && userInfo?.address != "") {
userExists = true;
walletExists = true;
}

if (session) {
Expand All @@ -85,12 +86,11 @@ const particlesLoaded = useCallback(async (container: Container | undefined) =>
>
Sign Out
</Button>
{userExists && walletExists ?
{userExists && !clickedSubmit ?
<ExistingUser email={session?.user?.email} address={userInfo?.address || ""} secretWords={userInfo?.secretWords || []} userGid={session?.user?.sub}/>
:
<NewUserForm email={email} userGid={session?.user?.sub}/>
<NewUserForm email={email} userGid={session?.user?.sub} setClickedSubmit={setClickedSubmit} />
}
{/* <NewUserForm email={email} userGid={session?.user?.sub}/>*/}
</Box>
)
}
Expand Down
11 changes: 10 additions & 1 deletion src/views/Home/components/NewUserForm/CreateWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@ import { createEncryptionKey, encrypt } from "@/utils/functions/cryptography";
import { network } from "@/config.devnet";
import { TransactionActionsEnum } from "@multiversx/sdk-dapp/types";

export default function CreateWallet({ pin, email, handleReset, userGid }: { pin: string, email: string, handleReset: any, userGid: string }) {
interface CreateWalletProps {
pin: string;
email: string;
handleReset: () => void;
userGid: string;
setClickSubmit: React.Dispatch<React.SetStateAction<boolean>>;
}

export default function CreateWallet({ pin, email, handleReset, userGid, setClickSubmit }: CreateWalletProps) {

const [encryptionKey, setEncryptionKey] = useState(createEncryptionKey(pin, userGid));
const [walletCreationHash, setWalletCreationHash] = useState("");
Expand Down Expand Up @@ -131,6 +139,7 @@ export default function CreateWallet({ pin, email, handleReset, userGid }: { pin

const handleSubmit = async () => {
setClickedSubmit(true);
setClickSubmit(true);
try {
const hash = await createUser(
email,
Expand Down
20 changes: 16 additions & 4 deletions src/views/Home/components/NewUserForm/NewUserForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@ import { useGetUserInfo } from "@/views/Home/hooks/hooks";
import { useEffect } from "react";
import ViewWallet from "./ViewWallet";

function NewUserForm({ email, userGid }: { email: string; userGid: string; }) {
interface NewUserFormProps {
email: string;
userGid: string;
setClickedSubmit: React.Dispatch<React.SetStateAction<boolean>>; // Callback function to update clickedSubmit in parent
}

function NewUserForm({ email, userGid, setClickedSubmit }: NewUserFormProps) {
const platform = "google";
const { userInfo, isLoadingUserInfo, errorUserInfo } = useGetUserInfo(email, platform);

console.log(userInfo)

const [pin, setPin] = useState("");
const [isPinFilled, setIsPinFilled] = useState(false);
const [activeStep, setActiveStep] = useState(0);
Expand All @@ -50,6 +54,7 @@ function NewUserForm({ email, userGid }: { email: string; userGid: string; }) {
setPin("");
setIsPinFilled(false);
setActiveStep(0);
setClickSubmit(false);
}

const handleCreatePinClick = () => {
Expand All @@ -68,6 +73,13 @@ function NewUserForm({ email, userGid }: { email: string; userGid: string; }) {
}
};

const [clickedSubmit, setClickSubmit] = useState(false);
const handleCreateWalletSubmit = () => {
console.log("clicked submit from new user form")
setClickSubmit(true);
setClickedSubmit(true);
}

return (
<Box px={20} marginTop={'100px'}>
<Flex flexDir="column" width="100%">
Expand Down Expand Up @@ -100,7 +112,7 @@ function NewUserForm({ email, userGid }: { email: string; userGid: string; }) {
/>
)}
{index === 1 && isPinFilled && (
<CreateWallet pin={pin} email={email} handleReset={handleReset} userGid={userGid} />
<CreateWallet pin={pin} email={email} handleReset={handleReset} userGid={userGid} setClickSubmit={handleCreateWalletSubmit }/>
)}
{index > 1 && userInfo && !isLoadingUserInfo &&
<ViewWallet userInfo={userInfo} isLoadingUserInfo={isLoadingUserInfo} />
Expand Down

0 comments on commit 510adab

Please sign in to comment.