Skip to content

Commit

Permalink
working on user signup
Browse files Browse the repository at this point in the history
  • Loading branch information
priyeshkadbe committed Aug 24, 2023
1 parent 9bdf44e commit 88f42b5
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
seed into code fresh camera monkey glory escape cable choice narrow hard barely
into code fresh camera monkey glory escape cable choice narrow hard barely
Empty file.
Empty file.
Empty file.
Empty file.
77 changes: 58 additions & 19 deletions src/components/wallet/import-exisiting/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@ import React, { useState } from "react";

import { useNavigate } from "react-router-dom";
import { SecretRecoveryPhase } from "./secret-recovery-phrase";
import {
checkAccountExists,
encryptMnemonic,
storeMnemonics,
storePassword,
encryptPassword
} from "@/services/accountServices";
import {Password} from "./password";
import { mnemonicToSeed } from "ethers/lib/utils";
import Stages from "./stages";


interface FormData {
password: string;
secretPhrase: string;
Expand All @@ -27,32 +35,62 @@ export default function ImportExisting() {
setStep(step + 1);
};


// const handleNextStep = async () => {
// try {
// const accountExists = await checkAccountExists(
// formData.secretPhrase.toString()
// );
// if (accountExists) {
// setStep(step + 1);
// } else {
// console.log("Wrong seed phrase");
// }
// } catch (error) {
// console.error("Error checking account existence:", error);
// }
// };

const saveToStorage = () => {
storePassword(encryptPassword(formData.password));
storeMnemonics(formData.secretPhrase);
console.log(localStorage.getItem("password"));
console.log(localStorage.getItem(""));

navigate('/home');
};


const validateSecretPhrase = () => {

}


const handlePrevStep = () => {
setStep(step - 1);
};

const handleChange = (
e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>
) => {
// const { password, mnemonic } = e.target;
// setFormData({
// ...formData,
// [mnemonic]: mnemonic,
// });
};
// const handleChange = (
// e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>
// ) => {
// // const { password, mnemonic } = e.target;
// // setFormData({
// // ...formData,
// // [mnemonic]: mnemonic,
// // });
// };

const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
// Perform form submission or other actions here
navigate("/home");
console.log(formData);
};
// const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
// e.preventDefault();
// // Perform form submission or other actions here
// navigate("/home");
// console.log(formData);
// };



const handleStageClick = (stepNumber: number) => {
// Handle going back to a previous stage
// For example, if stepNumber is 1 and currentStep is 3, setStep(1)

if (stepNumber < step) {
setStep(stepNumber);
}
Expand Down Expand Up @@ -82,7 +120,7 @@ export default function ImportExisting() {
<Password
password={formData.password}
onPrev={handlePrevStep}
onNext={handleNextStep}
onNext={saveToStorage}
/>
);
default:
Expand All @@ -93,8 +131,9 @@ export default function ImportExisting() {
return (
<div>
<div>

<Stages currentStep={step} onStageClick={handleStageClick} />
<form>{renderForm()}</form>
{renderForm()}
</div>
</div>
);
Expand Down
18 changes: 9 additions & 9 deletions src/components/wallet/import-exisiting/password.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ export const Password: React.FC<PasswordProps> = ({
const [confirmPass, setConfirmPass] = useState("");

const onSubmit = () => {
if (pass !== confirmPass) {
toast.error("The passwords do not match");
return;
}
if (pass.length < 6) {
toast.error("The password must be greater than 5 characters");
return;
}
// if (pass !== confirmPass) {
// toast.error("The passwords do not match");
// return;
// }
// if (pass.length < 6) {
// toast.error("The password must be greater than 5 characters");
// return;
// }
password = pass
console.log(password);
navigate("/home");
onNext()
};

return (
Expand Down
69 changes: 56 additions & 13 deletions src/components/wallet/import-exisiting/secret-recovery-phrase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import {
encryptMnemonic,
storeMnemonics,
} from "@/services/accountServices";
import * as bip39 from "bip39"
import { ethers } from "ethers";
import next from "next";
interface SecretRecoveryPhaseProps {
secretPhrase: string;
onNext: () => void;
Expand Down Expand Up @@ -59,27 +62,67 @@ export const SecretRecoveryPhase: React.FC<SecretRecoveryPhaseProps> = ({
return inputValues.every((value) => value.trim() !== "");
};

// const handleNext = async() => {
// if (!isAllField()) {
// toast.error("please fill all the fields");
// return false;
// }
// console.log('mnemonic',inputValues.join(" "))
// let isWalletExits = await ethers.utils.isValidMnemonic(
// inputValues.join(" ")
// );
// console.log("isWalletExits", isWalletExits);
// // if (!isWalletExits) {
// // toast.error("provided mnemonic(seed phrase) is incorrect");
// // return;
// // }

// // if (!bip39.validateMnemonic(inputValues.join(" "))) {
// // toast.error("provided mnemonic(seed phrase) is incorrect");
// // return
// // }
// if (isWalletExits) {
// toast.success("exits");
// secretPhrase = inputValues.join(" ");
// console.log(secretPhrase);
// onNext();
// } else {
// toast.error("provided mnemonic(seed phrase) is incorrect");
// }


// // if (isWalletExits==='true') {
// // onNext();
// // }

// };

const handleNext = async () => {
if (!isAllField()) {
toast.error("please fill all the fields");
return false;
}
let isWalletExits = await checkAccountExists(inputValues.join(" "));
if (!isWalletExits) {
toast.error("provided mnemonic(seed phrase) is incorrect");
return;
try {
if (!isAllField()) {
toast.error("please fill all the fields");
return ;
}
console.log(inputValues.join(" "));
let isWalletExits = await ethers.utils.isValidMnemonic(inputValues.join(" "));
if (!isWalletExits) {
toast.error("invalid mnemonic")
return
}
secretPhrase=inputValues.toString();
onNext();
} catch (error) {
toast.error("something went wrong");
}
toast.success("exits");
secretPhrase = inputValues.join(" ");
console.log(secretPhrase);
onNext();
};
}

const handleClear = () => {
const clearedValues = Array(inputValues.length).fill("");
setInputValues(clearedValues);
};



return (
<div className="flex flex-col justify-center items-center">
<ToastContainer />
Expand Down
31 changes: 17 additions & 14 deletions src/services/accountServices.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,30 @@
import ethers from "ethers"
import bcrypt from "bcryptjs";
import CryptoJS from "crypto-js";
import bip39 from "bip39"

export const validateMnemonic = async (mnemonic: string) => {
try {
await ethers.utils.isValidMnemonic(mnemonic);
return true;
} catch (error) {
return false;
}
};
// export const validateMnemonic = async (mnemonic: string) => {
// try {
// await bip39.validateMnemonic(mnemonic);
// return true;
// } catch (error) {
// return false;
// }
// };



export const checkAccountExists = async (inputValues:string) => {
let isWalletExits = validateMnemonic(inputValues);
if (!isWalletExits) {
try {
console.log("input values")
const isWalletExists = await ethers.utils.isValidMnemonic(inputValues.toString());
console.log("input values" ,isWalletExists);

return isWalletExists;
} catch (error) {
console.error("Error validating mnemonic:", error);
return false;
}
return true;
};


Expand All @@ -44,7 +50,6 @@ export const encryptMnemonic = async (mnemonic:string,password:string) => {
}
);

// Encrypt the data
const encryptedData = cipher.toString();

return encryptedData;
Expand All @@ -61,8 +66,6 @@ export const decryptMnemonic = async (encryptedMnemonic: string, password:string
padding: CryptoJS.pad.Pkcs7,
}
);

// Decrypt the data
const decryptedData = cipher.toString(CryptoJS.enc.Utf8);

return decryptedData;
Expand Down
13 changes: 12 additions & 1 deletion src/styles/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,22 @@
@tailwind utilities;

/* Set the max height and max width for the root element */


html, body {
min-width: 375px;
min-height: 600px;
overflow-y: auto;
overflow-x:hidden;
}


/*
@layer base{
body{
@apply min-w-min
@apply min-h-min
@apply overflow-x-hidden
@apply overflow-y-auto
}
}
*/

0 comments on commit 88f42b5

Please sign in to comment.