|
@ -1,13 +1,10 @@ |
|
|
import { Component, OnInit } from '@angular/core'; |
|
|
import { Component, OnInit } from '@angular/core'; |
|
|
import { ActivatedRoute } from '@angular/router'; |
|
|
import { ActivatedRoute } from '@angular/router'; |
|
|
|
|
|
|
|
|
import { Observable } from 'rxjs/Observable'; |
|
|
|
|
|
|
|
|
|
|
|
import { Balance } from '../../models/balance'; |
|
|
import { Balance } from '../../models/balance'; |
|
|
import { Transaction } from '../../models/transaction'; |
|
|
|
|
|
|
|
|
|
|
|
import { AddressesService } from '../../services/addresses.service'; |
|
|
import { AddressesService } from '../../services/addresses.service'; |
|
|
import { ErrorService } from '../../services/error.service'; |
|
|
import { ErrorService } from '../../services/error.service'; |
|
|
|
|
|
import { LightWalletTransaction } from '../..//models/light-wallet-transaction'; |
|
|
|
|
|
|
|
|
@Component({ |
|
|
@Component({ |
|
|
selector: 'app-address-details', |
|
|
selector: 'app-address-details', |
|
@ -20,10 +17,8 @@ export class AddressDetailsComponent implements OnInit { |
|
|
addressString: string; |
|
|
addressString: string; |
|
|
|
|
|
|
|
|
// pagination
|
|
|
// pagination
|
|
|
total = 0; |
|
|
limit = 10; |
|
|
currentPage = 1; |
|
|
items: LightWalletTransaction[] = []; |
|
|
pageSize = 10; |
|
|
|
|
|
asyncItems: Observable<Transaction[]>; |
|
|
|
|
|
|
|
|
|
|
|
constructor( |
|
|
constructor( |
|
|
private route: ActivatedRoute, |
|
|
private route: ActivatedRoute, |
|
@ -36,26 +31,46 @@ export class AddressDetailsComponent implements OnInit { |
|
|
response => this.onAddressRetrieved(response), |
|
|
response => this.onAddressRetrieved(response), |
|
|
response => this.onError(response) |
|
|
response => this.onError(response) |
|
|
); |
|
|
); |
|
|
this.getPage(this.currentPage); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private onAddressRetrieved(response: Balance) { |
|
|
private onAddressRetrieved(response: Balance) { |
|
|
this.address = response; |
|
|
this.address = response; |
|
|
|
|
|
this.load(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
getPage(page: number) { |
|
|
load() { |
|
|
const offset = (page - 1) * this.pageSize; |
|
|
const order = 'desc'; |
|
|
const limit = this.pageSize; |
|
|
let lastSeenTxid = ''; |
|
|
const order = 'time:desc'; |
|
|
if (this.items.length > 0) { |
|
|
|
|
|
lastSeenTxid = this.items[this.items.length - 1].id; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
this.asyncItems = this.addressesService |
|
|
this.addressesService |
|
|
.getTransactions(this.addressString, offset, limit, order) |
|
|
.getTransactionsV2(this.addressString, this.limit, lastSeenTxid, order) |
|
|
.do(response => this.total = response.total) |
|
|
.do(response => this.items = this.items.concat(response.data)) |
|
|
.do(response => this.currentPage = 1 + (response.offset / this.pageSize)) |
|
|
.subscribe(); |
|
|
.map(response => response.data); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private onError(response: any) { |
|
|
private onError(response: any) { |
|
|
this.errorService.renderServerErrors(null, response); |
|
|
this.errorService.renderServerErrors(null, response); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
renderValue(tx: LightWalletTransaction): string { |
|
|
|
|
|
const spent = tx |
|
|
|
|
|
.inputs |
|
|
|
|
|
.map(input => input.value) |
|
|
|
|
|
.reduce((a, b) => a + b, 0); |
|
|
|
|
|
|
|
|
|
|
|
const received = tx |
|
|
|
|
|
.outputs |
|
|
|
|
|
.map(output => output.value) |
|
|
|
|
|
.reduce((a, b) => a + b, 0); |
|
|
|
|
|
|
|
|
|
|
|
const diff = Math.abs(received - spent); |
|
|
|
|
|
if (received >= spent) { |
|
|
|
|
|
return '+' + diff; |
|
|
|
|
|
} else { |
|
|
|
|
|
return '-' + diff; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|