-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add onboarding flow for web extension (#3582)
- Loading branch information
Showing
30 changed files
with
22,210 additions
and
64 deletions.
There are no files selected for viewing
21,700 changes: 21,660 additions & 40 deletions
21,700
applications/tari_web_extension/package-lock.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,37 @@ | ||
import "./app.css"; | ||
import "./app.scss"; | ||
import React, { useEffect } from "react"; | ||
import { MemoryRouter, Navigate, Route, Routes } from "react-router"; | ||
import Assets from "./screens/assets/assets"; | ||
import Login from "./screens/login/login"; | ||
import { Navigate, Route, Routes } from "react-router"; | ||
import { useDispatch, useSelector } from "react-redux"; | ||
import { getCredentials, refreshLogin } from "./redux/loginSlice"; | ||
import { | ||
getCredentials, | ||
getCredentialsCalled, | ||
refreshLogin, | ||
} from "./redux/loginSlice"; | ||
import Onboarding from "./onboarding/Onboarding"; | ||
import { HashRouter } from "react-router-dom"; | ||
import Popup from "./popup/Popup"; | ||
|
||
export default function App() { | ||
const credentials = useSelector(getCredentials); | ||
const credentialsCalled = useSelector(getCredentialsCalled); | ||
const dispatch = useDispatch(); | ||
useEffect(() => { | ||
dispatch(refreshLogin()); | ||
}, [dispatch]); | ||
|
||
if (!credentials) { | ||
if (!window.location.href.includes("#/onboarding") && credentialsCalled) { | ||
window.open("#/onboarding"); | ||
} | ||
} | ||
return ( | ||
<div className="main"> | ||
<MemoryRouter> | ||
<HashRouter> | ||
<Routes> | ||
<Route path="/assets" element={<Assets />} /> | ||
<Route | ||
path="*" | ||
element={credentials ? <Navigate to="/assets" /> : <Login />} | ||
/> | ||
<Route path="/onboarding/*" element={<Onboarding />} /> | ||
<Route path="/popup/*" element={<Popup />} /> | ||
<Route path="" element={<Navigate replace to="popup" />} /> | ||
</Routes> | ||
</MemoryRouter> | ||
</HashRouter> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
*, | ||
*::after, | ||
*::before { | ||
margin: 0; | ||
padding: 0; | ||
box-sizing: border-box; | ||
} |
10 changes: 10 additions & 0 deletions
10
applications/tari_web_extension/src/onboarding/Complete/Complete.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import React from "react"; | ||
|
||
export default function Complete() { | ||
window.close(); | ||
return ( | ||
<div className="screen"> | ||
<div className="caption">Complete</div> | ||
</div> | ||
); | ||
} |
57 changes: 57 additions & 0 deletions
57
applications/tari_web_extension/src/onboarding/ConfirmSeedWords/ConfirmSeedWords.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import "./confirmseedwords.scss"; | ||
import React, { useState } from "react"; | ||
import { Link } from "react-router-dom"; | ||
import { useLocation } from "react-router"; | ||
|
||
export default function ConfirmSeedWords() { | ||
const [wordsOrder, setWordsOrder] = useState([]); | ||
const location = useLocation(); | ||
const seedWords = location.state.seedWords.split(" "); | ||
const alphabeticalSeedWords = [...seedWords]; | ||
alphabeticalSeedWords.sort(); | ||
const onWordClick = (word) => { | ||
if (wordsOrder.includes(word)) { | ||
// remove | ||
setWordsOrder(wordsOrder.filter((value) => value !== word)); | ||
} else { | ||
// add | ||
setWordsOrder([...wordsOrder, word]); | ||
} | ||
}; | ||
const checkSeedWords = () => | ||
JSON.stringify(seedWords) === JSON.stringify(wordsOrder); | ||
|
||
return ( | ||
<div className="screen"> | ||
<div className="caption">ConfirmSeedWords</div> | ||
<div className="ordered"> | ||
<div className="ordered-items"> | ||
{wordsOrder.map((word) => ( | ||
<div key={word} className="seed-word"> | ||
{word} | ||
</div> | ||
))} | ||
</div> | ||
</div> | ||
<div className="unordered"> | ||
{alphabeticalSeedWords.map((word) => ( | ||
<div | ||
key={word} | ||
className={`seed-word seed-word-button ${ | ||
wordsOrder.includes(word) ? "seed-word-button-pressed" : "" | ||
}`} | ||
onClick={() => onWordClick(word)} | ||
> | ||
{word} | ||
</div> | ||
))} | ||
</div> | ||
<Link | ||
to="../complete" | ||
className={`button ${checkSeedWords() || 1 ? "" : "disabled-button"}`} | ||
> | ||
Next | ||
</Link> | ||
</div> | ||
); | ||
} |
54 changes: 54 additions & 0 deletions
54
applications/tari_web_extension/src/onboarding/ConfirmSeedWords/confirmseedwords.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
.ordered { | ||
display: block; | ||
margin: 20px; | ||
width: 40%; | ||
border: 1px solid; | ||
padding: 10px; | ||
border-radius: 5px; | ||
height: calc( | ||
4 * 42px + 3 * 10px + 2 * 10px + 2px | ||
); // 4 buttons (42px height, 10px padding, 2px border) + 3 gaps (10px) | ||
.ordered-items { | ||
display: grid; | ||
width: 100%; | ||
height: auto; | ||
grid-template-columns: 1fr 1fr 1fr 1fr 1fr 1fr; | ||
row-gap: 10px; | ||
column-gap: 10px; | ||
} | ||
} | ||
|
||
.unordered { | ||
display: grid; | ||
grid-template-columns: 1fr 1fr 1fr 1fr 1fr 1fr; | ||
grid-template-rows: 1fr 1fr 1fr 1fr; | ||
row-gap: 10px; | ||
column-gap: 10px; | ||
margin: 20px; | ||
width: 40%; | ||
} | ||
|
||
.seed-word { | ||
justify-self: stretch; | ||
border: 2px solid #ffaaaa; | ||
border-radius: 5px; | ||
text-align: center; | ||
padding: 10px; | ||
color: red; | ||
height: 42px; | ||
} | ||
|
||
.seed-word-button-pressed { | ||
background-color: #ff2222; | ||
color: white; | ||
} | ||
|
||
.seed-word-button:hover { | ||
border-color: #ff0000; | ||
cursor: pointer; | ||
} | ||
|
||
.seed-word-button-pressed:hover { | ||
background-color: #dd0000; | ||
color: white; | ||
} |
54 changes: 54 additions & 0 deletions
54
applications/tari_web_extension/src/onboarding/CreateWallet/CreateWallet.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import React, { useState } from "react"; | ||
import { useDispatch } from "react-redux"; | ||
import { Link } from "react-router-dom"; | ||
import { login } from "../../redux/loginSlice"; | ||
|
||
export default function CreateWallet() { | ||
const [password, setPassword] = useState(""); | ||
const [confirmPassword, setConfirmPassword] = useState(""); | ||
const dispatch = useDispatch(); | ||
|
||
const onPasswordChange = (e) => { | ||
setPassword(e.target.value); | ||
}; | ||
|
||
const onConfirmPasswordChange = (e) => { | ||
setConfirmPassword(e.target.value); | ||
}; | ||
|
||
const checkPasswords = () => | ||
password === confirmPassword && password.length >= 6; | ||
|
||
const createWallet = () => { | ||
console.log("dispatching login"); | ||
const username = "username"; | ||
dispatch(login({ username, password })); | ||
}; | ||
|
||
return ( | ||
<div className="screen"> | ||
<div className="caption">Create Password</div> | ||
New password (....) | ||
<input | ||
name="password" | ||
value={password} | ||
type="password" | ||
onChange={onPasswordChange} | ||
></input> | ||
Confirm password | ||
<input | ||
name="confirm-password" | ||
value={confirmPassword} | ||
type="password" | ||
onChange={onConfirmPasswordChange} | ||
></input> | ||
<Link | ||
to="../seed-phrase" | ||
className={`button ${checkPasswords() ? "" : "disabled-button"}`} | ||
onClick={createWallet} | ||
> | ||
Create | ||
</Link> | ||
</div> | ||
); | ||
} |
57 changes: 57 additions & 0 deletions
57
applications/tari_web_extension/src/onboarding/ImportWallet/ImportWallet.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import "./importwallet.scss"; | ||
import React, { useState } from "react"; | ||
import { Link } from "react-router-dom"; | ||
|
||
export default function ImportWallet() { | ||
const [seedWords, setSeedWords] = useState(""); | ||
const [password, setPassword] = useState(""); | ||
const [confirmPassword, setConfirmPassword] = useState(""); | ||
const onSeedPhraseChange = (e) => { | ||
setSeedWords(e.target.value); | ||
}; | ||
const onPasswordChange = (e) => { | ||
setPassword(e.target.value); | ||
}; | ||
|
||
const onConfirmPasswordChange = (e) => { | ||
setConfirmPassword(e.target.value); | ||
}; | ||
|
||
const checkSeedWords = () => seedWords.split(" ").length === 24; | ||
|
||
const checkPasswords = () => | ||
password === confirmPassword && password.length >= 6; | ||
|
||
const checkForm = () => checkSeedWords() && checkPasswords(); | ||
|
||
return ( | ||
<div className="screen"> | ||
<div className="caption">ImportWallet</div> | ||
<textarea | ||
className="seedwords" | ||
value={seedWords} | ||
onChange={onSeedPhraseChange} | ||
/> | ||
New password (....) | ||
<input | ||
name="password" | ||
value={password} | ||
type="password" | ||
onChange={onPasswordChange} | ||
></input> | ||
Confirm password | ||
<input | ||
name="confirm-password" | ||
value={confirmPassword} | ||
type="password" | ||
onChange={onConfirmPasswordChange} | ||
></input> | ||
<Link | ||
to="../complete" | ||
className={`button ${checkForm() ? "" : "disabled-button"}`} | ||
> | ||
Next | ||
</Link> | ||
</div> | ||
); | ||
} |
10 changes: 10 additions & 0 deletions
10
applications/tari_web_extension/src/onboarding/ImportWallet/importwallet.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.screen { | ||
.seedwords { | ||
width: 30%; | ||
max-width: 30%; | ||
height: 5em; | ||
padding: 10px; | ||
font-size: larger; | ||
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
applications/tari_web_extension/src/onboarding/Improve/Improve.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from "react"; | ||
import { useLocation } from "react-router"; | ||
import { Link } from "react-router-dom"; | ||
|
||
export default function Improve() { | ||
const location = useLocation(); | ||
const { next } = location.state; | ||
return ( | ||
<div className="screen"> | ||
<div className="caption">Help us improve</div> | ||
<Link to={next} className="button"> | ||
I Agree | ||
</Link> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.