diff --git a/src/app/app.module.ts b/src/app/app.module.ts
index 09901fa..7d3be8b 100644
--- a/src/app/app.module.ts
+++ b/src/app/app.module.ts
@@ -12,7 +12,7 @@ import { MatDialogModule } from '@angular/material/dialog';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
//import { PostCreateComponent } from './posts/post-create/post-create.component';
-//import { HeaderComponent } from './header/header.component';
+import { HeaderComponent } from './header/header.component';
//import { PostListComponent } from './posts/post-list/post-list.component';
//import { PostService } from './posts/posts.service';
import { ViewerComponent } from './viewer/viewer.component';
@@ -24,7 +24,7 @@ import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
declarations: [
AppComponent,
//PostCreateComponent,
- //HeaderComponent,
+ HeaderComponent,
ViewerComponent,
LoginComponent,
//NameDialogComponent,
diff --git a/src/app/header/header.component.html b/src/app/header/header.component.html
index 7bd7184..fe758ab 100644
--- a/src/app/header/header.component.html
+++ b/src/app/header/header.component.html
@@ -1,19 +1,11 @@
- ZEC Block Height: {{height}}
+ ZEC Block Height: {{heightUpdate | async}}
- testy
+ {{shortenZaddr()}}
-
diff --git a/src/app/header/header.component.ts b/src/app/header/header.component.ts
index 4431f26..c9920f3 100644
--- a/src/app/header/header.component.ts
+++ b/src/app/header/header.component.ts
@@ -1,7 +1,7 @@
import {Component, OnInit, OnDestroy} from '@angular/core';
import {FullnodeService} from '../fullnode.service';
import { UserService } from '../user.service';
-import {Subscription} from 'rxjs';
+import {Subscription, Observable} from 'rxjs';
import {Owner} from '../owner.model';
@@ -16,23 +16,26 @@ export class HeaderComponent implements OnInit, OnDestroy {
public height = 0;
private owner: Owner= {_id:'', address: 'none', name:''};
private session: string | null = '';
- //private FullnodeSub: Subscription = new Subscription();
- private UserSub: Subscription = new Subscription();
+ public heightUpdate: Observable;
+ public ownerUpdate: Observable;
+
constructor(
public fullnodeService: FullnodeService,
public userService: UserService
){
+ this.heightUpdate = fullnodeService.heightUpdate;
+ this.ownerUpdate = userService.ownerUpdate;
}
ngOnInit(){
- this.fullnodeService.getHeight();
- this.height = this.fullnodeService.heightUpdate;
+ this.ownerUpdate.subscribe((owner) => {
+ this.owner = owner;
+ });
+ console.log('Header owner', this.owner);
}
ngOnDestroy(){
- //this.FullnodeSub.unsubscribe();
- //this.UserSub.unsubscribe();
}
shortenZaddr() {
diff --git a/src/app/owner.model.ts b/src/app/owner.model.ts
index 13e095c..432d8c6 100644
--- a/src/app/owner.model.ts
+++ b/src/app/owner.model.ts
@@ -1,5 +1,5 @@
export interface Owner {
- _id: string;
+ _id?: string;
address: string;
name: string;
}
diff --git a/src/app/user.service.ts b/src/app/user.service.ts
index 3e05d0f..b5e4a62 100644
--- a/src/app/user.service.ts
+++ b/src/app/user.service.ts
@@ -7,15 +7,26 @@ import {Owner} from './owner.model';
@Injectable({providedIn: 'root'})
export class UserService{
- private dataStore: { user: User} = { user: { address: '', session: '', blocktime: 0 }};
+ private dataStore: { user: User, owner: Owner} = {
+ user: {
+ address: '',
+ session: '',
+ blocktime: 0
+ },
+ owner: {
+ address: '',
+ name: ''
+ }
+ };
private uZaddr = '';
private oZaddr = '';
private uName = '';
private session: string | null = '';
private _uZaddrUpdated: BehaviorSubject = new BehaviorSubject(this.uZaddr);
private uNameUpdated = new Subject();
- private ownerUpdated = new Subject();
+ private _ownerUpdated: BehaviorSubject = new BehaviorSubject(this.dataStore.owner);
public readonly uZaddrUpdate: Observable = this._uZaddrUpdated.asObservable();
+ public readonly ownerUpdate: Observable = this._ownerUpdated.asObservable();
constructor(private http: HttpClient){
this.session = localStorage.getItem('s4z_token');
@@ -44,22 +55,27 @@ export class UserService{
addUser(address: string, session: string, blocktime: number) {
const user: User={_id: '', address: address, session: session, blocktime: blocktime};
- this.http.post<{message: string}>('http://localhost:3000/api/users', user).
- subscribe((responseData) => {
+ let obs = this.http.post<{message: string}>('http://localhost:3000/api/users', user);
+
+ obs.subscribe((responseData) => {
console.log(responseData.message);
- //this.getOwner(address);
- //if (this.oZaddr == '') {
- //this.addOwner(address);
- //}
+ this.getOwner(address).subscribe((response) => {
+ console.log('addUser, checking owner', response);
+ });
});
+
+ return obs;
}
addOwner(address: string) {
const owner: Owner={_id: '', address: address, name: 'Zgo-'.concat(address.substring(0,5))};
- this.http.post<{message: string}>('http://localhost:3000/api/addowner', {address: owner.address, name: owner.name}).
- subscribe((responseData) => {
+ let obs = this.http.post<{message: string}>('http://localhost:3000/api/addowner', {address: owner.address, name: owner.name});
+
+ obs.subscribe((responseData) => {
console.log(responseData.message);
});
+
+ return obs;
}
addOwnerName(address: string, name: string) {
@@ -69,50 +85,55 @@ export class UserService{
});
}
- getUser(session: string) {
- const params = new HttpParams().append('session', session);
- console.log(`US: Searching for session ${session} `);
- this.http.get<{message: string, user: any}>('http://localhost:3000/api/getuser', { headers:{}, params: params, observe: 'response'}).
- subscribe((UserDataResponse) => {
- console.log(UserDataResponse.status);
- if (UserDataResponse.status == 200){
- this.uZaddr = UserDataResponse.body!.user[0].address;
- console.log(`US: Found user, returning zaddr ${this.uZaddr}`);
- this._uZaddrUpdated.next(this.uZaddr);
- } else {
- console.log('US: Did not find user');
- this._uZaddrUpdated.next('');
- }
- });
-
- }
getOwner(address: string) {
const ownParams = new HttpParams().append('address', address);
- this.http.get<{message:string, owner: any}>('http://localhost:3000/api/getowner', {params: ownParams, observe: 'response'}).
- subscribe((OwnerDataResponse) => {
+ let obs = this.http.get<{message:string, owner: any}>('http://localhost:3000/api/getowner', {params: ownParams, observe: 'response'});
+
+ obs.subscribe((OwnerDataResponse) => {
if (OwnerDataResponse.status == 200) {
- this.ownerUpdated.next(OwnerDataResponse.body!.owner[0]);
+ this.dataStore.owner = OwnerDataResponse.body!.owner[0];
+ this._ownerUpdated.next(this.dataStore.owner);
} else {
- console.log("No owner found, adding");
- //this.addOwner(address);
+ console.log("No owner found");
+ this.addOwner(address);
}
});
+
+ return obs;
}
hasOwner() {
return this.uZaddr === this.oZaddr;
}
- getName() {
- if (this.session != null) {
- this.getUser(this.session);
- this._uZaddrUpdated.subscribe((addr: string) => {
- console.log(` US: ${addr}`);
- this.getOwner(addr);
- });
- }
- }
+ //getUser(session: string) {
+ //const params = new HttpParams().append('session', session);
+ //console.log(`US: Searching for session ${session} `);
+ //this.http.get<{message: string, user: any}>('http://localhost:3000/api/getuser', { headers:{}, params: params, observe: 'response'}).
+ //subscribe((UserDataResponse) => {
+ //console.log(UserDataResponse.status);
+ //if (UserDataResponse.status == 200){
+ //this.uZaddr = UserDataResponse.body!.user[0].address;
+ //console.log(`US: Found user, returning zaddr ${this.uZaddr}`);
+ //this._uZaddrUpdated.next(this.uZaddr);
+ //} else {
+ //console.log('US: Did not find user');
+ //this._uZaddrUpdated.next('');
+ //}
+ //});
+
+ //}
+
+ //getName() {
+ //if (this.session != null) {
+ //this.getUser(this.session);
+ //this._uZaddrUpdated.subscribe((addr: string) => {
+ //console.log(` US: ${addr}`);
+ //this.getOwner(addr);
+ //});
+ //}
+ //}
getNameUpdateListener() {
return this.uNameUpdated;
@@ -122,8 +143,4 @@ export class UserService{
//return this.uZaddrUpdated;
//}
- getOwnerUpdateListener() {
- return this.ownerUpdated;
- }
-
}
diff --git a/src/app/viewer/viewer.component.html b/src/app/viewer/viewer.component.html
index b4eaaa6..dee0d4b 100644
--- a/src/app/viewer/viewer.component.html
+++ b/src/app/viewer/viewer.component.html
@@ -1,4 +1,4 @@
-
+
{{message}}