refactored TransactionsComponent to accept blockHash or address
This commit is contained in:
parent
25a83b546b
commit
f02fd3c01f
@ -17,6 +17,7 @@ export class TransactionsComponent {
|
|||||||
|
|
||||||
public loading: boolean = true;
|
public loading: boolean = true;
|
||||||
@Input() public blockHash: string;
|
@Input() public blockHash: string;
|
||||||
|
@Input() public address: string;
|
||||||
public transactions: any = [];
|
public transactions: any = [];
|
||||||
|
|
||||||
constructor(private navCtrl: NavController, private http: Http) {
|
constructor(private navCtrl: NavController, private http: Http) {
|
||||||
@ -24,8 +25,21 @@ export class TransactionsComponent {
|
|||||||
|
|
||||||
private ngOnInit(): void {
|
private ngOnInit(): void {
|
||||||
let apiPrefix: string = 'http://localhost:3001/insight-api/';
|
let apiPrefix: string = 'http://localhost:3001/insight-api/';
|
||||||
|
let lookupType: string, lookupValue: string;
|
||||||
|
|
||||||
this.http.get(apiPrefix + 'txs?block=' + this.blockHash).subscribe(
|
if (this.blockHash) {
|
||||||
|
lookupType = 'blocks';
|
||||||
|
lookupValue = this.blockHash;
|
||||||
|
}
|
||||||
|
if (this.address) {
|
||||||
|
lookupType = 'address';
|
||||||
|
lookupValue = this.address;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('blockHash', this.blockHash);
|
||||||
|
console.log('address', this.address);
|
||||||
|
|
||||||
|
this.http.get(apiPrefix + 'txs?' + lookupType + '=' + lookupValue).subscribe(
|
||||||
(data) => {
|
(data) => {
|
||||||
this.transactions = JSON.parse(data['_body']);
|
this.transactions = JSON.parse(data['_body']);
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
|
|||||||
@ -19,7 +19,7 @@
|
|||||||
<ion-col col-12>
|
<ion-col col-12>
|
||||||
<h1>Address</h1>
|
<h1>Address</h1>
|
||||||
<p>0 BTC</p>
|
<p>0 BTC</p>
|
||||||
<p>address</p>
|
<p>{{ address }}</p>
|
||||||
</ion-col>
|
</ion-col>
|
||||||
</ion-row>
|
</ion-row>
|
||||||
<ion-row>
|
<ion-row>
|
||||||
@ -48,4 +48,6 @@
|
|||||||
<ion-col col-12><h2>Transactions</h2></ion-col>
|
<ion-col col-12><h2>Transactions</h2></ion-col>
|
||||||
</ion-row>
|
</ion-row>
|
||||||
</ion-grid>
|
</ion-grid>
|
||||||
|
|
||||||
|
<transactions [address]="address"></transactions>
|
||||||
</ion-content>
|
</ion-content>
|
||||||
|
|||||||
@ -1,10 +1,12 @@
|
|||||||
import { NgModule } from '@angular/core';
|
import { NgModule } from '@angular/core';
|
||||||
import { IonicPageModule } from 'ionic-angular';
|
import { IonicPageModule } from 'ionic-angular';
|
||||||
import { AddressPage } from './address';
|
import { AddressPage } from './address';
|
||||||
|
import { TransactionsComponent } from '../../components/transactions/transactions';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
declarations: [
|
declarations: [
|
||||||
AddressPage
|
AddressPage,
|
||||||
|
TransactionsComponent
|
||||||
],
|
],
|
||||||
imports: [
|
imports: [
|
||||||
IonicPageModule.forChild(AddressPage)
|
IonicPageModule.forChild(AddressPage)
|
||||||
|
|||||||
@ -17,7 +17,11 @@ import { IonicPage, NavController, NavParams } from 'ionic-angular';
|
|||||||
})
|
})
|
||||||
export class AddressPage {
|
export class AddressPage {
|
||||||
|
|
||||||
|
public loading: boolean = true;
|
||||||
|
private address: string;
|
||||||
|
|
||||||
constructor(public navCtrl: NavController, public navParams: NavParams) {
|
constructor(public navCtrl: NavController, public navParams: NavParams) {
|
||||||
|
this.address = navParams.get('address');
|
||||||
}
|
}
|
||||||
|
|
||||||
public ionViewDidLoad(): void {
|
public ionViewDidLoad(): void {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user