Browse Source

web-ui: Add the BlocksService

scalafmt-draft
Alexis Hernandez 7 years ago
parent
commit
a9da5951b5
  1. 2
      web-ui/src/app/app.module.ts
  2. 36
      web-ui/src/app/models/block.ts
  3. 24
      web-ui/src/app/services/blocks.service.ts

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

@ -13,6 +13,7 @@ import { ToastrModule } from 'ngx-toastr';
import { NgHttpLoaderModule } from 'ng-http-loader/ng-http-loader.module'
import { AddressesService } from './services/addresses.service';
import { BlocksService } from './services/blocks.service';
import { ErrorService } from './services/error.service';
import { LanguageService } from './services/language.service';
import { NavigatorService } from './services/navigator.service';
@ -58,6 +59,7 @@ import { BlockDetailsComponent } from './components/block-details/block-details.
],
providers: [
AddressesService,
BlocksService,
ErrorService,
LanguageService,
NavigatorService,

36
web-ui/src/app/models/block.ts

@ -0,0 +1,36 @@
export class BlockDetails {
block: Block;
rewards: BlockRewards;
}
class Block {
hash: string;
previousBlockhash: string;
nextBlockhash: string;
merkleRoot: string;
transactions: string[];
confirmations: number;
size: number;
height: number;
version: number;
time: number;
medianTime: number;
nonce: number;
bits: string;
chainwork: string;
difficulty: number;
tposContract: string;
}
class BlockRewards {
reward: BlockReward;
coinstake: BlockReward;
masternode: BlockReward;
}
class BlockReward {
address: string;
value: number;
}

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

@ -0,0 +1,24 @@
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import { environment } from '../../environments/environment';
import { BlockDetails } from '../models/block';
const httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'application/json' })
};
@Injectable()
export class BlocksService {
private baseUrl = environment.api.url + '/blocks';
constructor(private http: HttpClient) { }
get(blockhash: string): Observable<BlockDetails> {
const url = `${this.baseUrl}/${blockhash}`;
return this.http.get<BlockDetails>(url);
}
}
Loading…
Cancel
Save