Skip to content

Commit

Permalink
New Waverly Onboarding Workflow To Fix Login Issues 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
whoisanku authored Feb 28, 2023
2 parents 989e48b + 543dfc0 commit fb35b39
Show file tree
Hide file tree
Showing 13 changed files with 524 additions and 409 deletions.
36 changes: 18 additions & 18 deletions src/Components/HeartOperation.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ const HeartOperation = () => {
console.log(public_key);
const delay = (ms) => new Promise((res) => setTimeout(res, ms));
await delay(2000);

} catch (error) {
setIsUsername(false);
setLoading(false);
Expand All @@ -51,7 +50,7 @@ const HeartOperation = () => {
// fetch posthash hex of numberofpost to an array
const deso = new Deso();
const no_of_posts = Number(numberOfPost);
const reader_pub_key = localStorage.getItem("user_key");
const reader_pub_key = localStorage.getItem("user_key_popup");
const reading_pub_key = public_key;
const request = {
PublicKeyBase58Check: reading_pub_key,
Expand All @@ -63,7 +62,6 @@ const HeartOperation = () => {
postHexes.push(response.Posts[i].PostHashHex);
}
// cool got the hexes here

}
let seed;
let senderPubKey;
Expand All @@ -75,11 +73,11 @@ const HeartOperation = () => {
await getProfile();
// fetch post of user
await fetchPosts();
seed = localStorage.getItem("derived_seed_hex");
senderPubKey = localStorage.getItem("user_key");
derived_pub_key = localStorage.getItem("derived_pub_key");
seed = localStorage.getItem("derived_seed_hex_popup");
senderPubKey = localStorage.getItem("user_key_popup");
derived_pub_key = localStorage.getItem("derived_pub_key_popup");
// send diamonds required data posthash hex collection array of no of Posts to fetch
localStorage.setItem("postLen", '0');
localStorage.setItem("postLen", "0");
localStorage.setItem("postLen", numberOfPost.toString());
setIsUsername(true);
chrome.runtime.sendMessage({
Expand Down Expand Up @@ -133,10 +131,10 @@ const HeartOperation = () => {
setLoading(true);
setIsUsername(true);
setUsername("Wait...");
const postLen = localStorage.getItem("postLen")
setNumberOfPost(postLen)
const postLen = localStorage.getItem("postLen");
setNumberOfPost(postLen);
if (postLen == message.message) {
setLoading(false)
setLoading(false);
setUsername("");
setIsUsername(false);
setNumberOfPost(10);
Expand Down Expand Up @@ -188,8 +186,9 @@ const HeartOperation = () => {
focused
) => (
<div
className={`user ${focused ? "focused" : ""
} flex flex-row rounded-xl lato`}
className={`user ${
focused ? "focused" : ""
} flex flex-row rounded-xl lato`}
>
<div className=" flex flex-row rounded-xl lato">
<img
Expand Down Expand Up @@ -234,14 +233,15 @@ const HeartOperation = () => {
</div>
</div>
{/* Submit Button */}
<div className="flex justify-between items-center mt-[2.7rem] mr-1">
<div className="flex justify-between items-center mt-[2.5rem] mr-1">
<div className="lato"></div>
<div className="flex items-center space-x-5">
<button
className={`select-none focus:outline-none bg-[#efefef] mt-2 ${Dark
? "bigbtn-dark hover:border-[#ff7521] "
: "bigbtn bg-[#efefef]"
}`}
className={`select-none focus:outline-none bg-[#efefef] mt-2 ${
Dark
? "bigbtn-dark hover:border-[#ff7521] "
: "bigbtn bg-[#efefef]"
}`}
onClick={handleHeartButton}
disabled={loading}
>
Expand All @@ -268,4 +268,4 @@ const HeartOperation = () => {
);
};

export default HeartOperation;
export default HeartOperation;
142 changes: 65 additions & 77 deletions src/Components/Index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,84 +7,72 @@ import { WaverlyContext } from "../Contexts/WaverlyContext";
import { MemoryRouter as Router, Route, Routes } from "react-router-dom";

function Index() {
const [logIn, setLogIn] = useState(false);
const [settingActive, setSettingActive] = useState(false);
const [menuActive, setMenuActive] = useState(false);
const [Dark, setDark] = useState(false);
const [textBoxActive2, setTextBoxActive2] = useState(false);
const [shower, setShower] = useState("diamond");
const [tipLevel, setTipLevel] = useState("1");
const [settingActive, setSettingActive] = useState(false);
const [menuActive, setMenuActive] = useState(false);
const [Dark, setDark] = useState(false);
const [textBoxActive2, setTextBoxActive2] = useState(false);
const [shower, setShower] = useState("diamond");
const [tipLevel, setTipLevel] = useState("1");

useEffect(() => {
const isLoggedIn = localStorage.getItem("isLoggedIn");
const isDark = localStorage.getItem("dark");
const diamondORheart = localStorage.getItem("showerOption");
if (diamondORheart === "heart") {
setShower("heart");
}
if (diamondORheart === "diamond") {
setShower("diamond");
}
if (isLoggedIn === "true") {
setLogIn(true);
}
if (isDark === true) {
setDark(true);
}
}, []);
useEffect(() => {
const isDark = localStorage.getItem("dark");
const diamondORheart = localStorage.getItem("showerOption");
if (diamondORheart === "heart") {
setShower("heart");
}
if (diamondORheart === "diamond") {
setShower("diamond");
}
if (isDark === true) {
setDark(true);
}
}, []);

return (
<>
<WaverlyContext.Provider
value={{
Dark,
setDark,
setSettingActive,
textBoxActive2,
setTextBoxActive2,
logIn,
setLogIn,
tipLevel,
setTipLevel
}}
>
<Router>
<div>
<Nav
logIn={logIn}
setSettingActive={setSettingActive}
menuActive={menuActive}
setMenuActive={setMenuActive}
Dark={Dark}
setDark={setDark}
/>
<Routes>
{logIn ? (
<Route
exact
path="/"
element={
<LoggedIn
settingActive={settingActive}
setSettingActive={setSettingActive}
menuActive={menuActive}
setMenuActive={setMenuActive}
Dark={Dark}
setDark={setDark}
shower={shower}
setShower={setShower}
/>
}
/>
) : (
<Route exact path="/" element={<Landing logIn={setLogIn} />} />
)}
</Routes>
</div>
</Router>
</WaverlyContext.Provider>
</>
);
return (
<>
<WaverlyContext.Provider
value={{
Dark,
setDark,
setSettingActive,
textBoxActive2,
setTextBoxActive2,
tipLevel,
setTipLevel,
}}
>
<Router>
<div>
<Nav
setSettingActive={setSettingActive}
menuActive={menuActive}
setMenuActive={setMenuActive}
Dark={Dark}
setDark={setDark}
/>
<Routes>
<Route
exact
path="/"
element={
<LoggedIn
settingActive={settingActive}
setSettingActive={setSettingActive}
menuActive={menuActive}
setMenuActive={setMenuActive}
Dark={Dark}
setDark={setDark}
shower={shower}
setShower={setShower}
/>
}
/>
</Routes>
</div>
</Router>
</WaverlyContext.Provider>
</>
);
}

export default Index;
export default Index;
34 changes: 12 additions & 22 deletions src/Components/Landing.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ import React from "react";
import Deso from "deso-protocol";

const Landing = ({ logIn }) => {
let derivedSeedHex_bg;
let dervidedPubKey_bg;
let publickey_bg;
let transactionSpendingLimitHex_bg;
let expirationBlock_bg;
let accessSignature_bg;
const deso = new Deso();
const handleLogin = async () => {
const derivePayload = {
Expand All @@ -24,20 +18,14 @@ const Landing = ({ logIn }) => {
};
const user = await deso.identity.derive(derivePayload);
console.log(user);
localStorage.setItem("derived_pub_key", user.derivedPublicKeyBase58Check);
localStorage.setItem("derived_seed_hex", user.derivedSeedHex);
localStorage.setItem("user_key", user.publicKeyBase58Check);
localStorage.setItem("JWT_KEY", user.jwt);
localStorage.setItem("isLoggedIn", "true");
logIn(true);
dervidedPubKey_bg = localStorage.getItem("derived_pub_key");
derivedSeedHex_bg = localStorage.getItem("derived_seed_hex");
publickey_bg = localStorage.getItem("user_key");
transactionSpendingLimitHex_bg = user.transactionSpendingLimitHex;
expirationBlock_bg = user.expirationBlock;
accessSignature_bg = user.accessSignature;
let dervidedPubKey_bg = user.derivedPublicKeyBase58Check;
let derivedSeedHex_bg = user.derivedSeedHex;
let publickey_bg = user.publicKeyBase58Check;
let transactionSpendingLimitHex_bg = user.transactionSpendingLimitHex;
let expirationBlock_bg = user.expirationBlock;
let accessSignature_bg = user.accessSignature;
console.log(user);
await chrome.runtime.sendMessage({
chrome.runtime.sendMessage({
getLoginFunction: true,
dervidedPubKey_bg,
derivedSeedHex_bg,
Expand All @@ -46,14 +34,16 @@ const Landing = ({ logIn }) => {
transactionSpendingLimitHex_bg,
accessSignature_bg,
});

// user[]
localStorage.setItem("derived_pub_key", user.derivedPublicKeyBase58Check);
localStorage.setItem("derived_seed_hex", user.derivedSeedHex);
localStorage.setItem("user_key", user.publicKeyBase58Check);
localStorage.setItem("JWT_KEY", user.jwt);
};

// return jsx
return (
<div className="w-[40rem] h-[25rem] border ">
<div className="w-full h-full flex justify-center items-center text-center">
<div className="w-full h-full flex justify-center items-center text-center">
<div>
<div className="absolute top-40 left-14 text-3xl text-center welcomewaverly select-none">
<span id="welcometo">Welcome to </span>Waverly 🌊👋
Expand Down
Loading

0 comments on commit fb35b39

Please sign in to comment.