Skip to content
This repository has been archived by the owner on Jan 14, 2022. It is now read-only.

Commit

Permalink
Merge pull request #907 from LiskHQ/905-delegate-page
Browse files Browse the repository at this point in the history
Fix the delegate page - Closes #905
  • Loading branch information
Michal Tuleja authored May 17, 2019
2 parents df968a0 + 74a15ce commit d2d2617
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 87 deletions.
20 changes: 20 additions & 0 deletions features/delegate.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Feature: Delegate page
Scenario: should show title, summary
Given I'm on page "/delegate/537318935439898807L"
Then I should see "Delegate summary" in "h1" html element
And I should see "Home Delegate 537318935439898807L" in "breadcrumb" element
And I should see table "summary" containing:
| Name | genesis_17 |
| Address | 537318935439898807L |
| Uptime | /\d{1,3}(\.\d\d)?%/ |
| Rank / Status | 50 / Active |
| Approval | /\d{1,3}(\.\d\d)?%/ |
| Vote weight | /99(,\d{3})*.\d{1,8} LSK/ |
| Forged | /1,\d{3}.\d{8} LSK/ |
| Blocks | /\d+ \(\d+ missed\)/ |

Scenario: should link address to address page
Given I'm on page "/delegate/4401082358022424760L"
And I click link on row no. 2 cell no. 2 of "summary" table
Then I should be on page "/address/4401082358022424760L"

54 changes: 2 additions & 52 deletions src/components/delegate/delegate.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import AppDelegate from './delegate.module';
import template from './delegate.html';

const DelegateConstructor = function ($rootScope, $stateParams,
$location, $http, addressTxs, $state) {
$location, $http, $state) {
const vm = this;

$rootScope.breadCrumb = { address: $stateParams.delegateId };
Expand All @@ -30,11 +30,8 @@ const DelegateConstructor = function ($rootScope, $stateParams,
}).then((resp) => {
if (resp.data.success) {
vm.address = resp.data;
vm.getVotes(vm.address.publicKey);

if (vm.address.delegate) {
vm.getVoters(vm.address.publicKey);
} else {
if (!vm.address.delegate) {
$state.go('address', { address: $stateParams.delegateId });
}
} else {
Expand All @@ -45,54 +42,7 @@ const DelegateConstructor = function ($rootScope, $stateParams,
});
};

vm.getVotes = (publicKey) => {
$http.get('/api/getVotes', { params: { publicKey } }).then((resp) => {
if (resp.data.success) {
vm.address.votes = resp.data.votes;
}
});
};

vm.getVoters = (publicKey) => {
$http.get('/api/getVoters', { params: { publicKey } }).then((resp) => {
if (resp.data.success) {
vm.address.voters = resp.data.voters;
vm.address.votersMeta = resp.data.meta;
vm.address.votersCount = vm.address.votersMeta.count;
}
});
};

vm.loadMoreVoters = () => {
const limit = vm.address.votersMeta.limit;
const offset = vm.address.votersMeta.offset + limit;

$http.get('/api/getVoters', { params: { publicKey: vm.address.publicKey, limit, offset } }).then((resp) => {
if (resp.data.success) {
for (let i = 0; i < resp.data.voters.length; i++) {
if (vm.address.voters.indexOf(resp.data.voters[i]) < 0) {
vm.address.voters.push(resp.data.voters[i]);
}
}

vm.address.votersMeta = resp.data.meta;
vm.address.votersCount = vm.address.votersMeta.count;
}
});
};

vm.address = {
address: $stateParams.delegateId,
};

// Sets the filter for which transactions to display
vm.filterTxs = (direction) => {
vm.direction = direction;
vm.txs = addressTxs({ address: $stateParams.delegateId, direction });
};

vm.getAddress();
vm.txs = addressTxs({ address: $stateParams.delegateId });
};

AppDelegate.component('delegate', {
Expand Down
40 changes: 5 additions & 35 deletions src/components/delegate/delegate.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@
<section>
<h1>Delegate summary</h1>

<div class="row horizontal-padding-xs horizontal-padding-s horizontal-padding-m horizontal-padding-l">
<p>Visit the <a href="/address/{{ vm.address.delegate.address }}">address page</a> to see more delegate details.</p>
</div>

<div class="delegate">
<div class="row horizontal-padding-xs horizontal-padding-s horizontal-padding-m horizontal-padding-l">
<div class="row">
<div class="col-md-7 col-lg-8">
<div class="table-responsive">
<table class="table summary">
Expand Down Expand Up @@ -66,39 +70,5 @@ <h1>Delegate summary</h1>
</div>
</div>
</div>

<div class="row horizontal-padding-xs horizontal-padding-s horizontal-padding-m horizontal-padding-l">
<uib-tabset class="voters-votes">
<uib-tab>
<uib-tab-heading class="transactions-tab">
<h2>Voters <small>{{vm.address.votersCount}}</small></h2>
</uib-tab-heading>

<div class="delegate-vote" data-ng-if="vm.address.voters">
<div class="row horizontal-padding-xs horizontal-padding-s horizontal-padding-m horizontal-padding-l">
<div class="col-md-12 voters">
<span data-ng-repeat='voter in vm.address.voters'>
<span>
<a data-account-href="voter" data-type="voter" class="voter-link">{{voter | votes}}</a>
<span class="text-muted">&bull;</span>
</span>
<span data-ng-if="$last && vm.address.voters.length < vm.address.votersCount">
<span role="button" class="load-more" data-ng-click="vm.loadMoreVoters()"><b>Load more...</b></span>
</span>
</span>
</div>
</div>
</div>
</uib-tab>

<uib-tab>
<uib-tab-heading class="blocks-tab">
<h2>Votes <small>{{vm.address.votes.length}}</small></h2>
</uib-tab-heading>

<votes data-votes="vm.address.votes"></votes>
</uib-tab>
</uib-tabset>
</div>
</div>
</section>

0 comments on commit d2d2617

Please sign in to comment.