Fix header

This commit is contained in:
Rene Vergara 2021-10-21 14:29:04 -05:00
parent 7e6cd11962
commit 62658f7be9
5 changed files with 25 additions and 14 deletions

View file

@ -16,3 +16,8 @@ ul{
.spacer{
flex: 1 1 auto;
}
.mini {
font-size: 9px;
line-height: 0.8;
}

View file

@ -1,11 +1,13 @@
<mat-toolbar color="primary">
<span>
<a routerLink = "/">
ZEC Block Height: {{heightUpdate | async}}
Zgo!
</a>
<p class="mini">Last block seen: {{heightUpdate | async}}</p>
</span>
<span class="spacer"></span>
<span>
{{shortenZaddr()}}
<span align="center">
<div>{{(ownerUpdate | async)!.name}}</div>
<div class="mini">{{ shortenZaddr((ownerUpdate | async)!.address) }}</div>
</span>
</mat-toolbar>

View file

@ -18,28 +18,26 @@ export class HeaderComponent implements OnInit, OnDestroy {
private session: string | null = '';
public heightUpdate: Observable<number>;
public ownerUpdate: Observable<Owner>;
public uZaddrUpdate: Observable<string>;
constructor(
public fullnodeService: FullnodeService,
public userService: UserService
){
this.heightUpdate = fullnodeService.heightUpdate;
this.uZaddrUpdate = userService.uZaddrUpdate;
this.ownerUpdate = userService.ownerUpdate;
}
ngOnInit(){
this.ownerUpdate.subscribe((owner) => {
this.owner = owner;
});
console.log('Header owner', this.owner);
}
ngOnDestroy(){
}
shortenZaddr() {
var addr = this.owner.address;
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));

View file

@ -45,6 +45,7 @@ export class UserService{
this.dataStore.user = UserDataResponse.body!.user[0];
console.log(`US: Found user, returning it`);
this._uZaddrUpdated.next(Object.assign({},this.dataStore).user.address);
this.getOwner(Object.assign({},this.dataStore.user).address);
} else {
console.log('US: Did not find user');
}
@ -87,15 +88,18 @@ export class UserService{
getOwner(address: string) {
console.log('getOwner', address);
const ownParams = new HttpParams().append('address', address);
let obs = this.http.get<{message:string, owner: any}>('http://localhost:3000/api/getowner', {params: ownParams, observe: 'response'});
obs.subscribe((OwnerDataResponse) => {
console.log('api/getowner', OwnerDataResponse.status);
if (OwnerDataResponse.status == 200) {
this.dataStore.owner = OwnerDataResponse.body!.owner[0];
this._ownerUpdated.next(this.dataStore.owner);
//console.log('getOwner object', this.dataStore.owner);
this._ownerUpdated.next(Object.assign({},this.dataStore).owner);
} else {
console.log("No owner found");
console.log("No owner found, adding");
this.addOwner(address);
}
});

View file

@ -21,9 +21,8 @@ import {Owner} from '../owner.model';
export class ViewerComponent implements OnInit {
public message: string = "Welcome to the inside!";
private UserSub: Subscription = new Subscription();
private OwnerSub: Subscription = new Subscription();
public addrUpdate: Observable<string>;
public ownerUpdate: Observable<Owner>;
constructor(
public fullnodeService: FullnodeService,
@ -32,10 +31,13 @@ export class ViewerComponent implements OnInit {
private dialog: MatDialog
){
this.addrUpdate = fullnodeService.addrUpdate;
this.ownerUpdate = userService.ownerUpdate;
}
ngOnInit(){
this.ownerUpdate.subscribe((owner) => {
this.message = owner.name;
});
}
ngOnDestroy(){