@@ -206,11 +206,30 @@ class AccountBackupStep5 extends Component {
206
206
} ) ;
207
207
} ;
208
208
209
+ getIndexOfWord ( word , index , words ) {
210
+ const confirmedWordsOcurrences = this . getNumberOfOcurrences ( word , words ) ;
211
+ if ( confirmedWordsOcurrences === 1 ) {
212
+ return words . indexOf ( word ) ;
213
+ }
214
+
215
+ let currentOccurence = 0 ;
216
+
217
+ for ( let i = 0 ; i < words . length ; i ++ ) {
218
+ if ( words [ i ] === word ) {
219
+ currentOccurence ++ ;
220
+ if ( i === index && currentOccurence <= confirmedWordsOcurrences ) {
221
+ return i ;
222
+ }
223
+ }
224
+ }
225
+ return words . indexOf ( word ) ;
226
+ }
227
+
209
228
selectWord = ( word , i ) => {
210
229
const newConfirmedWords = this . state . confirmedWords . slice ( ) ;
211
230
let newIndex ;
212
- if ( newConfirmedWords . includes ( word ) ) {
213
- const matchIndex = newConfirmedWords . indexOf ( word ) ;
231
+ if ( this . isSelectedWord ( word , i ) ) {
232
+ const matchIndex = this . getIndexOfWord ( word , i , this . state . confirmedWords ) ;
214
233
newConfirmedWords [ matchIndex ] = undefined ;
215
234
newIndex = matchIndex ;
216
235
} else {
@@ -234,6 +253,37 @@ class AccountBackupStep5 extends Component {
234
253
this . setState ( { confirmedWords : newConfirmedWords , currentIndex : newIndex } ) ;
235
254
} ;
236
255
256
+ getNumberOfOcurrences ( word , words ) {
257
+ let ocurrences = 0 ;
258
+ for ( let i = 0 ; i < words . length ; i ++ ) {
259
+ words [ i ] === word && ocurrences ++ ;
260
+ }
261
+ return ocurrences ;
262
+ }
263
+
264
+ isSelectedWord ( word , index ) {
265
+ if ( ! this . state . confirmedWords . includes ( word ) ) {
266
+ return false ;
267
+ }
268
+ const totalOcurrences = this . getNumberOfOcurrences ( word , this . words ) ;
269
+ const confirmedWordsOcurrences = this . getNumberOfOcurrences ( word , this . state . confirmedWords ) ;
270
+ if ( totalOcurrences === confirmedWordsOcurrences ) {
271
+ return true ;
272
+ }
273
+
274
+ let currentOccurence = 0 ;
275
+
276
+ for ( let i = 0 ; i < this . words . length ; i ++ ) {
277
+ if ( this . words [ i ] === word ) {
278
+ currentOccurence ++ ;
279
+ if ( i === index && currentOccurence <= confirmedWordsOcurrences ) {
280
+ return true ;
281
+ }
282
+ }
283
+ }
284
+ return false ;
285
+ }
286
+
237
287
render ( ) {
238
288
return (
239
289
< SafeAreaView style = { styles . mainWrapper } >
@@ -290,9 +340,7 @@ class AccountBackupStep5 extends Component {
290
340
291
341
< View style = { styles . words } >
292
342
{ this . words . map ( ( word , i ) => {
293
- const selected = this . state . confirmedWords . includes ( word )
294
- ? styles . selectedWord
295
- : null ;
343
+ const selected = this . isSelectedWord ( word , i ) ? styles . selectedWord : null ;
296
344
const selectedText = selected ? styles . selectedWordText : null ;
297
345
return (
298
346
< TouchableOpacity
0 commit comments