Skip to content
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

feature/support-24-word-seed-phrase-game #1954

Merged
merged 1 commit into from
Nov 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions app/components/Views/AccountBackupStep5/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,22 @@ class AccountBackupStep5 extends PureComponent {
}

state = {
confirmedWords: Array(12).fill({ word: undefined, originalPosition: undefined }),
confirmedWords: [],
showSuccessModal: false,
wordsDict: {},
currentIndex: 0,
seedPhraseReady: false
};

componentDidMount = () => {
this.createWordsDictionary();
const { navigation } = this.props;
const words = navigation.getParam('words', []);
this.setState(
{
confirmedWords: Array(words.length).fill({ word: undefined, originalPosition: undefined })
},
this.createWordsDictionary
);
};

createWordsDictionary = () => {
Expand Down Expand Up @@ -297,6 +304,8 @@ class AccountBackupStep5 extends PureComponent {

render = () => {
const { confirmedWords, wordsDict, seedPhraseReady } = this.state;
const wordLength = confirmedWords.length;
const half = wordLength / 2;
return (
<SafeAreaView style={styles.mainWrapper}>
<ScrollView style={styles.mainWrapper} testID={'account-backup-step-5-screen'}>
Expand All @@ -313,10 +322,12 @@ class AccountBackupStep5 extends PureComponent {

<View style={styles.seedPhraseWrapper}>
<View style={styles.colLeft}>
{confirmedWords.slice(0, 6).map(({ word }, i) => this.renderWordBox(word, i))}
{confirmedWords.slice(0, half).map(({ word }, i) => this.renderWordBox(word, i))}
</View>
<View style={styles.colRight}>
{confirmedWords.slice(-6).map(({ word }, i) => this.renderWordBox(word, i + 6))}
{confirmedWords
.slice(-half)
.map(({ word }, i) => this.renderWordBox(word, i + half))}
</View>
</View>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ exports[`ManualBackupStep1 should render correctly 1`] = `
"borderRadius": 8,
"borderWidth": 1,
"flexDirection": "row",
"height": 275,
"marginBottom": 64,
"minHeight": 275,
}
}
>
Expand Down
69 changes: 37 additions & 32 deletions app/components/Views/ManualBackupStep1/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ const styles = StyleSheet.create({
borderColor: colors.grey100,
borderWidth: 1,
marginBottom: 64,
height: 275
minHeight: 275
},
wordColumn: {
flex: 1,
Expand Down Expand Up @@ -363,40 +363,45 @@ export default class ManualBackupStep1 extends PureComponent {
);
}

renderSeedphraseView = () => (
<ActionView
confirmTestID={'manual-backup-step-1-continue-button'}
confirmText={strings('manual_backup_step_1.continue')}
onConfirmPress={this.goNext}
confirmDisabled={this.state.seedPhraseHidden}
showCancelButton={false}
confirmButtonMode={'confirm'}
>
<View style={styles.wrapper} testID={'manual_backup_step_1-screen'}>
<Text style={styles.action}>{strings('manual_backup_step_1.action')}</Text>
<View style={styles.infoWrapper}>
<Text style={styles.info}>{strings('manual_backup_step_1.info')}</Text>
</View>
<View style={styles.seedPhraseWrapper}>
<View style={styles.wordColumn}>
{this.words.slice(0, 6).map((word, i) => (
<View key={`word_${i}`} style={styles.wordWrapper}>
<Text style={styles.word}>{`${i + 1}. ${word}`}</Text>
</View>
))}
renderSeedphraseView = () => {
const words = this.words || [];
Copy link
Contributor Author

@rickycodes rickycodes Nov 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

falling back to array here because this component does not have a constructor that defines this.words

const wordLength = words.length;
const half = wordLength / 2 || 6;
return (
<ActionView
confirmTestID={'manual-backup-step-1-continue-button'}
confirmText={strings('manual_backup_step_1.continue')}
onConfirmPress={this.goNext}
confirmDisabled={this.state.seedPhraseHidden}
showCancelButton={false}
confirmButtonMode={'confirm'}
>
<View style={styles.wrapper} testID={'manual_backup_step_1-screen'}>
<Text style={styles.action}>{strings('manual_backup_step_1.action')}</Text>
<View style={styles.infoWrapper}>
<Text style={styles.info}>{strings('manual_backup_step_1.info')}</Text>
</View>
<View style={styles.wordColumn}>
{this.words.slice(-6).map((word, i) => (
<View key={`word_${i}`} style={styles.wordWrapper}>
<Text style={styles.word}>{`${i + 7}. ${word}`}</Text>
</View>
))}
<View style={styles.seedPhraseWrapper}>
<View style={styles.wordColumn}>
{this.words.slice(0, half).map((word, i) => (
<View key={`word_${i}`} style={styles.wordWrapper}>
<Text style={styles.word}>{`${i + 1}. ${word}`}</Text>
</View>
))}
</View>
<View style={styles.wordColumn}>
{this.words.slice(-half).map((word, i) => (
<View key={`word_${i}`} style={styles.wordWrapper}>
<Text style={styles.word}>{`${i + (half + 1)}. ${word}`}</Text>
</View>
))}
</View>
{this.state.seedPhraseHidden && this.renderSeedPhraseConcealer()}
</View>
{this.state.seedPhraseHidden && this.renderSeedPhraseConcealer()}
</View>
</View>
</ActionView>
);
</ActionView>
);
};

render() {
const { ready, currentStep, view } = this.state;
Expand Down
20 changes: 15 additions & 5 deletions app/components/Views/ManualBackupStep2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,22 @@ class ManualBackupStep2 extends PureComponent {
}

state = {
confirmedWords: Array(12).fill({ word: undefined, originalPosition: undefined }),
confirmedWords: [],
wordsDict: {},
currentIndex: 0,
seedPhraseReady: false,
currentStep: 2
};

componentDidMount = () => {
this.createWordsDictionary();
const { navigation } = this.props;
const words = navigation.getParam('words', []);
this.setState(
{
confirmedWords: Array(words.length).fill({ word: undefined, originalPosition: undefined })
},
this.createWordsDictionary
);
};

createWordsDictionary = () => {
Expand Down Expand Up @@ -253,7 +260,8 @@ class ManualBackupStep2 extends PureComponent {

validateWords = () => {
const words = this.props.navigation.getParam('words', []);
const confirmedWords = this.state.confirmedWords.map(confirmedWord => confirmedWord.word);
const { confirmedWords: wordMap } = this.state;
const confirmedWords = wordMap.map(confirmedWord => confirmedWord.word);
if (words.join('') === confirmedWords.join('')) {
return true;
}
Expand Down Expand Up @@ -316,6 +324,8 @@ class ManualBackupStep2 extends PureComponent {

render = () => {
const { confirmedWords, seedPhraseReady } = this.state;
const wordLength = confirmedWords.length;
const half = wordLength / 2;
return (
<SafeAreaView style={styles.mainWrapper}>
<View style={styles.onBoardingWrapper}>
Expand Down Expand Up @@ -343,10 +353,10 @@ class ManualBackupStep2 extends PureComponent {
]}
>
<View style={styles.colLeft}>
{confirmedWords.slice(0, 6).map(({ word }, i) => this.renderWordBox(word, i))}
{confirmedWords.slice(0, half).map(({ word }, i) => this.renderWordBox(word, i))}
</View>
<View style={styles.colRight}>
{confirmedWords.slice(-6).map(({ word }, i) => this.renderWordBox(word, i + 6))}
{confirmedWords.slice(-half).map(({ word }, i) => this.renderWordBox(word, i + half))}
</View>
</View>
{this.validateWords() ? this.renderSuccess() : this.renderWords()}
Expand Down