zgo/src/app/fullnode.service.ts

107 lines
3.5 KiB
TypeScript
Raw Normal View History

2021-10-15 19:14:49 +00:00
import {Injectable} from '@angular/core';
2021-10-20 20:51:14 +00:00
import {Subject, Subscription, BehaviorSubject, Observable} from 'rxjs';
2021-11-09 18:39:16 +00:00
import {HttpClient, HttpParams, HttpHeaders} from '@angular/common/http';
2021-10-15 19:14:49 +00:00
import {UserService} from './user.service';
2021-11-22 20:37:45 +00:00
import { Owner } from './owner.model';
2021-10-15 19:14:49 +00:00
import { ConfigData } from './configdata';
2022-05-18 20:51:39 +00:00
var Buffer = require('buffer/').Buffer;
2021-10-15 19:14:49 +00:00
//import {User} from './user.model';
@Injectable({providedIn: 'root'})
export class FullnodeService{
beUrl = ConfigData.Be_URL;
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);
private _addrUpdated: BehaviorSubject<string> = new BehaviorSubject(this.dataStore.addr);
private _priceUpdated: BehaviorSubject<number> = new BehaviorSubject(this.dataStore.price);
2021-10-20 20:51:14 +00:00
public readonly addrUpdate: Observable<string> = this._addrUpdated.asObservable();
public readonly heightUpdate: Observable<number> = this._heightUpdated.asObservable();
public readonly memoUpdate: Observable<string[]> = this._memoUpdated.asObservable();
public readonly priceUpdate: Observable<number> = this._priceUpdated.asObservable();
2021-11-22 20:37:45 +00:00
public readonly ownerUpdate: Observable<Owner>;
2021-10-20 20:51:14 +00:00
private UserSub: Subscription = new Subscription();
2021-11-09 18:39:16 +00:00
private reqHeaders: HttpHeaders;
2021-11-22 20:37:45 +00:00
private owner: Owner = {
_id: '',
name: '',
address: '',
currency: 'usd',
tax: false,
taxValue: 0,
vat: false,
2022-01-17 20:49:08 +00:00
vatValue: 0,
2022-01-28 20:03:35 +00:00
first: '',
last: '',
2022-01-17 20:49:08 +00:00
email: '',
street: '',
city: '',
state: '',
postal: '',
phone: '',
2022-01-18 22:40:20 +00:00
paid: false,
2022-01-19 16:26:25 +00:00
website: '',
2022-03-07 17:14:29 +00:00
country: '',
2022-05-18 20:51:39 +00:00
zats: false,
invoices: false,
2022-07-14 16:11:04 +00:00
expiration: new Date(Date.now()).toISOString(),
2022-07-18 20:29:27 +00:00
payconf: false,
2022-08-31 13:56:06 +00:00
viewkey: '',
crmToken: ''
2021-11-22 20:37:45 +00:00
};
2021-10-15 19:14:49 +00:00
constructor(private http: HttpClient, public userService: UserService){
var auth = 'Basic ' + Buffer.from(ConfigData.UsrPwd).toString('base64');
Implement Data Export Squashed commit of the following: commit 0c63521f38df66cd8a3d20e67d7b653f42f6b1bc Author: Rene Vergara <rene@vergara.network> Date: Tue Oct 11 14:18:20 2022 -0500 Update version commit f80232d9119a4a7ba94b0659ff13419857bffca5 Author: Rene Vergara <rene@vergara.network> Date: Tue Oct 11 11:52:56 2022 -0500 Adjust look and feel for data export commit 53c3d5e78effc26de14d9cc72e734fc7f7e81cb7 Author: Rene Vergara A <rvergara59@protonmail.com> Date: Sun Oct 9 09:40:58 2022 -0500 Db-export component ready for testing commit d4cdcd2a9a3eb0c53f5c0365e9a11298b6b15b36 Merge: da4413a 41b899b Author: Rene Vergara A <rvergara59@protonmail.com> Date: Sat Oct 8 09:08:33 2022 -0500 Merge branch 'master' of https://gitlab.com/pitmutt/zgo into dbexport commit da4413af853a6b5846a03455beb91321e98405a8 Author: Rene Vergara A <rvergara59@protonmail.com> Date: Sat Oct 8 09:06:56 2022 -0500 Data Export component in progress... commit 98d9360aad597c4ba66d54607e008222f3c58371 Author: Rene Vergara A <rvergara59@protonmail.com> Date: Fri Oct 7 18:05:36 2022 -0500 Angular updated to v14 - core commit e78d4efa46e691ed830fc8824aa5fa0986968a7c Author: Rene Vergara A <rvergara59@protonmail.com> Date: Fri Oct 7 17:59:17 2022 -0500 Angular updated to v14 - cli commit 9f2afbbff945bc24487e1798bd6a50ff231f6ae9 Author: Rene Vergara A <rvergara59@protonmail.com> Date: Fri Oct 7 17:52:44 2022 -0500 Angular updated to v14 commit 21b1866a091a689ead4f197717afd3f2ed1f1d9e Merge: 3936371 72f4d67 Author: Rene Vergara A <rvergara59@protonmail.com> Date: Fri Oct 7 17:31:41 2022 -0500 Merge branch 'master' of https://gitlab.com/pitmutt/zgo into xero commit 3936371c971a1bb4eaec7cc06ee3fb97e5a07782 Author: Rene Vergara A <rvergara59@protonmail.com> Date: Fri Oct 7 17:31:24 2022 -0500 Initial programming of Data Export commit 7c9b4ef43a8fdb891d3ffa2bb39bd8da1a776a17 Author: Rene Vergara A <rvergara59@protonmail.com> Date: Thu Sep 22 16:58:59 2022 -0500 Few updates
2022-10-11 19:20:06 +00:00
console.log('auth: ' + auth);
2022-05-18 20:51:39 +00:00
this.reqHeaders = new HttpHeaders().set('Authorization', auth);
Implement Data Export Squashed commit of the following: commit 0c63521f38df66cd8a3d20e67d7b653f42f6b1bc Author: Rene Vergara <rene@vergara.network> Date: Tue Oct 11 14:18:20 2022 -0500 Update version commit f80232d9119a4a7ba94b0659ff13419857bffca5 Author: Rene Vergara <rene@vergara.network> Date: Tue Oct 11 11:52:56 2022 -0500 Adjust look and feel for data export commit 53c3d5e78effc26de14d9cc72e734fc7f7e81cb7 Author: Rene Vergara A <rvergara59@protonmail.com> Date: Sun Oct 9 09:40:58 2022 -0500 Db-export component ready for testing commit d4cdcd2a9a3eb0c53f5c0365e9a11298b6b15b36 Merge: da4413a 41b899b Author: Rene Vergara A <rvergara59@protonmail.com> Date: Sat Oct 8 09:08:33 2022 -0500 Merge branch 'master' of https://gitlab.com/pitmutt/zgo into dbexport commit da4413af853a6b5846a03455beb91321e98405a8 Author: Rene Vergara A <rvergara59@protonmail.com> Date: Sat Oct 8 09:06:56 2022 -0500 Data Export component in progress... commit 98d9360aad597c4ba66d54607e008222f3c58371 Author: Rene Vergara A <rvergara59@protonmail.com> Date: Fri Oct 7 18:05:36 2022 -0500 Angular updated to v14 - core commit e78d4efa46e691ed830fc8824aa5fa0986968a7c Author: Rene Vergara A <rvergara59@protonmail.com> Date: Fri Oct 7 17:59:17 2022 -0500 Angular updated to v14 - cli commit 9f2afbbff945bc24487e1798bd6a50ff231f6ae9 Author: Rene Vergara A <rvergara59@protonmail.com> Date: Fri Oct 7 17:52:44 2022 -0500 Angular updated to v14 commit 21b1866a091a689ead4f197717afd3f2ed1f1d9e Merge: 3936371 72f4d67 Author: Rene Vergara A <rvergara59@protonmail.com> Date: Fri Oct 7 17:31:41 2022 -0500 Merge branch 'master' of https://gitlab.com/pitmutt/zgo into xero commit 3936371c971a1bb4eaec7cc06ee3fb97e5a07782 Author: Rene Vergara A <rvergara59@protonmail.com> Date: Fri Oct 7 17:31:24 2022 -0500 Initial programming of Data Export commit 7c9b4ef43a8fdb891d3ffa2bb39bd8da1a776a17 Author: Rene Vergara A <rvergara59@protonmail.com> Date: Thu Sep 22 16:58:59 2022 -0500 Few updates
2022-10-11 19:20:06 +00:00
console.log(this.reqHeaders);
2021-11-22 20:37:45 +00:00
this.ownerUpdate = userService.ownerUpdate;
this.getAddr();
this.getHeight();
2021-11-22 20:37:45 +00:00
this.ownerUpdate.subscribe((owner) => {
this.owner = owner;
this.getPrice(this.owner.currency);
});
2021-10-15 19:14:49 +00:00
}
2021-10-20 20:51:14 +00:00
getHeight(){
2021-11-09 18:39:16 +00:00
let obs = this.http.get<{message: string, height: number}>(this.beUrl+'api/blockheight', { headers: this.reqHeaders });
2021-10-20 20:51:14 +00:00
obs.subscribe((BlockData) => {
this.dataStore.height = BlockData.height;
this._heightUpdated.next(Object.assign({}, this.dataStore).height);
2021-10-15 19:14:49 +00:00
});
2021-10-20 20:51:14 +00:00
return obs;
2021-10-15 19:14:49 +00:00
}
2021-11-22 20:37:45 +00:00
getPrice(currency: string){
//var currency = 'usd';
2021-11-02 21:13:24 +00:00
const params = new HttpParams().append('currency', currency);
2021-11-09 18:39:16 +00:00
let obs = this.http.get<{message: string, price: any}>(this.beUrl+'api/price', { headers:this.reqHeaders, params: params, observe: 'response'});
obs.subscribe((PriceData) => {
2021-11-02 21:13:24 +00:00
if (PriceData.status == 200) {
this.dataStore.price = PriceData.body!.price.price;
console.log("price", this.dataStore.price);
this._priceUpdated.next(Object.assign({},this.dataStore).price);
} else {
console.log('No price found for currency', currency);
}
});
return obs;
}
2021-10-20 20:51:14 +00:00
2021-10-15 19:14:49 +00:00
getAddr() {
2021-11-09 18:39:16 +00:00
let obs = this.http.get<{message: string, addr: string}>(this.beUrl+'api/getaddr', { headers: this.reqHeaders });
obs.subscribe((AddrData) => {
this.dataStore.addr = AddrData.addr;
this._addrUpdated.next(Object.assign({}, this.dataStore).addr);
2021-10-15 19:14:49 +00:00
});
return obs;
2021-10-15 19:14:49 +00:00
}
}