Skip to content

Commit

Permalink
Merge pull request #386 from pqv199x/issue-383-377
Browse files Browse the repository at this point in the history
Optimize update candidate's information workflow/ Update information by ledger
  • Loading branch information
thanhson1085 authored Dec 19, 2018
2 parents 71ac75e + de20f77 commit d261e03
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 46 deletions.
2 changes: 1 addition & 1 deletion apis/candidates.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ router.post('/:candidate/generateMessage', async function (req, res, next) {
}

const message = '[Tomomaster ' + (new Date().toLocaleString().replace(/['"]+/g, '')) + ']' +
' I am the candidate ' + '[' + candidate + ']'
' I am the owner of candidate ' + '[' + candidate + ']'
const id = uuidv4()

// update id, status
Expand Down
18 changes: 18 additions & 0 deletions app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,24 @@ Vue.prototype.sendSignedTransaction = async function (txParams, signature) {
return rs
}

Vue.prototype.signMessage = async function (message) {
try {
const path = localStorage.get('hdDerivationPath')
const result = await Vue.prototype.appEth.signPersonalMessage(
path,
Buffer.from(message).toString('hex')
)
let v = result['v'] - 27
v = v.toString(16)
if (v.length < 2) {
v = '0' + v
}
return '0x' + result['r'] + result['s'] + v
} catch (error) {
console.log(error)
}
}

new Vue({ // eslint-disable-line no-new
el: '#app',
store,
Expand Down
63 changes: 18 additions & 45 deletions app/components/candidates/Update.vue
Original file line number Diff line number Diff line change
Expand Up @@ -109,43 +109,6 @@
class="text-danger"><b>{{ signHashError }}</b></span>
</div>
</div>
<div
v-if="provider === 'metamask'">
<strong>Copy message below and sign the message using
<a
href="https://www.mycrypto.com/signmsg.html"
style="color: #3498db">MyCrypto</a>
or <a
href="https://www.myetherwallet.com/signmsg.html"
style="color: #3498db">MyEtherWallet</a>
</strong>
<span style="font-size: 12px">( Click to copy )</span>
<label style="margin-top: 5px">
<div>
<textarea
ref="text"
:value="message"
class="sign-message"
type="text"
readonly
cols="100"
rows="2"
style="width: 100%"
@click="copyTextArea"/>
</div>
</label>
<div>
<input
v-model="signHash"
class="form-control"
type="text"
autocomplete="false"
style="box-sizing: border-box; width: 100%"
placeholder="Enter the message signature hash">
<span
class="text-danger">{{ signHashError }}</span>
</div>
</div>
</div>
</div>
<div
Expand Down Expand Up @@ -283,20 +246,30 @@ export default {
update: async function () {
let self = this
try {
if (self.provider === 'metamask' && self.signHash === '') {
self.signHashError = 'This field is required'
return false
}
self.loading = true
if (self.provider === 'custom') {
switch (self.provider) {
case 'custom':
self.signHash = await self.web3.eth.sign(self.message, self.account)
break
case 'metamask':
self.signHash = await self.web3.eth.personal.sign(self.message, self.account)
break
case 'ledger':
self.signHash = await self.signMessage(self.message)
break
default:
self.loading = false
self.$toasted.show(`An error occurred while updating.`, {
type: 'error'
})
break
}
// calling update api
await self.updateCandidateInfo()
} catch (e) {
console.log(e)
self.loading = false
self.$toasted.show(`An error occurred while updating. ${String(e)}`, {
self.$toasted.show(`An error occurred while updating.`, {
type: 'error'
})
}
Expand Down Expand Up @@ -384,7 +357,7 @@ export default {
} catch (e) {
console.log(e)
self.loading = false
self.$toasted.show(`An error occurred while updating. ${String(e)}`, {
self.$toasted.show(`An error occurred while updating.`, {
type: 'error'
})
}
Expand All @@ -403,7 +376,7 @@ export default {
}
} catch (e) {
console.log(e)
self.$toasted.show(`An error occurred while updating. ${String(e)}`, {
self.$toasted.show(`An error occurred while updating.`, {
type: 'error'
})
}
Expand Down

0 comments on commit d261e03

Please sign in to comment.