mempool/frontend/src/app/shared/components/global-footer/global-footer.component.ts

102 lines
3.9 KiB
TypeScript
Raw Normal View History

import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit, Inject, LOCALE_ID } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Observable, merge, of, Subject, Subscription } from 'rxjs';
2023-05-11 19:31:22 -04:00
import { tap, takeUntil } from 'rxjs/operators';
import { Env, StateService } from '../../../services/state.service';
2023-05-06 04:10:17 -04:00
import { IBackendInfo } from '../../../interfaces/websocket.interface';
import { LanguageService } from '../../../services/language.service';
import { NavigationService } from '../../../services/navigation.service';
import { StorageService } from '../../../services/storage.service';
import { WebsocketService } from '../../../services/websocket.service';
@Component({
selector: 'app-global-footer',
templateUrl: './global-footer.component.html',
styleUrls: ['./global-footer.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class GlobalFooterComponent implements OnInit {
2023-05-11 19:31:22 -04:00
private destroy$: Subject<any> = new Subject<any>();
env: Env;
officialMempoolSpace = this.stateService.env.OFFICIAL_MEMPOOL_SPACE;
2023-05-06 04:10:17 -04:00
backendInfo$: Observable<IBackendInfo>;
servicesBackendInfo$: Observable<IBackendInfo>;
2023-05-06 04:10:17 -04:00
frontendGitCommitHash = this.stateService.env.GIT_COMMIT_HASH;
packetJsonVersion = this.stateService.env.PACKAGE_JSON_VERSION;
urlLanguage: string;
2023-05-11 19:31:22 -04:00
network$: Observable<string>;
networkPaths: { [network: string]: string };
2023-05-12 09:37:19 -05:00
currentNetwork = '';
loggedIn = false;
username = null;
urlSubscription: Subscription;
addPadding = false;
isServices = false;
constructor(
public stateService: StateService,
private languageService: LanguageService,
private navigationService: NavigationService,
@Inject(LOCALE_ID) public locale: string,
private storageService: StorageService,
private route: ActivatedRoute,
private cd: ChangeDetectorRef,
private websocketService: WebsocketService,
private router: Router
) {}
ngOnInit(): void {
this.isServices = this.router.url.includes('/services/');
this.env = this.stateService.env;
2023-05-06 04:10:17 -04:00
this.backendInfo$ = this.stateService.backendInfo$;
this.servicesBackendInfo$ = this.stateService.servicesBackendInfo$;
this.urlLanguage = this.languageService.getLanguageForUrl();
this.navigationService.subnetPaths.subscribe((paths) => {
this.networkPaths = paths;
});
2023-05-11 19:31:22 -04:00
this.network$ = merge(of(''), this.stateService.networkChanged$).pipe(
tap((network: string) => {
return network;
})
);
this.network$.pipe(takeUntil(this.destroy$)).subscribe((network) => {
this.currentNetwork = network;
});
this.urlSubscription = this.route.url.subscribe((url) => {
this.loggedIn = JSON.parse(this.storageService.getValue('auth')) !== null;
const auth = JSON.parse(this.storageService.getValue('auth'));
if (auth?.user?.username) {
this.username = auth.user.username;
} else {
this.username = null;
}
this.addPadding = url[0].path === 'services' && !this.isSmallScreen();
this.cd.markForCheck();
})
}
2023-05-12 09:37:19 -05:00
ngOnDestroy(): void {
this.destroy$.next(true);
this.destroy$.complete();
this.urlSubscription.unsubscribe();
2023-05-12 09:37:19 -05:00
}
networkLink(network) {
const thisNetwork = network || 'mainnet';
if( network === '' || network === 'mainnet' || network === 'testnet' || network === 'signet' ) {
return (this.env.BASE_MODULE === 'mempool' ? '' : this.env.MEMPOOL_WEBSITE_URL + this.urlLanguage) + this.networkPaths[thisNetwork] || '/';
}
2023-05-12 09:37:19 -05:00
if( network === 'liquid' || network === 'liquidtestnet' ) {
return (this.env.BASE_MODULE === 'liquid' ? '' : this.env.LIQUID_WEBSITE_URL + this.urlLanguage) + this.networkPaths[thisNetwork] || '/';
}
2023-05-12 09:37:19 -05:00
if( network === 'bisq' ) {
return (this.env.BASE_MODULE === 'bisq' ? '' : this.env.BISQ_WEBSITE_URL + this.urlLanguage) + this.networkPaths[thisNetwork] || '/';
}
}
isSmallScreen() {
return window.innerWidth <= 767.98;
}
}