import {Component, OnInit, OnDestroy} from '@angular/core'; import { MatDialog, MatDialogConfig} from '@angular/material/dialog'; import {FullnodeService} from '../fullnode.service'; import { UserService } from '../user.service'; import {Subscription, Observable} from 'rxjs'; import { SettingsComponent } from '../settings/settings.component'; import {Owner} from '../owner.model'; @Component({ selector: 'app-header', templateUrl: './header.component.html', styleUrls: ['./header.component.css'] }) export class HeaderComponent implements OnInit, OnDestroy { public height = 0; private owner: Owner= {_id:'', address: 'none', name:''}; private session: string | null = ''; public heightUpdate: Observable; public ownerUpdate: Observable; public uZaddrUpdate: Observable; constructor( public fullnodeService: FullnodeService, public userService: UserService, private dialog: MatDialog ){ this.heightUpdate = fullnodeService.heightUpdate; this.uZaddrUpdate = userService.uZaddrUpdate; this.ownerUpdate = userService.ownerUpdate; this.ownerUpdate.subscribe((owner) => { this.owner = owner; }); } ngOnInit(){ } ngOnDestroy(){ } shortenZaddr(address:string) { var addr = address; var end = addr.length; var last = end - 5; return addr.substring(0,5).concat('...').concat(addr.substring(last, end)); } openSettings() { const dialogConfig = new MatDialogConfig(); dialogConfig.disableClose = true; dialogConfig.autoFocus = true; dialogConfig.data = this.owner; const dialogRef = this.dialog.open(SettingsComponent, dialogConfig); dialogRef.afterClosed().subscribe((val) => { if (val != null) { console.log('Saving settings'); this.userService.updateOwner(val); } }); } }