-
Notifications
You must be signed in to change notification settings - Fork 42
implement UX fixes and design for mnemonic phrase views #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
bceca95
e312be7
6d0c8c0
dd2123c
2a37d09
e04bd30
f707df9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,29 +3,52 @@ import styled from "styled-components"; | |
| import { shuffle } from "lodash"; | ||
| import { useDispatch, useSelector } from "react-redux"; | ||
| import { confirmMnemonicPhrase, authErrorSelector } from "ducks/authServices"; | ||
| import { ErrorMessage } from "components/form"; | ||
| import { ErrorMessage, FormButton } from "components/form"; | ||
| import { COLOR_PALETTE } from "styles"; | ||
| import { Button } from "styles/Basics"; | ||
| import CheckButton from "./basics/CheckButton"; | ||
|
|
||
| const ConfirmInput = styled.textarea` | ||
| background: #d3d3d3; | ||
| const ConfirmInput = styled.div` | ||
| background: #d2d8e5; | ||
| border: 0; | ||
| border-radius: 5px; | ||
| color: purple; | ||
| font-size: 14px; | ||
| padding: 20px 30px; | ||
| width: 60%; | ||
| border-radius: 30px; | ||
| box-sizing: border-box; | ||
| color: ${COLOR_PALETTE.primary}; | ||
| font-size: 1.125rem; | ||
| height: 160px; | ||
| padding: 2.3rem; | ||
| resize: none; | ||
| width: 100%; | ||
| margin-bottom: 20px; | ||
| text-align: center; | ||
| `; | ||
|
|
||
| const ClearButton = styled(Button)` | ||
| background: ${COLOR_PALETTE.primaryGradient}; | ||
| border-radius: 7px; | ||
| color: #fff; | ||
| font-weight: 800; | ||
| height: 24px; | ||
| margin-left: 7px; | ||
| width: 24px; | ||
| `; | ||
|
|
||
| const ConfirmMnemonicPhrase = ({ | ||
| mnemonicPhrase, | ||
| setReadyToConfirm, | ||
| }: { | ||
| mnemonicPhrase: string; | ||
| setReadyToConfirm: (readyToConfirm: boolean) => void; | ||
| }) => { | ||
| const dispatch = useDispatch(); | ||
| const words = useRef(shuffle(mnemonicPhrase.split(" "))); | ||
| const words = shuffle(mnemonicPhrase.split(" ")); | ||
| const wordState = useRef( | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this form starts to get more complicated bc we're introducing a "clear field" button. we need to create an object to store all the values of each form input so we can clear em all at once when needed
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is the initial state. setting all the checkboxes to false (AKA, not checked)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be a good idea to switch to Formik or another form tool sooner rather than later. I know that Formik gives you "reset form" out of the box
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yup, been looking at some form libraries. The next iteration of this will be using one |
||
| words.reduce( | ||
| (obj, current, i) => ({ | ||
| ...obj, | ||
| [`${current}-${i}`]: false, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we need to create a unique key bc evidently a mnemonic phrase can repeat the same word at different pts |
||
| }), | ||
| {}, | ||
| ), | ||
| ); | ||
| const [selectedWords, setSelectedWords] = useState<string[]>([]); | ||
| const authError = useSelector(authErrorSelector); | ||
|
|
||
|
|
@@ -40,16 +63,31 @@ const ConfirmMnemonicPhrase = ({ | |
| }); | ||
| }; | ||
|
|
||
| const initialWordState = wordState.current; | ||
|
|
||
| const [checkboxState, setCheckboxState] = useState(initialWordState); | ||
|
|
||
| const wordStateArr: [string, boolean][] = Object.entries(checkboxState); | ||
|
|
||
| const wordBubbles = () => | ||
| words.current.map((word) => ( | ||
| wordStateArr.map(([wordKey, value]) => ( | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. grab each "word/checked" state and create a checkbox from it |
||
| <CheckButton | ||
| onChange={(e) => { | ||
| setCheckboxState((prev) => ({ ...prev, [wordKey]: !value })); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. update the form state to track changing values |
||
| updatePhrase(e.target); | ||
| }} | ||
| word={word} | ||
| key={wordKey} | ||
| wordKey={wordKey} | ||
| value={value} | ||
| word={wordKey.replace(/-.*/, "")} | ||
| /> | ||
| )); | ||
|
|
||
| const clearFields = () => { | ||
| setSelectedWords([]); | ||
| setCheckboxState(initialWordState); | ||
| }; | ||
|
|
||
| const handleSubmit = (e: React.FormEvent) => { | ||
| e.preventDefault(); | ||
| dispatch(confirmMnemonicPhrase(selectedWords.join(" "))); | ||
|
|
@@ -58,16 +96,18 @@ const ConfirmMnemonicPhrase = ({ | |
| <> | ||
| <form onSubmit={handleSubmit}> | ||
| <div> | ||
| <ConfirmInput readOnly value={selectedWords.join(" ")} /> | ||
| <ConfirmInput> | ||
| {selectedWords.join(" ")} | ||
| {selectedWords.length ? ( | ||
| <ClearButton type="button" onClick={clearFields}> | ||
| X | ||
| </ClearButton> | ||
| ) : null} | ||
| </ConfirmInput> | ||
| <ErrorMessage authError={authError}></ErrorMessage> | ||
| </div> | ||
| {wordBubbles()} | ||
| <div> | ||
| <button type="submit">Confirm</button> | ||
| </div> | ||
| <div> | ||
| <button onClick={() => setReadyToConfirm(false)}>Go back</button> | ||
| </div> | ||
| <FormButton type="submit">Confirm</FormButton> | ||
| </form> | ||
| </> | ||
| ); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.