This repository has been archived by the owner on Apr 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #110 from LiskHQ/23_forging-center
Add forging center - Closes #23
- Loading branch information
Showing
12 changed files
with
522 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import moment from 'moment'; | ||
|
||
import './forging.less'; | ||
|
||
const UPDATE_INTERVAL = 20000; | ||
|
||
app.component('forging', { | ||
template: require('./forging.pug')(), | ||
bindings: { | ||
account: '=', | ||
}, | ||
controller: class forging { | ||
constructor($scope, $timeout, $peers) { | ||
this.$scope = $scope; | ||
this.$timeout = $timeout; | ||
this.$peers = $peers; | ||
|
||
this.statistics = {}; | ||
this.blocks = []; | ||
|
||
this.updateAllData(); | ||
} | ||
|
||
$onDestroy() { | ||
this.$timeout.cancel(this.timeout); | ||
} | ||
|
||
updateAllData() { | ||
this.updateDelegate(); | ||
this.updateForgedBlocks(10); | ||
|
||
this.updateForgingStats('today', moment().format('YYYY-MM-DD')); | ||
this.updateForgingStats('last24h', moment().subtract(1, 'days')); | ||
this.updateForgingStats('last7d', moment().subtract(7, 'days')); | ||
this.updateForgingStats('last30d', moment().subtract(30, 'days')); | ||
this.updateForgingStats('total', moment('2016-04-24 17:00')); | ||
} | ||
|
||
updateDelegate() { | ||
this.$peers.active.sendRequest('delegates/get', { | ||
publicKey: this.account.publicKey, | ||
}, (data) => { | ||
if (data.success) { | ||
this.delegate = data.delegate; | ||
} else { | ||
this.delegate = {}; | ||
} | ||
}); | ||
} | ||
|
||
updateForgedBlocks(limit, offset) { | ||
this.$timeout.cancel(this.timeout); | ||
|
||
this.$peers.active.sendRequest('blocks', { | ||
limit, | ||
offset: offset || 0, | ||
generatorPublicKey: this.account.publicKey, | ||
}, (data) => { | ||
if (data.success) { | ||
if (this.blocks.length === 0) { | ||
this.blocks = data.blocks; | ||
} else if (offset) { | ||
Array.prototype.push.apply(this.blocks, data.blocks); | ||
} else if (this.blocks[0].id !== data.blocks[0].id) { | ||
Array.prototype.unshift.apply(this.blocks, | ||
data.blocks.filter(block => block.timestamp > this.blocks[0].timestamp)); | ||
} | ||
this.blocksLoaded = true; | ||
this.moreBlocksExist = this.blocks.length < data.count; | ||
} | ||
|
||
this.timeout = this.$timeout(this.updateAllData.bind(this), UPDATE_INTERVAL); | ||
}); | ||
} | ||
|
||
loadMoreBlocks() { | ||
this.blocksLoaded = false; | ||
this.updateForgedBlocks(20, this.blocks.length); | ||
} | ||
|
||
updateForgingStats(key, startMoment) { | ||
this.$peers.active.sendRequest('delegates/forging/getForgedByAccount', { | ||
generatorPublicKey: this.account.publicKey, | ||
start: moment(startMoment).unix(), | ||
end: moment().unix(), | ||
}, (data) => { | ||
if (data.success) { | ||
this.statistics[key] = data.forged; | ||
} | ||
}); | ||
} | ||
}, | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
forging { | ||
md-card-content { | ||
padding: 0 0 5px; | ||
} | ||
|
||
md-card-title md-menu { | ||
margin: -8px -14px; | ||
} | ||
|
||
.pull-right { | ||
float: right; | ||
} | ||
|
||
.progress-label { | ||
right: auto; | ||
left: auto; | ||
position: absolute; | ||
font-size: 2em; | ||
margin-top: 15px; | ||
padding: 60px 90px; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
div.offline-hide | ||
div | ||
md-card.loading(ng-show='!$ctrl.delegate') | ||
md-progress-linear(md-mode='indeterminate') | ||
md-content | ||
div(layout='row', ng-if='$ctrl.delegate && !$ctrl.delegate.username') | ||
md-card(flex-100, flex-gt-xs=100, layout-align='center center', layout-padding) | ||
span.title You need to become a delegate to start forging | ||
md-button.md-raised.md-primary(disabled) Become Delegate | ||
div(layout='column', layout-gt-xs='row', ng-if='$ctrl.delegate.username') | ||
md-card(flex-gt-xs=100, layout-padding) | ||
.info-panel.info-panel-grey | ||
span.title {{$ctrl.delegate.username}} | ||
span.pull-right {{$ctrl.statistics.total | lsk | number:2 }} LSK Earned | ||
md-content(layout='column', layout-gt-xs='row', ng-if='$ctrl.delegate.username') | ||
md-card(flex-50, flex-gt-xs=25, layout-padding) | ||
.info-panel.info-panel-grey | ||
span.title Today | ||
span.pull-right {{$ctrl.statistics.today | lsk | number:2 }} LSK | ||
md-card(flex-50, flex-gt-xs=25, layout-padding) | ||
.info-panel.info-panel-grey | ||
span.title Last 24 hours | ||
span.pull-right {{$ctrl.statistics.last24h | lsk | number:2 }} LSK | ||
md-card(flex-50, flex-gt-xs=25, layout-padding) | ||
.info-panel.info-panel-grey | ||
span.title {{'Last 7 days'}} | ||
span.pull-right {{$ctrl.statistics.last7d | lsk | number:2 }} LSK | ||
md-card(flex-50, flex-gt-xs=25, layout-padding) | ||
.info-panel.info-panel-grey | ||
span.title {{'Last 30 days'}} | ||
span.pull-right {{$ctrl.statistics.last30d | lsk | number:2 }} LSK | ||
div(layout='column', layout-gt-xs='row', ng-if='$ctrl.delegate.username') | ||
md-card(flex-gt-xs=33, layout-align='center center', layout-padding) | ||
div Rank | ||
div.progress-label {{$ctrl.delegate.rate}} | ||
md-progress-circular(md-mode='determinate', value='{{101 - $ctrl.delegate.rate}}', md-diameter='200') {{$ctrl.delegate.rate}} | ||
md-card(flex-gt-xs=33, layout-align='center center', layout-padding) | ||
div Productivity | ||
div.progress-label {{$ctrl.delegate.productivity}}% | ||
md-progress-circular(md-mode='determinate', value='{{$ctrl.delegate.productivity}}', md-diameter='200') | ||
md-card(flex-gt-xs=33, layout-align='center center', layout-padding) | ||
div Approval | ||
div.progress-label {{$ctrl.delegate.approval}}% | ||
md-progress-circular(md-mode='determinate', value='{{$ctrl.delegate.approval}}', md-diameter='200') | ||
md-card(layout='column', ng-if='$ctrl.delegate.username') | ||
md-card-title | ||
md-card-title-text | ||
spa.md-title Forged Blocks | ||
span(md-position-mode='target-right target', ng-if='$ctrl.blocks.length === 0 && $ctrl.blocksLoaded') | ||
span You have not forged any blocks yet. | ||
md-menu(md-position-mode='target-right target', ng-if='$ctrl.blocks.length') | ||
md-button.md-icon-button(ng-click='$mdOpenMenu()') | ||
i.material-icons more_vert | ||
md-menu-content(width='4') | ||
md-menu-item | ||
p(ng-click='check($event)') | ||
md-checkbox#advanced.filled-in.violet(ng-model='$ctrl.showAllColumns') Show All Columns | ||
// md-menu-item | ||
p(ng-click='check($event)') | ||
md-checkbox#fulltime.filled-in.violet(ng-model='showFullTime') | ||
label(for='fulltime') Show Full Time | ||
md-card-content | ||
md-content(layout='column') | ||
md-table-container(ng-show='$ctrl.blocks.length') | ||
table(md-table, ng-table='tableBlocks', border='0', width='100%', cellpadding='0', cellspacing='0', ng-show='$ctrl.blocks.length') | ||
thead(md-head) | ||
tr(md-row) | ||
th(md-column) Block height | ||
th(md-column, ng-show='$ctrl.showAllColumns') Block Id | ||
th(md-column) Timestamp | ||
th(md-column) Total fee | ||
th(md-column) Reward | ||
tbody(md-body) | ||
tr(md-row, ng-repeat='block in $ctrl.blocks') | ||
td(md-cell data-title='tableBlocks.cols.height', sortable="'height'") {{block.height}} | ||
td(md-cell data-title='tableBlocks.cols.blockId', ng-show='$ctrl.showAllColumns') {{block.id}} | ||
td(md-cell data-title='tableBlocks.cols.timestamp', sortable="'timestamp'") | ||
span(ng-show='block.timestamp > 0') | ||
timestamp(data='block.timestamp') | ||
span(ng-show='block.timestamp == 0') - | ||
td(md-cell data-title='tableBlocks.cols.totalFee', sortable="'totalFee'") {{block.totalFee | lsk}} | ||
td(md-cell data-title='tableBlocks.cols.reward', sortable="'reward'") {{block.reward | lsk}} | ||
td.width-80(md-cell data-title="''") | ||
md-button.more(ng-show='$ctrl.moreBlocksExist', ng-disabled='!$ctrl.blocksLoaded', ng-click='$ctrl.loadMoreBlocks()') Load More | ||
.loading | ||
md-progress-linear(md-mode='indeterminate', ng-hide='$ctrl.blocksLoaded') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.