Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #29

Merged
merged 2 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import { ChangeDetectionStrategy, Component, OnDestroy, OnInit } from '@angular/core';
import { ActivatedRoute, Params } from '@angular/router';
import { NetworkService } from '../../../../../services/network.service';
import { BehaviorSubject, combineLatest, Observable, of, Subject, take, timer } from 'rxjs';
import { BehaviorSubject, combineLatest, Observable, of, startWith, Subject, take, timer } from 'rxjs';
import { Block } from '../../../../../services/block/block.harvester';
import { catchError, filter, first, switchMap, takeUntil, takeWhile, tap } from 'rxjs/operators';
import { catchError, distinctUntilChanged, filter, first, switchMap, takeUntil, takeWhile, tap } from 'rxjs/operators';
import { PolkadaptService } from '../../../../../services/polkadapt.service';
import { types as pst } from '@polkadapt/core';

Expand All @@ -34,8 +34,8 @@ import { types as pst } from '@polkadapt/core';
export class BlockDetailComponent implements OnInit, OnDestroy {
private destroyer = new Subject<void>();
block = new BehaviorSubject<Block | null>(null);
extrinsics = new BehaviorSubject<pst.Extrinsic[]>([]);
events = new BehaviorSubject<pst.Event[]>([]);
extrinsics: Observable<pst.Extrinsic[]>;
events: Observable<pst.Event[]>;
headNumber = new BehaviorSubject<number>(0);
invalidHash = new BehaviorSubject<boolean>(false);

Expand Down Expand Up @@ -95,14 +95,13 @@ export class BlockDetailComponent implements OnInit, OnDestroy {
).subscribe();


this.block.pipe(
filter((block): block is Block => Boolean(block && block.finalized === true)),
take(1)
).subscribe({
next: (block) => {
this.extrinsics.next([]);
if (block.countExtrinsics) {
timer(0, 1000).pipe(
this.extrinsics = this.block.pipe(
distinctUntilChanged((p, n) => Boolean(p && n
&& p.number === n.number
&& p.finalized === n.finalized)),
switchMap((block) => {
if (block && block.finalized && block.countExtrinsics) {
return timer(0, 1000).pipe(
take(10), // Try it for 10 seconds.
switchMap(() => this.pa.run().getExtrinsics({
blockNumber: block.number,
Expand All @@ -111,15 +110,21 @@ export class BlockDetailComponent implements OnInit, OnDestroy {
}, 300)),
takeUntil(this.destroyer),
takeWhile((extrinsics) => block.countExtrinsics! > extrinsics.length, true),
switchMap((obs) => obs.length ? combineLatest(obs) : of([]))
).subscribe({
next: (extrinsics: pst.Extrinsic[]) => this.extrinsics.next(extrinsics)
});
switchMap((obs) => obs.length ? combineLatest(obs) : of([])),
startWith([])
)
}
return of([]);
})
);

this.events.next([]);
if (block.countEvents) {
timer(0, 1000).pipe(
this.events = this.block.pipe(
distinctUntilChanged((p, n) => Boolean(p && n
&& p.number === n.number
&& p.finalized === n.finalized)),
switchMap((block) => {
if (block && block.finalized && block.countEvents) {
return timer(0, 1000).pipe(
take(10), // Try it for 10 seconds.
switchMap(() => this.pa.run().getEvents({
blockNumber: block.number,
Expand All @@ -128,13 +133,13 @@ export class BlockDetailComponent implements OnInit, OnDestroy {
}, 300)),
takeUntil(this.destroyer),
takeWhile((events) => block.countEvents! > events.length, true),
switchMap((obs) => obs.length ? combineLatest(obs) : of([]))
).subscribe({
next: (events: pst.Event[]) => this.events.next(events)
});
switchMap((obs) => obs.length ? combineLatest(obs) : of([])),
startWith([])
)
}
}
})
return of([]);
})
);
}

ngOnDestroy(): void {
Expand Down
1 change: 0 additions & 1 deletion src/app/pages/privacy-policy/privacy-policy.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export class PrivacyPolicyComponent implements OnInit {
this.http.get('assets/privacy-policy.html', {responseType: 'text'}).subscribe({
next: html => {
this.safeHtml.next(this.sanitizer.sanitize(SecurityContext.HTML, html));
console.log(this.safeHtml.value);
},
error: (err) => {
this.router.navigate(['/not-found']);
Expand Down