forked from bitpay/bitcore
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(insight): begin building out blocks view, related components
- Loading branch information
Showing
42 changed files
with
624 additions
and
124 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export type IBlock = { | ||
chain: string; | ||
network: string; | ||
height: number; | ||
hash: string; | ||
version: number; | ||
merkleRoot: string; | ||
time: Date; | ||
timeNormalized: Date; | ||
nonce: number; | ||
previousBlockHash: string; | ||
nextBlockHash: string; | ||
transactionCount: number; | ||
size: number; | ||
bits: number; | ||
reward: number; | ||
processed: boolean; | ||
}; |
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,12 @@ | ||
const enum Direction { | ||
ascending = 1, | ||
descending = -1 | ||
} | ||
|
||
export type StreamingFindOptions<T> = Partial<{ | ||
paging: keyof T; | ||
since: T[keyof T]; | ||
sort: any; | ||
direction: Direction; | ||
limit: number; | ||
}>; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,25 @@ | ||
<ion-app> | ||
<ion-split-pane when="lg"> | ||
<ion-menu> | ||
<ion-content> | ||
<ion-list> | ||
<ion-menu-toggle auto-hide="false" *ngFor="let p of appPages"> | ||
<ion-item [routerDirection]="'root'" [routerLink]="[p.url]"> | ||
<ion-label> | ||
{{ p.title }} | ||
</ion-label> | ||
</ion-item> | ||
</ion-menu-toggle> | ||
</ion-list> | ||
</ion-content> | ||
</ion-menu> | ||
<ion-router-outlet main></ion-router-outlet> | ||
</ion-split-pane> | ||
</ion-app> | ||
<ion-split-pane when="lg"> | ||
<ion-menu> | ||
<ion-content | ||
class="dark-theme" | ||
padding | ||
> | ||
<ion-list> | ||
<ion-menu-toggle | ||
auto-hide="false" | ||
*ngFor="let p of appPages" | ||
> | ||
<ion-item | ||
[routerDirection]="'root'" | ||
[routerLink]="[p.url]" | ||
> | ||
<ion-label>{{ p.title }}</ion-label> | ||
</ion-item> | ||
</ion-menu-toggle> | ||
</ion-list> | ||
</ion-content> | ||
</ion-menu> | ||
<ion-router-outlet main></ion-router-outlet> | ||
</ion-split-pane> | ||
</ion-app> |
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,5 @@ | ||
.dark-theme { | ||
--ion-background-color: #3d3d4d; | ||
--ion-item-background-color-active: lighten(--ion-background-color, 15%); | ||
--ion-text-color: rgba(255, 255, 255, 0.9); | ||
} |
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
9 changes: 6 additions & 3 deletions
9
packages/insight/src/app/blocks/block-list/block-list.component.html
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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
<p> | ||
block-list works! | ||
</p> | ||
<app-block | ||
*ngFor="let block of block$ | async as blocks; index as i; first as isFirst" | ||
[block]="block" | ||
(click)="goToBlock(block)" | ||
[displayValueIn]="displayValueIn" | ||
></app-block> |
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,3 @@ | ||
app-block { | ||
cursor: pointer; | ||
} |
47 changes: 30 additions & 17 deletions
47
packages/insight/src/app/blocks/block-list/block-list.component.ts
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 |
---|---|---|
@@ -1,29 +1,42 @@ | ||
import { Component, Input, OnDestroy, OnInit } from '@angular/core'; | ||
import { | ||
ChangeDetectionStrategy, | ||
Component, | ||
Input, | ||
OnInit | ||
} from '@angular/core'; | ||
import * as equal from 'fast-deep-equal'; | ||
import { combineLatest, Observable } from 'rxjs'; | ||
import { distinctUntilChanged, switchMap, tap } from 'rxjs/operators'; | ||
import { ApiService } from '../../services/api/api.service'; | ||
import { IBlock } from '../../types/bitcore-node'; | ||
import { Network, Ticker } from '../../types/configuration'; | ||
import { IBlock, StreamingFindOptions } from '../../types/bitcore-node'; | ||
import { Chain } from '../../types/configuration'; | ||
|
||
@Component({ | ||
selector: 'app-block-list', | ||
templateUrl: './block-list.component.html', | ||
styleUrls: ['./block-list.component.scss'] | ||
styleUrls: ['./block-list.component.scss'], | ||
changeDetection: ChangeDetectionStrategy.OnPush | ||
}) | ||
export class BlockListComponent { | ||
export class BlockListComponent implements OnInit { | ||
@Input() | ||
public ticker: Ticker; | ||
chain: Observable<Chain>; | ||
@Input() | ||
public network: Network; | ||
query: Observable<StreamingFindOptions<IBlock>>; | ||
@Input() | ||
public blocks: number; | ||
@Input() | ||
public paging: keyof IBlock = 'height'; | ||
|
||
public blockStream = this.apiService.streamBlocks( | ||
{ ticker: this.ticker, network: this.network }, | ||
{ | ||
paging: this.paging | ||
} | ||
); | ||
displayValueIn = 'BCH'; | ||
block$: Observable<IBlock>; | ||
|
||
constructor(private apiService: ApiService) {} | ||
ngOnInit() { | ||
this.block$ = combineLatest(this.chain, this.query).pipe( | ||
distinctUntilChanged((x, y) => equal(x, y)), | ||
switchMap(([chain, query]) => this.apiService.streamBlocks(chain, query)), | ||
distinctUntilChanged((x, y) => equal(x, y)) | ||
); | ||
} | ||
|
||
goToBlock(block: IBlock) { | ||
// tslint:disable-next-line:no-console | ||
console.log('TODO: navigate to block', block.hash); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
packages/insight/src/app/blocks/block/block.component.html
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,59 @@ | ||
<!-- <small>block: | ||
{{block | json}}</small> --> | ||
|
||
<div class="card"> | ||
<div class="section header"> | ||
<div class="identifiers"> | ||
<div | ||
class="height" | ||
title="The height of this block, i.e. its position in the chain." | ||
> | ||
{{block.height}} | ||
</div> | ||
<span | ||
*ngIf="!block.nextBlockHash" | ||
class="tip-tag" | ||
title="This is the latest block on the network." | ||
> | ||
Tip | ||
</span> | ||
</div> | ||
<app-date-time | ||
[value]="block.timeNormalized" | ||
class="time" | ||
> | ||
</app-date-time> | ||
</div> | ||
<div class="section body"> | ||
<div class="property"> | ||
<div class="key">Block Hash</div> | ||
<div class="value">{{block.hash}}</div> | ||
</div> | ||
<div class="property"> | ||
<span class="key">Transaction Count</span> | ||
<span | ||
class="value link" | ||
(click)="listTransactionsInBlock(block)" | ||
> | ||
{{block.transactionCount}} | ||
</span> | ||
</div> | ||
<div class="property"> | ||
<span class="key">Reward</span> | ||
<span class="value"> | ||
<app-currency-value | ||
class="reward" | ||
inAtomicUnits="{{block.reward}}" | ||
ticker="{{block.chain}}" | ||
displayAs="displayValueIn" | ||
></app-currency-value> | ||
</span> | ||
</div> | ||
</div> | ||
<div | ||
class="section details" | ||
*ngIf="!summary" | ||
> | ||
[show details] | ||
</div> | ||
</div> |
Oops, something went wrong.