refactored TransactionsComponent to accept blockHash or address

This commit is contained in:
Darren Nelsen 2017-07-31 17:54:32 -04:00
parent 25a83b546b
commit f02fd3c01f
4 changed files with 25 additions and 3 deletions

View File

@ -17,6 +17,7 @@ export class TransactionsComponent {
public loading: boolean = true;
@Input() public blockHash: string;
@Input() public address: string;
public transactions: any = [];
constructor(private navCtrl: NavController, private http: Http) {
@ -24,8 +25,21 @@ export class TransactionsComponent {
private ngOnInit(): void {
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) => {
this.transactions = JSON.parse(data['_body']);
this.loading = false;

View File

@ -19,7 +19,7 @@
<ion-col col-12>
<h1>Address</h1>
<p>0 BTC</p>
<p>address</p>
<p>{{ address }}</p>
</ion-col>
</ion-row>
<ion-row>
@ -48,4 +48,6 @@
<ion-col col-12><h2>Transactions</h2></ion-col>
</ion-row>
</ion-grid>
<transactions [address]="address"></transactions>
</ion-content>

View File

@ -1,10 +1,12 @@
import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { AddressPage } from './address';
import { TransactionsComponent } from '../../components/transactions/transactions';
@NgModule({
declarations: [
AddressPage
AddressPage,
TransactionsComponent
],
imports: [
IonicPageModule.forChild(AddressPage)

View File

@ -17,7 +17,11 @@ import { IonicPage, NavController, NavParams } from 'ionic-angular';
})
export class AddressPage {
public loading: boolean = true;
private address: string;
constructor(public navCtrl: NavController, public navParams: NavParams) {
this.address = navParams.get('address');
}
public ionViewDidLoad(): void {