Skip to content

Commit 8907572

Browse files
committed
web-ui: Allow to display raw block
1 parent da86ec4 commit 8907572

12 files changed

+151
-4
lines changed

web-ui/src/app/app-routing.module.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import { Routes, RouterModule } from '@angular/router';
44
import { HomeComponent } from './components/home/home.component';
55
import { TransactionComponent } from './components/transaction/transaction.component';
66
import { AddressDetailsComponent } from './components/address-details/address-details.component';
7-
import { BlockDetailsComponent } from './components/block-details/block-details.component';
7+
import { BlockComponent } from './components/block/block.component';
88
import { MasternodeDetailsComponent } from './components/masternode-details/masternode-details.component';
99

1010
const routes: Routes = [
1111
{ path: '', component: HomeComponent },
1212
{ path: 'addresses/:address', component: AddressDetailsComponent },
13-
{ path: 'blocks/:blockhash', component: BlockDetailsComponent },
13+
{ path: 'blocks/:query', component: BlockComponent },
1414
{ path: 'transactions/:txid', component: TransactionComponent },
1515
{ path: 'masternodes/:ip', component: MasternodeDetailsComponent },
1616
{ path: '**', redirectTo: '' }

web-ui/src/app/app.module.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ import { MasternodesComponent } from './components/masternodes/masternodes.compo
4242
import { MasternodeDetailsComponent } from './components/masternode-details/masternode-details.component';
4343
import { TransactionRawComponent } from './components/transaction-raw/transaction-raw.component';
4444
import { TransactionComponent } from './components/transaction/transaction.component';
45+
import { BlockComponent } from './components/block/block.component';
46+
import { BlockRawComponent } from './components/block-raw/block-raw.component';
4547

4648
@NgModule({
4749
declarations: [
@@ -59,7 +61,9 @@ import { TransactionComponent } from './components/transaction/transaction.compo
5961
MasternodesComponent,
6062
MasternodeDetailsComponent,
6163
TransactionRawComponent,
62-
TransactionComponent
64+
TransactionComponent,
65+
BlockComponent,
66+
BlockRawComponent
6367
],
6468
imports: [
6569
AppRoutingModule,

web-ui/src/app/components/block-details/block-details.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class BlockDetailsComponent implements OnInit {
2626
private errorService: ErrorService) { }
2727

2828
ngOnInit() {
29-
this.route.params.forEach(params => this.onBlockhash(params['blockhash']));
29+
this.route.params.forEach(params => this.onBlockhash(params['query']));
3030
}
3131

3232
private onBlockhash(blockhash: string) {

web-ui/src/app/components/block-raw/block-raw.component.css

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<div>
2+
<div [hidden]="block != null">
3+
<alert>{{'message.blockNotFound' | translate}}</alert>
4+
</div>
5+
<div *ngIf="block != null">
6+
<pre>{{block | json}}</pre>
7+
</div>
8+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { BlockRawComponent } from './block-raw.component';
4+
5+
describe('BlockRawComponent', () => {
6+
let component: BlockRawComponent;
7+
let fixture: ComponentFixture<BlockRawComponent>;
8+
9+
beforeEach(async(() => {
10+
TestBed.configureTestingModule({
11+
declarations: [ BlockRawComponent ]
12+
})
13+
.compileComponents();
14+
}));
15+
16+
beforeEach(() => {
17+
fixture = TestBed.createComponent(BlockRawComponent);
18+
component = fixture.componentInstance;
19+
fixture.detectChanges();
20+
});
21+
22+
it('should create', () => {
23+
expect(component).toBeTruthy();
24+
});
25+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { Component, OnInit } from '@angular/core';
2+
import { ActivatedRoute, Router } from '@angular/router';
3+
4+
import { TranslateService } from '@ngx-translate/core';
5+
6+
import { Transaction } from '../../models/transaction';
7+
8+
import { ErrorService } from '../../services/error.service';
9+
import { NavigatorService } from '../../services/navigator.service';
10+
import { BlocksService } from '../../services/blocks.service';
11+
12+
@Component({
13+
selector: 'app-block-raw',
14+
templateUrl: './block-raw.component.html',
15+
styleUrls: ['./block-raw.component.css']
16+
})
17+
export class BlockRawComponent implements OnInit {
18+
19+
block: any;
20+
21+
constructor(
22+
private route: ActivatedRoute,
23+
private router: Router,
24+
private navigatorService: NavigatorService,
25+
private blocksService: BlocksService,
26+
private errorService: ErrorService) { }
27+
28+
ngOnInit() {
29+
this.route.params.forEach(params => this.onBlockQuery(params['query']));
30+
}
31+
32+
private onBlockQuery(query: string) {
33+
this.blocksService.getRaw(query).subscribe(
34+
response => this.onBlockRetrieved(response),
35+
response => this.onError(response)
36+
);
37+
}
38+
39+
private onBlockRetrieved(response: any) {
40+
this.block = response;
41+
}
42+
43+
private onError(response: any) {
44+
this.errorService.renderServerErrors(null, response);
45+
}
46+
}

web-ui/src/app/components/block/block.component.css

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<div>
2+
<tabset class="col-xs-12 col-sm-12 col-md-12 col-xs-12">
3+
<tab heading="{{'label.details' | translate}}" (select)="selectView('details')">
4+
<app-block-details *ngIf="isSelected('details')"></app-block-details>
5+
</tab>
6+
<tab heading="{{'label.raw' | translate}}" (select)="selectView('raw')">
7+
<app-block-raw *ngIf="isSelected('raw')"></app-block-raw>
8+
</tab>
9+
</tabset>
10+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { BlockComponent } from './block.component';
4+
5+
describe('BlockComponent', () => {
6+
let component: BlockComponent;
7+
let fixture: ComponentFixture<BlockComponent>;
8+
9+
beforeEach(async(() => {
10+
TestBed.configureTestingModule({
11+
declarations: [ BlockComponent ]
12+
})
13+
.compileComponents();
14+
}));
15+
16+
beforeEach(() => {
17+
fixture = TestBed.createComponent(BlockComponent);
18+
component = fixture.componentInstance;
19+
fixture.detectChanges();
20+
});
21+
22+
it('should create', () => {
23+
expect(component).toBeTruthy();
24+
});
25+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { Component, OnInit } from '@angular/core';
2+
3+
@Component({
4+
selector: 'app-block',
5+
templateUrl: './block.component.html',
6+
styleUrls: ['./block.component.css']
7+
})
8+
export class BlockComponent implements OnInit {
9+
10+
currentView = 'details';
11+
12+
constructor() { }
13+
14+
ngOnInit() {
15+
}
16+
17+
selectView(view: string) {
18+
this.currentView = view;
19+
}
20+
21+
isSelected(view: string): boolean {
22+
return this.currentView === view;
23+
}
24+
}

web-ui/src/app/services/blocks.service.ts

+5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ export class BlocksService {
2222
return this.http.get<BlockDetails>(url);
2323
}
2424

25+
getRaw(query: string): Observable<any> {
26+
const url = `${this.baseUrl}/${query}/raw`;
27+
return this.http.get<any>(url);
28+
}
29+
2530
getLatest(): Observable<Block[]> {
2631
return this.http.get<Block[]>(this.baseUrl);
2732
}

0 commit comments

Comments
 (0)