Enhance fullnode service for new API

This commit is contained in:
Rene Vergara 2023-05-08 12:02:03 -05:00
parent 3479c0c206
commit a0291fb05e
Signed by: pitmutt
GPG Key ID: 65122AD495A7F5B2
1 changed files with 8 additions and 5 deletions

View File

@ -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<number> = new BehaviorSubject(this.dataStore.height);
private _memoUpdated: BehaviorSubject<string[]> = new BehaviorSubject(this.dataStore.memoList);
@ -22,8 +23,8 @@ export class FullnodeService{
public readonly memoUpdate: Observable<string[]> = this._memoUpdated.asObservable();
public readonly priceUpdate: Observable<number> = this._priceUpdated.asObservable();
public readonly ownerUpdate: Observable<Owner>;
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;