refactored TransactionsComponent to allow for passed in query types and values

This commit is contained in:
Darren Nelsen 2017-08-02 11:20:16 -04:00
parent f02fd3c01f
commit 22351df704
5 changed files with 14 additions and 25 deletions

View File

@ -16,8 +16,8 @@ import { Http } from '@angular/http';
export class TransactionsComponent {
public loading: boolean = true;
@Input() public blockHash: string;
@Input() public address: string;
@Input() public queryType: string;
@Input() public queryValue: string;
public transactions: any = [];
constructor(private navCtrl: NavController, private http: Http) {
@ -25,21 +25,10 @@ export class TransactionsComponent {
private ngOnInit(): void {
let apiPrefix: string = 'http://localhost:3001/insight-api/';
let lookupType: string, lookupValue: string;
if (this.blockHash) {
lookupType = 'blocks';
lookupValue = this.blockHash;
}
if (this.address) {
lookupType = 'address';
lookupValue = this.address;
}
let url: string = apiPrefix + 'txs?' + this.queryType + '=' + this.queryValue;
console.log('blockHash', this.blockHash);
console.log('address', this.address);
this.http.get(apiPrefix + 'txs?' + lookupType + '=' + lookupValue).subscribe(
this.http.get(url).subscribe(
(data) => {
this.transactions = JSON.parse(data['_body']);
this.loading = false;

View File

@ -49,5 +49,5 @@
</ion-row>
</ion-grid>
<transactions [address]="address"></transactions>
<transactions [queryType]="'address'" [queryValue]="address"></transactions>
</ion-content>

View File

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

View File

@ -33,7 +33,7 @@
<p>Next Block <a (click)="goToNextBlock()">{{ block.height + 1 }}</a></p>
<h3>Transactions</h3>
<transactions [blockHash]="block.hash"></transactions>
<transactions [queryType]="'block'" [queryValue]="block.hash"></transactions>
</div>
<div *ngIf="loading">
<p>Loading...</p>

View File

@ -1,15 +1,15 @@
import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { BlockDetailPage } from './block-detail';
import { TransactionsComponent } from '../../components/transactions/transactions';
import { TransactionsComponentModule } from '../../components/transactions/transactions.module';
@NgModule({
declarations: [
BlockDetailPage,
TransactionsComponent
BlockDetailPage
],
imports: [
IonicPageModule.forChild(BlockDetailPage)
IonicPageModule.forChild(BlockDetailPage),
TransactionsComponentModule
],
exports: [
BlockDetailPage