Skip to content

Commit

Permalink
New verification added
Browse files Browse the repository at this point in the history
  • Loading branch information
hsurf22 committed Aug 22, 2018
1 parent 2107f42 commit d5dfff9
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,21 @@
}
}
}


.verificationTest {
>div{

ul {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
}
}
}







Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,27 @@
<b-modal ref="verification" hide-footer centered class="bootstrap-modal-wide verification nopadding" title="Verification">
<div class="content-block">
<p class="block-title">Please enter and fill out the empty boxes below to verify your mnemonic phrase key.</p>
<div class="phrases">

<div class="verificationTest">
<div v-for="verifyItemRow in mnemonicVerificationItems" v-bind:key="verifyItemRow.key">
<p>{{verifyItemRow.num}}</p>
<ul v-for="items in verifyItemRow.data" v-bind:key="items.key">
<li v-for="item in items" v-bind:key="item.key">{{item.value}}</li>
</ul>
</div>
</div>

<!-- Old verification is hidden, so if we can use it later in the future if we need it. -->
<div class="phrases hidden">
<ul>
<li class="word" v-for="(value, index) in mnemonicValues" v-bind:key="index" v-bind:data-index="index + 1">
{{index + 1}}.<span>{{value}}</span>
<input class="hidden" type="text" name="" autocomplete="off" />
</li>
</ul>
</div>
<!-- Old verification is hidden, so if we can use it later in the future if we need it. -->

<div class="button-container">
<div v-on:click="mnemonicDoneModalOpen" class="verify-button large-round-button-green-filled">
Verify
Expand All @@ -26,41 +39,61 @@ export default {
props: ['mnemonicValues', 'mnemonicDoneModalOpen'],
data () {
return {
mnemonicVerificationItems: [
[
{ value: '', correctItem: false },
{ value: '', correctItem: false },
{ value: '', correctItem: false }
],
[
{ value: '', correctItem: false },
{ value: '', correctItem: false },
{ value: '', correctItem: false }
],
[
{ value: '', correctItem: false },
{ value: '', correctItem: false },
{ value: '', correctItem: false }
]
]
mnemonicVerificationItems: []
}
},
methods: {
removeElFromArray (arr, value) {
return arr.filter(function (ele) {
return ele !== value
})
},
getRandMnemonicElements (mnemonic, howMany) {
var mnemonicCount = mnemonic.length
var arr = []
while (arr.length < howMany) {
var randomnumber = Math.floor(Math.random() * mnemonicCount)
if (arr.indexOf(randomnumber) > -1) continue
arr[arr.length] = randomnumber
}
return arr.sort((a, b) => a - b)
},
shuffleArray (a) {
var j, x, i
for (i = a.length - 1; i > 0; i--) {
j = Math.floor(Math.random() * (i + 1))
x = a[i]
a[i] = a[j]
a[j] = x
}
return a
}
},
watch: {
mnemonicValues: function (mnemonicVal) {
// When mnemonic value changes, we pick 3 mnemonic values to verification.
// When "mnemonicValues" changes, reselect verification items.
mnemonicValues: function (mnemonicValArray) {
// Get 3 random "array index" for "mnemonicValues"
var randItems = this.getRandMnemonicElements(mnemonicValArray, 3)
var mnemonicCount = mnemonicVal.length
for (let c = 0; c < randItems.length; c++) {
// Remove randItems from Mnemonic Value Array
let newMnemonicValArray = this.removeElFromArray(mnemonicValArray, mnemonicValArray[randItems[c]])
var ranItems = []
while (ranItems.length < 3) {
var randomnumber = Math.floor(Math.random() * mnemonicCount) + 1
if (ranItems.indexOf(randomnumber) > -1) continue
ranItems[ranItems.length] = randomnumber
// Shuffle array
newMnemonicValArray = this.shuffleArray(newMnemonicValArray)
this.mnemonicVerificationItems[c] = {
num: randItems[c],
data: [
[{value: newMnemonicValArray[0]}, {correctItem: false}],
[{value: newMnemonicValArray[1]}, {correctItem: false}],
[{value: mnemonicValArray[randItems[c]]}, {correctItem: true}]
]
}
}
console.log(ranItems)
console.log(this.mnemonicVerificationItems)
}
}
}
Expand Down

1 comment on commit d5dfff9

@mew-bot
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please sign in to comment.