Enhance fullnode service for new API
This commit is contained in:
parent
3479c0c206
commit
a0291fb05e
1 changed files with 8 additions and 5 deletions
|
@ -1,5 +1,5 @@
|
||||||
import {Injectable} from '@angular/core';
|
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 {HttpClient, HttpParams, HttpHeaders} from '@angular/common/http';
|
||||||
import {UserService} from './user.service';
|
import {UserService} from './user.service';
|
||||||
import { Owner } from './owner.model';
|
import { Owner } from './owner.model';
|
||||||
|
@ -12,6 +12,7 @@ var Buffer = require('buffer/').Buffer;
|
||||||
@Injectable({providedIn: 'root'})
|
@Injectable({providedIn: 'root'})
|
||||||
export class FullnodeService{
|
export class FullnodeService{
|
||||||
beUrl = ConfigData.Be_URL;
|
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 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 _heightUpdated: BehaviorSubject<number> = new BehaviorSubject(this.dataStore.height);
|
||||||
private _memoUpdated: BehaviorSubject<string[]> = new BehaviorSubject(this.dataStore.memoList);
|
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 memoUpdate: Observable<string[]> = this._memoUpdated.asObservable();
|
||||||
public readonly priceUpdate: Observable<number> = this._priceUpdated.asObservable();
|
public readonly priceUpdate: Observable<number> = this._priceUpdated.asObservable();
|
||||||
public readonly ownerUpdate: Observable<Owner>;
|
public readonly ownerUpdate: Observable<Owner>;
|
||||||
private UserSub: Subscription = new Subscription();
|
|
||||||
private reqHeaders: HttpHeaders;
|
private reqHeaders: HttpHeaders;
|
||||||
|
private params : HttpParams;
|
||||||
private owner: Owner = {
|
private owner: Owner = {
|
||||||
_id: '',
|
_id: '',
|
||||||
name: '',
|
name: '',
|
||||||
|
@ -53,6 +54,8 @@ export class FullnodeService{
|
||||||
};
|
};
|
||||||
|
|
||||||
constructor(private http: HttpClient, public userService: UserService){
|
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');
|
var auth = 'Basic ' + Buffer.from(ConfigData.UsrPwd).toString('base64');
|
||||||
this.reqHeaders = new HttpHeaders().set('Authorization', auth);
|
this.reqHeaders = new HttpHeaders().set('Authorization', auth);
|
||||||
this.ownerUpdate = userService.ownerUpdate;
|
this.ownerUpdate = userService.ownerUpdate;
|
||||||
|
@ -65,7 +68,7 @@ export class FullnodeService{
|
||||||
}
|
}
|
||||||
|
|
||||||
getHeight(){
|
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) => {
|
obs.subscribe((BlockData) => {
|
||||||
this.dataStore.height = BlockData.height;
|
this.dataStore.height = BlockData.height;
|
||||||
this._heightUpdated.next(Object.assign({}, this.dataStore).height);
|
this._heightUpdated.next(Object.assign({}, this.dataStore).height);
|
||||||
|
@ -76,7 +79,7 @@ export class FullnodeService{
|
||||||
|
|
||||||
getPrice(currency: string){
|
getPrice(currency: string){
|
||||||
//var currency = 'usd';
|
//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'});
|
let obs = this.http.get<{message: string, price: any}>(this.beUrl+'api/price', { headers:this.reqHeaders, params: params, observe: 'response'});
|
||||||
obs.subscribe((PriceData) => {
|
obs.subscribe((PriceData) => {
|
||||||
if (PriceData.status == 200) {
|
if (PriceData.status == 200) {
|
||||||
|
@ -92,7 +95,7 @@ export class FullnodeService{
|
||||||
}
|
}
|
||||||
|
|
||||||
getAddr() {
|
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) => {
|
obs.subscribe((AddrData) => {
|
||||||
this.dataStore.addr = AddrData.addr;
|
this.dataStore.addr = AddrData.addr;
|
||||||
|
|
Loading…
Reference in a new issue