Skip to content

Commit

Permalink
Merge pull request #584 from pqv199x/fix-website-tele
Browse files Browse the repository at this point in the history
Fix update canidate infor issue, calculating est reward issue
  • Loading branch information
thanhson1085 authored Apr 2, 2019
2 parents 8778870 + 9aa3f94 commit b0f43c6
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 26 deletions.
9 changes: 2 additions & 7 deletions apis/candidates.js
Original file line number Diff line number Diff line change
Expand Up @@ -741,13 +741,8 @@ router.put('/update', [
set['dataCenter.location'] = body.dcLocation
}

if (body.website) {
set['socials.website'] = body.website
}

if (body.telegram) {
set['socials.telegram'] = body.telegram
}
set['socials.website'] = body.website || ''
set['socials.telegram'] = body.telegram || ''

const address = await web3.eth.accounts.recover(message, signedMessage)

Expand Down
15 changes: 9 additions & 6 deletions apis/voters.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,17 +373,20 @@ router.get('/calculatingReward1Day', [], async (req, res, next) => {
const capacity = new BigNumber(candidate.capacity).div(10 ** 18)
const totalReward = new BigNumber(config.get('blockchain.reward'))
// get total signers in latest epoch
const totalSigners = await axios.post(
urljoin(config.get('tomoscanUrl'), `api/expose/totalSignNumber/${epoch}`)
)
let totalSigners
if (epoch) {
totalSigners = await axios.post(
urljoin(config.get('tomoscanUrl'), `api/expose/totalSignNumber/${epoch}`)
)
}

if (totalSigners.data && totalSigners.data.totalSignNumber) {
if (totalSigners && totalSigners.data && totalSigners.data.totalSignNumber) {
// calculate devided reward
const masternodeReward = totalReward.multipliedBy(signNumber).dividedBy(totalSigners.data.totalSignNumber)

// calculate voter reward 1 day
const estimateReward = masternodeReward
.multipliedBy((amount.div(0.5))).div(capacity.plus(amount)).multipliedBy(await epochIn1Day) || 'N/A'
const estimateReward = masternodeReward.multipliedBy(0.5)
.multipliedBy(amount).div(capacity.plus(amount)).multipliedBy(await epochIn1Day) || 'N/A'
return res.send(estimateReward.toString(10))
}
return res.send('N/A')
Expand Down
26 changes: 15 additions & 11 deletions app/components/candidates/Update.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@
<b-form-input
v-model="website"
name="website-value"/>
<span
v-if="$v.website.$dirty && !$v.website.url"
class="text-danger">Not an url</span>
</b-form-group>
<b-form-group
class="col-md-6"
Expand All @@ -76,6 +79,9 @@
<b-form-input
v-model="telegram"
name="telegram-value"/>
<span
v-if="$v.telegram.$dirty && !$v.telegram.url"
class="text-danger">Not an url</span>
</b-form-group>
</div>
<div class="buttons text-right">
Expand Down Expand Up @@ -157,7 +163,8 @@ import { validationMixin } from 'vuelidate'
import {
required,
minLength,
maxLength
maxLength,
url
} from 'vuelidate/lib/validators'
import axios from 'axios'
import VueQrcode from '@chenfengyuan/vue-qrcode'
Expand Down Expand Up @@ -207,7 +214,9 @@ export default {
dcLocation: {
maxLength: maxLength(30),
minLength: minLength(2)
}
},
website: { url },
telegram: { url }
},
beforeDestroy () {
if (this.interval) {
Expand Down Expand Up @@ -240,8 +249,8 @@ export default {
self.hardware = data.hardware || 'N/A'
self.dcName = (data.dataCenter || {}).name || 'N/A'
self.dcLocation = (data.dataCenter || {}).location || 'N/A'
self.website = data.website || ''
self.telegram = data.telegram || ''
self.website = (data.socials || {}).website || ''
self.telegram = (data.socials || {}).telegram || ''
}
}
} catch (e) {
Expand Down Expand Up @@ -356,13 +365,8 @@ export default {
body.dcLocation = self.dcLocation
}
if (self.website !== '') {
body.website = self.website
}
if (self.telegram !== '') {
body.telegram = self.telegram
}
body.website = self.website
body.telegram = self.telegram
const { data } = await axios.put(
'/api/candidates/update',
Expand Down
2 changes: 2 additions & 0 deletions app/components/candidates/View.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
:key="key"
class="list-inline-item social-links__item">
<a
v-if="value !== ''"
:href="value"
target="_blank"
class="social-links__link">
<i :class="'social-links__icon tm-' + key" />
</a>
Expand Down
4 changes: 2 additions & 2 deletions app/components/voters/EstimateReward.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div
v-if="estimatedReward !== 'N/A'"
class="float-left">
Est. Daily Reward: {{ estimatedReward }}
Est. Daily Reward: {{ estimatedReward }} TOMO
</div>
</template>
<script>
Expand Down Expand Up @@ -43,7 +43,7 @@ export default {
const query = self.serializeQuery(params)
const { data } = await axios.get('/api/voters/calculatingReward1Day' + '?' + query)
self.estimatedReward = data !== 'N/A' ? data.toFixed(6) : data
self.estimatedReward = data !== 'N/A' ? data.toFixed(3) : data
}
}
}
Expand Down

0 comments on commit b0f43c6

Please sign in to comment.