Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

web-ui: added color effect on newest blocks (fixes #20) #25

Merged
merged 4 commits into from
Jun 17, 2018

Conversation

mario128mex
Copy link
Contributor

Problem

On latest block view, the newest blocks were hard to notice
Solution

Added a color effect on newest blocks

Result

ezgif-4-e740ffedcb

this.blocks = response;
}

private countNewestBlocks(newBlocks: Block[]) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would avoid functions with side effects as much as possible, as a example, you mutating the totalNewestBlocks, instead you can return the number of new blocks and do whatever you want with the number, think about which version would be simpler to test.

return;
}

const lastestBlockHash: string = this.latestBlock.hash;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just pass this as an argument, as a hint, the height attribute from a block is just the block number and it is unique, it should be simpler to use that instead of the block hash, again, think on simplicity to test.

const lastestBlockHash: string = this.latestBlock.hash;
let totalNewBlocks = 0;

for (let i = 0; i < newBlocks.length; i++) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A loop is error prone, use collection transformation functions instead, like map and filter, if you use the latest block height, it is simple to filter by the blocks having a higher height.

@@ -92,4 +115,8 @@ export class LatestBlocksComponent implements OnInit, OnDestroy {
age(block: Block): string {
return '';
}

isBlockRecent(index: number): boolean {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, checking this by an index is error prone, angular allows you to pass the block object as an argument to the function, on the testability side, it would be simpler to receive both arguments instead of referencing a mutable variable.

@@ -70,9 +72,30 @@ export class LatestBlocksComponent implements OnInit, OnDestroy {
}

private onBlockRetrieved(response: Block[]) {
this.countNewestBlocks(response);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I would do is to get the list of new blocks and store them in a mutable variable, something like this.newBlocks = this.getNewBlocks(this.blocks || [], response) with a function like private getNewBlocks(currentBlocks: Block[], latestBlocks: Block[]): Block[].

This might give the effect that the initial load will paint all blocks which should be acceptable.

@@ -70,9 +72,30 @@ export class LatestBlocksComponent implements OnInit, OnDestroy {
}

private onBlockRetrieved(response: Block[]) {
this.countNewestBlocks(response);
this.latestBlock = response[0];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be required at all.

@@ -26,6 +26,8 @@ import { ErrorService } from '../../services/error.service';
export class LatestBlocksComponent implements OnInit, OnDestroy {

blocks: Block[];
private totalNewestBlocks: number;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would define private newBlocks: Block[]; instead.

@@ -26,6 +26,8 @@ import { ErrorService } from '../../services/error.service';
export class LatestBlocksComponent implements OnInit, OnDestroy {

blocks: Block[];
private totalNewestBlocks: number;
private latestBlock: Block;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be required at all.

@@ -26,7 +26,7 @@ <h4>{{'message.loadingLatestBlocks' | translate}}</h4>
</thead>

<tbody>
<tr *ngFor="let item of blocks">
<tr *ngFor="let item of blocks; let i = index" [ngClass]="{ 'latest-block': isBlockRecent(i) }">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The index is not required, you can just call isNewBlock(item) where that function returns true if the item hash or height exists in the newBlocks variable, this can be done easily by the filtering over it.

}

this.totalNewestBlocks = totalNewBlocks;
return newBlocks.filter(newBlock => newBlock.height > this.blocks[0].height);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are assuming that the blocks are in certain order, while today that's true, we don't know if it would be tomorrow. you can easily get the current latest block height and compare against that.

this.blocks = response;
}

private countNewestBlocks(newBlocks: Block[]) {
private getNewBlocks(newBlocks: Block[]): Block[] {
if (!this.blocks) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, this is harder to test than just passing the required argument to the function, please stop using global state.

this.blocks = response;
}

private countNewestBlocks(newBlocks: Block[]) {
private getNewBlocks(newBlocks: Block[]): Block[] {
if (!this.blocks) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in fact, if you receive the latest block height as an argument, this conditional will be useless.

@@ -26,6 +26,7 @@ import { ErrorService } from '../../services/error.service';
export class LatestBlocksComponent implements OnInit, OnDestroy {

blocks: Block[];
private latestBlockHeight: number;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please, initialize this to 0 or -1 to avoid undefined issues.

@@ -70,6 +71,7 @@ export class LatestBlocksComponent implements OnInit, OnDestroy {
}

private onBlockRetrieved(response: Block[]) {
this.latestBlockHeight = this.blocks ? this.blocks[0].height : 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please just get the maximum instead.

@AlexITC AlexITC merged commit 2833ba1 into wiringbits:develop Jun 17, 2018
@mario128mex mario128mex deleted the issue-20 branch June 18, 2018 18:02
AlexITC added a commit that referenced this pull request Oct 1, 2018
- A message is displayed when the transaction list is not available.
- The transaction list is loaded after the block data.
- When the paginated transactions aren't available, the transaction
  list from the block data is displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants