mempool/frontend/src/app/components/about/about.component.ts

94 lines
3.1 KiB
TypeScript
Raw Normal View History

import { ChangeDetectionStrategy, Component, Inject, LOCALE_ID, OnInit } from '@angular/core';
import { WebsocketService } from '../../services/websocket.service';
2022-09-21 17:23:45 +02:00
import { SeoService } from '../../services/seo.service';
import { StateService } from '../../services/state.service';
2021-05-18 13:23:39 +04:00
import { Observable } from 'rxjs';
2022-09-21 17:23:45 +02:00
import { ApiService } from '../../services/api.service';
import { IBackendInfo } from '../../interfaces/websocket.interface';
import { Router, ActivatedRoute } from '@angular/router';
import { map, tap } from 'rxjs/operators';
2022-09-21 17:23:45 +02:00
import { ITranslators } from '../../interfaces/node-api.interface';
import { DOCUMENT } from '@angular/common';
2019-07-21 17:59:47 +03:00
@Component({
selector: 'app-about',
templateUrl: './about.component.html',
styleUrls: ['./about.component.scss'],
2021-05-18 13:23:39 +04:00
changeDetection: ChangeDetectionStrategy.OnPush,
2019-07-21 17:59:47 +03:00
})
2021-05-18 13:23:39 +04:00
export class AboutComponent implements OnInit {
backendInfo$: Observable<IBackendInfo>;
sponsors$: Observable<any>;
2022-01-13 03:58:12 +04:00
translators$: Observable<ITranslators>;
allContributors$: Observable<any>;
frontendGitCommitHash = this.stateService.env.GIT_COMMIT_HASH;
packetJsonVersion = this.stateService.env.PACKAGE_JSON_VERSION;
officialMempoolSpace = this.stateService.env.OFFICIAL_MEMPOOL_SPACE;
2021-05-18 13:23:39 +04:00
showNavigateToSponsor = false;
2019-07-21 17:59:47 +03:00
constructor(
private websocketService: WebsocketService,
2020-03-24 00:52:08 +07:00
private seoService: SeoService,
public stateService: StateService,
private apiService: ApiService,
2021-05-18 13:23:39 +04:00
private router: Router,
private route: ActivatedRoute,
@Inject(LOCALE_ID) public locale: string,
@Inject(DOCUMENT) private document: Document,
) { }
2019-07-21 17:59:47 +03:00
ngOnInit() {
this.backendInfo$ = this.stateService.backendInfo$;
2020-12-03 18:34:19 +07:00
this.seoService.setTitle($localize`:@@004b222ff9ef9dd4771b777950ca1d0e4cd4348a:About`);
2020-02-17 20:39:20 +07:00
this.websocketService.want(['blocks']);
this.sponsors$ = this.apiService.getDonation$()
.pipe(
tap(() => this.goToAnchor())
);
2022-01-13 03:58:12 +04:00
this.translators$ = this.apiService.getTranslators$()
.pipe(
map((translators) => {
for (const t in translators) {
if (translators[t] === '') {
delete translators[t];
2022-01-13 03:58:12 +04:00
}
}
return translators;
}),
tap(() => this.goToAnchor())
2022-01-13 03:58:12 +04:00
);
this.allContributors$ = this.apiService.getContributor$().pipe(
map((contributors) => {
return {
regular: contributors.filter((user) => !user.core_constributor),
core: contributors.filter((user) => user.core_constributor),
};
}),
tap(() => this.goToAnchor())
);
}
ngAfterViewInit() {
this.goToAnchor();
}
goToAnchor() {
setTimeout(() => {
if (this.route.snapshot.fragment) {
if (this.document.getElementById(this.route.snapshot.fragment)) {
this.document.getElementById(this.route.snapshot.fragment).scrollIntoView({behavior: 'smooth'});
}
}
}, 1);
}
sponsor(): void {
if (this.officialMempoolSpace && this.stateService.env.BASE_MODULE === 'mempool') {
this.router.navigateByUrl('/enterprise');
2021-05-18 13:23:39 +04:00
} else {
this.showNavigateToSponsor = true;
}
}
2019-07-21 17:59:47 +03:00
}