From a0291fb05e3015beb8db4cbb7443084392045f18 Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Mon, 8 May 2023 12:02:03 -0500 Subject: [PATCH] Enhance fullnode service for new API --- src/app/fullnode.service.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/app/fullnode.service.ts b/src/app/fullnode.service.ts index 255a14b..ef3eb11 100644 --- a/src/app/fullnode.service.ts +++ b/src/app/fullnode.service.ts @@ -1,5 +1,5 @@ import {Injectable} from '@angular/core'; -import {Subject, Subscription, BehaviorSubject, Observable} from 'rxjs'; +import {BehaviorSubject, Observable} from 'rxjs'; import {HttpClient, HttpParams, HttpHeaders} from '@angular/common/http'; import {UserService} from './user.service'; import { Owner } from './owner.model'; @@ -12,6 +12,7 @@ var Buffer = require('buffer/').Buffer; @Injectable({providedIn: 'root'}) export class FullnodeService{ beUrl = ConfigData.Be_URL; + private session: null|string = ''; private dataStore: { height: number, memoList: string[], addr: string, price: number } = { height: 0, memoList: [], addr: '', price:0 }; private _heightUpdated: BehaviorSubject = new BehaviorSubject(this.dataStore.height); private _memoUpdated: BehaviorSubject = new BehaviorSubject(this.dataStore.memoList); @@ -22,8 +23,8 @@ export class FullnodeService{ public readonly memoUpdate: Observable = this._memoUpdated.asObservable(); public readonly priceUpdate: Observable = this._priceUpdated.asObservable(); public readonly ownerUpdate: Observable; - private UserSub: Subscription = new Subscription(); private reqHeaders: HttpHeaders; + private params : HttpParams; private owner: Owner = { _id: '', name: '', @@ -53,6 +54,8 @@ export class FullnodeService{ }; constructor(private http: HttpClient, public userService: UserService){ + this.session = localStorage.getItem('s4z_token'); + this.params = new HttpParams().append('session', this.session!); var auth = 'Basic ' + Buffer.from(ConfigData.UsrPwd).toString('base64'); this.reqHeaders = new HttpHeaders().set('Authorization', auth); this.ownerUpdate = userService.ownerUpdate; @@ -65,7 +68,7 @@ export class FullnodeService{ } getHeight(){ - let obs = this.http.get<{message: string, height: number}>(this.beUrl+'api/blockheight', { headers: this.reqHeaders }); + let obs = this.http.get<{message: string, height: number}>(this.beUrl+'api/blockheight', { headers: this.reqHeaders, params: this.params }); obs.subscribe((BlockData) => { this.dataStore.height = BlockData.height; this._heightUpdated.next(Object.assign({}, this.dataStore).height); @@ -76,7 +79,7 @@ export class FullnodeService{ getPrice(currency: string){ //var currency = 'usd'; - const params = new HttpParams().append('currency', currency); + const params = this.params.append('currency', currency); let obs = this.http.get<{message: string, price: any}>(this.beUrl+'api/price', { headers:this.reqHeaders, params: params, observe: 'response'}); obs.subscribe((PriceData) => { if (PriceData.status == 200) { @@ -92,7 +95,7 @@ export class FullnodeService{ } getAddr() { - let obs = this.http.get<{message: string, addr: string}>(this.beUrl+'api/getaddr', { headers: this.reqHeaders }); + let obs = this.http.get<{message: string, addr: string}>(this.beUrl+'api/getaddr', { headers: this.reqHeaders, params: this.params }); obs.subscribe((AddrData) => { this.dataStore.addr = AddrData.addr;