2020-03-01 03:32:12 +07:00
|
|
|
import { Component, OnInit, Input, ChangeDetectionStrategy, OnChanges, ChangeDetectorRef, Output, EventEmitter } from '@angular/core';
|
2020-02-16 22:15:07 +07:00
|
|
|
import { StateService } from '../../services/state.service';
|
|
|
|
import { Observable, forkJoin } from 'rxjs';
|
2020-02-26 04:29:57 +07:00
|
|
|
import { Block, Outspend, Transaction } from '../../interfaces/electrs.interface';
|
2020-02-16 22:15:07 +07:00
|
|
|
import { ElectrsApiService } from '../../services/electrs-api.service';
|
2020-05-02 12:36:35 +07:00
|
|
|
import { environment } from 'src/environments/environment';
|
|
|
|
import { AssetsService } from 'src/app/services/assets.service';
|
2020-06-21 14:55:16 +07:00
|
|
|
import { map } from 'rxjs/operators';
|
2020-02-16 22:15:07 +07:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-transactions-list',
|
|
|
|
templateUrl: './transactions-list.component.html',
|
|
|
|
styleUrls: ['./transactions-list.component.scss'],
|
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush
|
|
|
|
})
|
|
|
|
export class TransactionsListComponent implements OnInit, OnChanges {
|
2020-05-09 20:37:50 +07:00
|
|
|
network = '';
|
2020-05-02 12:36:35 +07:00
|
|
|
nativeAssetId = environment.nativeAssetId;
|
2020-11-15 17:58:38 +07:00
|
|
|
displayDetails = false;
|
2020-05-02 12:36:35 +07:00
|
|
|
|
2020-02-28 01:09:07 +07:00
|
|
|
@Input() transactions: Transaction[];
|
2020-02-16 22:15:07 +07:00
|
|
|
@Input() showConfirmations = false;
|
|
|
|
@Input() transactionPage = false;
|
2021-07-06 13:56:32 -03:00
|
|
|
@Input() errorUnblinded = false;
|
2020-02-16 22:15:07 +07:00
|
|
|
|
2020-03-01 03:32:12 +07:00
|
|
|
@Output() loadMore = new EventEmitter();
|
|
|
|
|
2020-06-21 14:55:16 +07:00
|
|
|
latestBlock$: Observable<Block>;
|
2020-02-16 22:15:07 +07:00
|
|
|
outspends: Outspend[] = [];
|
2020-05-02 12:36:35 +07:00
|
|
|
assetsMinimal: any;
|
2020-02-16 22:15:07 +07:00
|
|
|
|
|
|
|
constructor(
|
|
|
|
private stateService: StateService,
|
|
|
|
private electrsApiService: ElectrsApiService,
|
2020-05-02 12:36:35 +07:00
|
|
|
private assetsService: AssetsService,
|
2020-02-16 22:15:07 +07:00
|
|
|
private ref: ChangeDetectorRef,
|
|
|
|
) { }
|
|
|
|
|
|
|
|
ngOnInit() {
|
2020-06-21 14:55:16 +07:00
|
|
|
this.latestBlock$ = this.stateService.blocks$.pipe(map(([block]) => block));
|
2020-05-09 20:37:50 +07:00
|
|
|
this.stateService.networkChanged$.subscribe((network) => this.network = network);
|
|
|
|
|
2020-05-05 15:26:23 +07:00
|
|
|
if (this.network === 'liquid') {
|
|
|
|
this.assetsService.getAssetsMinimalJson$.subscribe((assets) => {
|
|
|
|
this.assetsMinimal = assets;
|
|
|
|
});
|
|
|
|
}
|
2020-02-16 22:15:07 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnChanges() {
|
|
|
|
if (!this.transactions || !this.transactions.length) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const observableObject = {};
|
|
|
|
this.transactions.forEach((tx, i) => {
|
2020-09-29 15:05:52 +07:00
|
|
|
tx['@voutLimit'] = true;
|
|
|
|
tx['@vinLimit'] = true;
|
2020-02-16 22:15:07 +07:00
|
|
|
if (this.outspends[i]) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
observableObject[i] = this.electrsApiService.getOutspends$(tx.txid);
|
|
|
|
});
|
|
|
|
|
|
|
|
forkJoin(observableObject)
|
|
|
|
.subscribe((outspends: any) => {
|
|
|
|
const newOutspends = [];
|
|
|
|
for (const i in outspends) {
|
|
|
|
if (outspends.hasOwnProperty(i)) {
|
|
|
|
newOutspends.push(outspends[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.outspends = this.outspends.concat(newOutspends);
|
|
|
|
this.ref.markForCheck();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-03-01 03:32:12 +07:00
|
|
|
onScroll() {
|
2021-05-19 19:03:59 -03:00
|
|
|
const scrollHeight = document.body.scrollHeight;
|
|
|
|
const scrollTop = document.documentElement.scrollTop;
|
2021-05-21 12:03:18 -03:00
|
|
|
if (scrollHeight > 0){
|
2021-05-19 19:03:59 -03:00
|
|
|
const percentageScrolled = scrollTop * 100 / scrollHeight;
|
2021-06-24 18:20:20 -04:00
|
|
|
if (percentageScrolled > 70){
|
2021-05-19 19:03:59 -03:00
|
|
|
this.loadMore.emit();
|
|
|
|
}
|
|
|
|
}
|
2020-03-01 03:32:12 +07:00
|
|
|
}
|
|
|
|
|
2020-03-27 02:34:09 +07:00
|
|
|
getTotalTxOutput(tx: Transaction) {
|
2020-02-16 22:15:07 +07:00
|
|
|
return tx.vout.map((v: any) => v.value || 0).reduce((a: number, b: number) => a + b);
|
|
|
|
}
|
|
|
|
|
|
|
|
switchCurrency() {
|
2020-05-02 12:36:35 +07:00
|
|
|
if (this.network === 'liquid') {
|
|
|
|
return;
|
|
|
|
}
|
2020-02-16 22:15:07 +07:00
|
|
|
const oldvalue = !this.stateService.viewFiat$.value;
|
|
|
|
this.stateService.viewFiat$.next(oldvalue);
|
|
|
|
}
|
|
|
|
|
2020-09-29 15:05:52 +07:00
|
|
|
trackByFn(index: number, tx: Transaction): string {
|
2020-02-26 21:11:43 +07:00
|
|
|
return tx.txid + tx.status.confirmed;
|
2020-02-16 22:15:07 +07:00
|
|
|
}
|
2020-03-27 02:34:09 +07:00
|
|
|
|
2020-07-03 23:45:19 +07:00
|
|
|
trackByIndexFn(index: number) {
|
|
|
|
return index;
|
|
|
|
}
|
2020-11-15 17:58:38 +07:00
|
|
|
|
|
|
|
formatHex(num: number): string {
|
|
|
|
const str = num.toString(16);
|
|
|
|
return '0x' + (str.length % 2 ? '0' : '') + str;
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleDetails() {
|
|
|
|
this.displayDetails = !this.displayDetails;
|
|
|
|
this.ref.markForCheck();
|
|
|
|
}
|
2020-02-16 22:15:07 +07:00
|
|
|
}
|