Skip to content

Commit ded865c

Browse files
committed
Daily reward issue fixed:
- removed uptime logic - removed registering account in distribution contract - added daily reward countdown - added availible for retrieval VTX amount - getreward button call getreward action instead uptime
1 parent e354ed2 commit ded865c

File tree

3 files changed

+90
-49
lines changed

3 files changed

+90
-49
lines changed

src/pages/Index.vue

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,13 @@
113113
</q-item>
114114
<q-separator color="vseparator" />
115115
<q-item>
116-
<q-item-section disabled>
117-
<q-item-label>Uptime:</q-item-label>
118-
</q-item-section>
119-
<q-item-section avatar disabled>
120-
<q-item-label>{{ identity.uptime }} days</q-item-label>
116+
<q-item-section>
117+
<div align="center" class="text-subtitle2 text-vgreen text-uppercase">
118+
<div content-style="font-size: 12px"> daily reward countdown </div>
119+
<div content-style="font-size: 24px" class="text-weight-bolder">
120+
{{ daily_reward_calculation_countdown.hours }} : {{daily_reward_calculation_countdown.minutes}} : {{daily_reward_calculation_countdown.seconds}}
121+
</div>
122+
</div>
121123
</q-item-section>
122124
</q-item>
123125
<q-separator color="vseparator" />
@@ -165,6 +167,12 @@
165167
<q-separator color="vseparator" v-if="parseFloat(status.cpu) == 0" />
166168
<q-item align="center">
167169
<q-item-section>
170+
<div align="center" class="text-subtitle2 text-uppercase">
171+
<div content-style="font-size: 12px"> available for retrieval </div>
172+
<div content-style="font-size: 24px" class="text-weight-bolder">
173+
{{identity.availble_for_retrieval}}
174+
</div>
175+
</div>
168176
<q-btn label="Retreive reward" outline rounded color="vgreen" class="q-my-xs" @click="retreiveReward()" />
169177
</q-item-section>
170178
</q-item>
@@ -605,7 +613,13 @@ export default {
605613
sortBy: 'rank',
606614
descending: false
607615
},
608-
script: ''
616+
script: '',
617+
now: '',
618+
daily_reward_calculation_countdown: {
619+
hours: '',
620+
minutes: '',
621+
seconds: ''
622+
}
609623
}
610624
},
611625
computed: {
@@ -623,14 +637,21 @@ export default {
623637
},
624638
registered_nodes: function () {
625639
return this.$store.getters.getRegisteredNodes
640+
},
641+
daily_reward_next_calculation: function () {
642+
return this.$store.getters.getDailyRewardNextCalculation
626643
}
627644
},
628645
mounted () {
646+
// to load countdown faster call getRewardHistoryData firstly
647+
this.$configManager.getRewardHistoryData()
648+
this.$configManager.getAvailbleForRetrieval(this.identity.accountName)
649+
this.int1 = setInterval(() => this.updateNow(), 1000)
650+
this.int2 = setInterval(() => this.updateDailyRewardCountdown(), 1000)
651+
this.int3 = setInterval(() => this.$configManager.getAvailbleForRetrieval(this.identity.accountName), 15000)
629652
this.version = this.$utils.getVersion()
630-
this.$configManager.accountAdded(this.identity.accountName)
631653
this.$configManager.accountRegistered(this.identity.accountName)
632654
this.$configManager.accountRun(this.identity.accountName)
633-
this.$configManager.getUserUptime(this.identity.accountName)
634655
// TODO: not implemented yet
635656
this.$store.commit('setEarned', '0.0000')
636657
this.$store.state.status.time = this.$utils.getTime()
@@ -665,8 +686,30 @@ export default {
665686
// clearInterval(this.m4)
666687
clearInterval(this.m5)
667688
clearInterval(this.m6)
689+
clearInterval(this.m7)
690+
clearInterval(this.int1)
691+
clearInterval(this.int2)
692+
clearInterval(this.int3)
668693
},
669694
methods: {
695+
updateNow () {
696+
this.now = Math.round(new Date().getTime() / 1000)
697+
},
698+
updateDailyRewardCountdown () {
699+
let timeDelta = this.daily_reward_next_calculation > this.now ? this.daily_reward_next_calculation - this.now : 0
700+
let hours = Math.floor(timeDelta / (60 * 60))
701+
let minutes = Math.floor((timeDelta - hours * 60 * 60) / 60)
702+
let seconds = timeDelta - hours * 60 * 60 - minutes * 60
703+
704+
function timeUnitToStr (unit) {
705+
return unit < 10 ? '0' + unit : unit.toString()
706+
}
707+
this.daily_reward_calculation_countdown = {
708+
hours: timeUnitToStr(hours),
709+
minutes: timeUnitToStr(minutes),
710+
seconds: timeUnitToStr(seconds)
711+
}
712+
},
670713
getInstallScript () {
671714
this.script = require('../assets/install.sh').default // eslint-disable-line global-require
672715
},
@@ -695,6 +738,7 @@ export default {
695738
this.voting_list = []
696739
this.getInfoRare()
697740
this.getInfoOften()
741+
this.$configManager.getRewardHistoryData()
698742
},
699743
getInfoRare () {
700744
this.getListOfNodes()
@@ -759,7 +803,6 @@ export default {
759803
.retreiveReward(this.identity.accountName)
760804
.then(() => {
761805
setTimeout(() => this.getInfoOften(), 3000)
762-
setTimeout(() => this.$configManager.getUserUptime(this.identity.accountName), 3000)
763806
})
764807
.catch(error => {
765808
throw new Error(error)

src/store/index.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ function initialState () {
1515
method: '',
1616
identity: {
1717
voted_i: [],
18-
voted_for: []
18+
voted_for: [],
19+
availble_for_retrieval: '0.0000 VTX'
1920
},
2021
status: {
2122
accountAdded: false,
@@ -25,7 +26,8 @@ function initialState () {
2526
cpu: '',
2627
net: ''
2728
},
28-
registered_nodes: []
29+
registered_nodes: [],
30+
daily_reward_next_calculation: 0
2931
}
3032
}
3133

@@ -37,7 +39,8 @@ const store = new Vuex.Store({
3739
getMethod: state => state.method,
3840
getIdentity: state => state.identity,
3941
getStatus: state => state.status,
40-
getRegisteredNodes: state => state.registered_nodes
42+
getRegisteredNodes: state => state.registered_nodes,
43+
getDailyRewardNextCalculation: state => state.daily_reward_next_calculation
4144
},
4245
mutations: {
4346
logout: state => {
@@ -67,12 +70,15 @@ const store = new Vuex.Store({
6770
setTotalRanks: (state, total) => {
6871
state.identity.totalRanks = total
6972
},
70-
setUptime: (state, uptime) => {
71-
state.identity.uptime = uptime
73+
setDailyRewardNextCalculation: (state, timestamp) => {
74+
state.daily_reward_next_calculation = timestamp
7275
},
7376
setEarned: (state, earned) => {
7477
state.identity.earned = earned
7578
},
79+
setAvailbleForRetrieval: (state, amount) => {
80+
state.identity.availble_for_retrieval = amount
81+
},
7682
setVotedI: (state, data) => {
7783
state.identity.voted_i = data
7884
},

src/util/configManager.js

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -95,22 +95,6 @@ function logout () {
9595
})
9696
}
9797

98-
async function accountAdded (accountName) {
99-
try {
100-
const result = await Vue.prototype.$rpc.getTable('vdexdposvote', 'vdexdposvote', 'producers')
101-
let nodeStats = result.find(row => row.account === accountName)
102-
if (nodeStats) {
103-
store.commit('setAccountAdded', true)
104-
} else {
105-
userResult('Account: ' + accountName + ' is not added to the distribution contract. Please Add it.')
106-
store.commit('setAccountAdded', false)
107-
}
108-
} catch (error) {
109-
userError(error, 'Account add status check')
110-
throw error
111-
}
112-
}
113-
11498
async function accountRegistered (accountName) {
11599
try {
116100
const result = await Vue.prototype.$rpc.getTable('vdexdposvote', 'vdexdposvote', 'producers')
@@ -137,7 +121,7 @@ async function accountRun (accountName) {
137121
userResult(
138122
'Account: ' +
139123
accountName +
140-
' is not initialized for getting the reward in the distribution contract. Please Init it by clicking the Run button.'
124+
' is not initialized for getting the reward in the voting contract. Please Init it by clicking the Run button.'
141125
)
142126
store.commit('setAccountRun', false)
143127
}
@@ -147,17 +131,28 @@ async function accountRun (accountName) {
147131
}
148132
}
149133

150-
async function getUserUptime (accountName) {
134+
async function getRewardHistoryData () {
151135
try {
152-
const result = await Vue.prototype.$rpc.getTable('vtxdistribut', 'vtxdistribut', 'uptimes')
153-
let nodeStats = result.find(row => row.account === accountName)
154-
if (nodeStats) {
155-
store.commit('setUptime', Math.floor((store.state.status.time - nodeStats.last_timestamp) / 86400))
156-
} else {
157-
store.commit('setUptime', 0)
158-
}
136+
const result = await Vue.prototype.$rpc.getTable('vtxdistribut', 'vtxdistribut', 'rewardhistor')
137+
let dailyRewardData = result.find(row => row.reward_id === 1)
138+
let dailyRewardLastCalculation = dailyRewardData.last_timestamp
139+
const rewardRules = await Vue.prototype.$rpc.getTable('vtxdistribut', 'vtxdistribut', 'rewards')
140+
let dailyRewardRules = rewardRules.find(row => row.reward_id === 1)
141+
let dailyRewardPeriod = dailyRewardRules.reward_period
142+
let dailyRewardNextCalculation = dailyRewardLastCalculation && dailyRewardPeriod ? dailyRewardLastCalculation + dailyRewardPeriod : 0
143+
store.commit('setDailyRewardNextCalculation', dailyRewardNextCalculation)
144+
} catch (error) {
145+
userError(error, 'Get last reward calculation timestaml')
146+
}
147+
}
148+
149+
async function getAvailbleForRetrieval (accountName) {
150+
try {
151+
const result = await Vue.prototype.$rpc.getTable('vtxdistribut', accountName, 'nodereward')
152+
let amount = result.map(item => parseFloat(item.amount)).reduce((a, b) => a + b, 0).toFixed(4)
153+
store.commit('setAvailbleForRetrieval', `${amount} VTX`)
159154
} catch (error) {
160-
userError(error, 'Get uptime action')
155+
userError(error, 'Get availble for retrieval')
161156
}
162157
}
163158

@@ -281,20 +276,17 @@ async function registerNode (accountName, options) {
281276
)
282277
}
283278
async function retreiveReward (accountName) {
284-
var jobs = new Int32Array()
285-
jobs[0] = 1
286-
jobs[1] = 2
287279
await Vue.prototype.$eos.transaction(
288280
'vtxdistribut',
289-
'uptime',
281+
'getreward',
290282
accountName,
291283
{
292-
account: accountName,
293-
job_ids: jobs
284+
node: accountName
294285
},
295286
"Transaction 'Retreive reward' executed successfully!",
296287
'Retreive reward action'
297288
)
289+
await getAvailbleForRetrieval()
298290
}
299291

300292
async function vote (votingList, accountName) {
@@ -405,10 +397,8 @@ export {
405397
configStore,
406398
hasConfig,
407399
logout,
408-
accountAdded,
409400
accountRegistered,
410401
accountRun,
411-
getUserUptime,
412402
getUserRank,
413403
getUserBalance,
414404
getUserResources,
@@ -418,5 +408,7 @@ export {
418408
registerNode,
419409
retreiveReward,
420410
vote,
421-
login
411+
login,
412+
getRewardHistoryData,
413+
getAvailbleForRetrieval
422414
}

0 commit comments

Comments
 (0)