1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-25 04:40:18 +02:00
metamask-extension/ui/app/components/pages/first-time-flow/seed-phrase/confirm-seed-phrase/confirm-seed-phrase.state.js
Alexander Tseung fba17d77de Refactor first time flow, remove seed phrase from state (#5994)
* Refactor and fix styling for first time flow. Remove seed phrase from persisted metamask state

* Fix linting and tests

* Fix translations, initialization notice routing

* Fix drizzle tests

* Fix e2e tests

* Fix integration tests

* Fix styling

* Fix migration naming from 030 to 031

* Open extension in browser when user has not completed onboarding
2019-01-23 11:55:34 -03:30

42 lines
1.3 KiB
JavaScript

export function selectSeedWord (word, shuffledIndex) {
return function update (state) {
const { selectedSeedWords, selectedSeedWordsHash } = state
const nextSelectedIndex = selectedSeedWords.length
return {
selectedSeedWords: [ ...selectedSeedWords, word ],
selectedSeedWordsHash: { ...selectedSeedWordsHash, [shuffledIndex]: nextSelectedIndex },
}
}
}
export function deselectSeedWord (shuffledIndex) {
return function update (state) {
const {
selectedSeedWords: prevSelectedSeedWords,
selectedSeedWordsHash: prevSelectedSeedWordsHash,
} = state
const selectedSeedWords = [...prevSelectedSeedWords]
const indexToRemove = prevSelectedSeedWordsHash[shuffledIndex]
selectedSeedWords.splice(indexToRemove, 1)
const selectedSeedWordsHash = Object.keys(prevSelectedSeedWordsHash).reduce((acc, index) => {
const output = { ...acc }
const selectedSeedWordIndex = prevSelectedSeedWordsHash[index]
if (selectedSeedWordIndex < indexToRemove) {
output[index] = selectedSeedWordIndex
} else if (selectedSeedWordIndex > indexToRemove) {
output[index] = selectedSeedWordIndex - 1
}
return output
}, {})
return {
selectedSeedWords,
selectedSeedWordsHash,
}
}
}