Modify services to use new API endpoints

This commit is contained in:
Rene Vergara 2023-05-12 09:02:45 -05:00
parent 8628f79043
commit 28012ee2a9
Signed by: pitmutt
GPG key ID: 65122AD495A7F5B2
11 changed files with 96 additions and 85 deletions

View file

@ -1,5 +1,7 @@
# ZGo - The Zcash Register
[![Please don't upload to GitHub](https://nogithub.codeberg.page/badge.svg)](https://nogithub.codeberg.page)
A Point-of-Sale application for accepting payments in [Zcash](https://z.cash/)
Visit our [ZGo Homepage](https://zgo.cash/) for more details.

View file

@ -1,8 +1,6 @@
import { Component, OnInit } from '@angular/core';
import { LanguageService } from './language.service';
import { LanguageData } from './language.model';
//import { Post} from './posts/post.model';
@Component({
selector: 'app-root',

View file

@ -2,7 +2,8 @@ import { Injectable } from '@angular/core';
import { Router, RouterStateSnapshot, ActivatedRouteSnapshot } from '@angular/router';
import {HttpClient, HttpParams} from '@angular/common/http';
import { UserService } from './user.service';
import { Subscription, Observable } from 'rxjs';
import { Observable } from 'rxjs';
@Injectable()
@ -12,44 +13,39 @@ export class AuthGuardService {
private paidUpdate: Observable<boolean>;
constructor(
private router: Router,
private http: HttpClient,
public userService: UserService
){
this.userService.findUser();
this.paidUpdate = this.userService.paidUpdate;
this.paidUpdate.subscribe((indicator) => {
this.paid = indicator;
});
}
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
const token = localStorage.getItem('s4z_token');
var path = route.url[0].path;
if(token != null){
this.userService.uZaddrUpdate.
subscribe((addr) => {
if (addr != null) {
//console.log(addr);
this.addr = addr;
if (path === 'biz') {
this.userService.checkUser()?.subscribe( response => {
if (response.status == 200 && response.body?.validated) {
return true;
} else {
console.log("No record for that token");
this.router.navigate(['/login']);
return false;
}
});
if (path === 'biz') {
if (this.addr.length > 0) {
return true;
} else {
this.router.navigate(['/login']);
return false;
}
} else {
if (this.addr != null && this.paid) {
} else {
this.userService.checkUser()?.subscribe( response => {
if (response.status == 200 && response.body?.validated && this.paid) {
return true;
} else {
this.router.navigate(['/login']);
return false;
}
});
}
} else {
console.log("Not logged in");

View file

@ -57,7 +57,7 @@ export class FullnodeService{
}
getHeight(){
let obs = this.http.get<{message: string, height: number}>(this.beUrl+'api/blockheight', { headers: this.reqHeaders, params: this.params });
let obs = this.http.get<{message: string, height: number}>(this.beUrl+'blockheight', { headers: this.reqHeaders, params: this.params });
obs.subscribe((BlockData) => {
this.dataStore.height = BlockData.height;
this._heightUpdated.next(Object.assign({}, this.dataStore).height);
@ -69,7 +69,7 @@ export class FullnodeService{
getPrice(currency: string){
//var currency = 'usd';
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+'price', { headers:this.reqHeaders, params: params, observe: 'response'});
obs.subscribe((PriceData) => {
if (PriceData.status == 200) {
this.dataStore.price = PriceData.body!.price.price;
@ -84,7 +84,7 @@ export class FullnodeService{
}
getAddr() {
let obs = this.http.get<{message: string, addr: string}>(this.beUrl+'api/getaddr', { headers: this.reqHeaders, params: this.params });
let obs = this.http.get<{message: string, addr: string}>(this.beUrl+'getaddr', { headers: this.reqHeaders, params: this.params });
obs.subscribe((AddrData) => {
this.dataStore.addr = AddrData.addr;

View file

@ -19,6 +19,9 @@ export class LanguageService {
//
// URL for access MongoDB database from remote server
private baseURL = ConfigData.Be_URL + 'api/getlang';
private loginURL = ConfigData.Be_URL + 'getloginlang';
private mainURL = ConfigData.Be_URL + 'getmainlang';
private scanURL = ConfigData.Be_URL + 'getscanlang';
public zgoLanguage: string = '';
@ -49,6 +52,13 @@ export class LanguageService {
// Get component's text data from language database
//
const params = new HttpParams().append('session', this.session!);
if (viewName === 'login') {
return this.http.get<LanguageData>(this.loginURL + '/?lang=' + this.zgoLanguage, {headers: reqHeaders, params: params});
} else if (viewName === 'main') {
return this.http.get<LanguageData>(this.mainURL + '/?lang=' + this.zgoLanguage, {headers: reqHeaders, params: params});
} else if (viewName === 'scan') {
return this.http.get<LanguageData>(this.scanURL + '/?lang=' + this.zgoLanguage, {headers: reqHeaders, params: params});
} else {
return this.http.get<LanguageData>(this.baseURL +
'/?lang=' + this.zgoLanguage +
'&component=' + viewName
@ -57,4 +67,5 @@ export class LanguageService {
}
);
}
}
}

View file

@ -2,7 +2,7 @@
<mat-card class="coolcard">
<mat-card-content>
<img mat-card-image src="/assets/logo-new-white_01.png" height="120px" />
<p class="text">{{ vE.loginLastBlock }}<span class="numbers">{{ heightUpdate | async }}</span></p>
<p class="text">{{ vE.loginLastBlock }}<span class="numbers"> {{ heightUpdate | async }}</span></p>
</mat-card-content>
</mat-card>
</div>

View file

@ -56,7 +56,7 @@ export class LoginComponent implements OnInit, AfterViewInit {
public uZaddrUpdate: Observable<string>;
public userUpdate: Observable<User>;
public ownerUpdate: Observable<Owner>;
public txsUpdate: Observable<Tx[]>;
//public txsUpdate: Observable<Tx[]>;
prompt: boolean = false;
confirmedMemo: boolean = false;
targetBlock: number = 0;
@ -65,7 +65,6 @@ export class LoginComponent implements OnInit, AfterViewInit {
barMessage = 'Scanning blockchain for login memo, please wait.';
@ViewChild('stepper') private myStepper?: MatStepper;
entryForm: UntypedFormGroup;
pinForm: UntypedFormGroup;
//
@ -95,9 +94,6 @@ export class LoginComponent implements OnInit, AfterViewInit {
){
//this.fullnodeService.getAddr();
this.entryForm = fb.group({
selectedSession: [0.001, Validators.required]
});
this.pinForm = fb.group({
pinValue: [null, Validators.required]
});
@ -111,10 +107,10 @@ export class LoginComponent implements OnInit, AfterViewInit {
this.ownerUpdate.subscribe((owner) => {
this.owner = owner;
});
this.txsUpdate = userService.txUpdate;
this.txsUpdate.subscribe((txs) => {
this.txs = txs;
});
//this.txsUpdate = userService.txUpdate;
//this.txsUpdate.subscribe((txs) => {
//this.txs = txs;
//});
}
ngAfterViewInit(){
@ -141,16 +137,16 @@ export class LoginComponent implements OnInit, AfterViewInit {
this.chgUILanguage();
this.intervalHolder = setInterval(() => {
this.fullnodeService.getHeight();
//this.userService.findUser();
this.loginCheck();
this._changeDetectorRef.markForCheck();
}, 1000 * 60);
}
loginCheck(){
this.userService.findUser();
this.userUpdate.subscribe((user) => {
if (user.blocktime > 0) {
this.userService.checkUser()!.subscribe({
next: (checkResponse) => {
if (checkResponse.status == 200) {
console.log('checkUser true');
if(this.myStepper!.selectedIndex === 0) {
this.myStepper!.next();
this.myStepper!.next();
@ -159,16 +155,17 @@ export class LoginComponent implements OnInit, AfterViewInit {
this.myStepper!.next();
}
}
//console.log('Log in found in blockchain!');
if (user.validated) {
clearInterval(this.intervalHolder);
if (this.owner.paid) {
this.router.navigate(['/shop']);
} else {
if(checkResponse.body!.validated) {
console.log('redirecting to biz');
this.userService.getOwner();
this.router.navigate(['/biz']);
clearInterval(this.intervalHolder);
} else {
console.log('validated failed');
}
}
}
},
error: (error) => {console.log(error);}
});
}

View file

@ -79,7 +79,7 @@ export class ReceiptService {
if (OrderDataResponse.status == 200) {
this.dataStore.order = OrderDataResponse.body!.order;
this._orderUpdated.next(Object.assign({}, this.dataStore).order);
this.userService.getOwner(this.dataStore.order.address);
this.userService.getOwner();
this.ownerUpdate.subscribe((owner) => {
this.dataStore.owner = owner;
this._nameUpdated.next(Object.assign({}, this.dataStore).owner.name);

View file

@ -5,7 +5,6 @@ import { DomSanitizer, SafeUrl } from '@angular/platform-browser';
import { NotifierService } from '../notifier.service';
import { LanguageService } from '../language.service';
import { LanguageData } from '../language.model';
var QRCode = require('easyqrcodejs');
var URLSafeBase64 = require('urlsafe-base64');
@ -148,13 +147,14 @@ export class ScanComponent implements OnInit{
}
chgUILanguage(){
console.log('SCAN.chgUILanguage Called ');
this.languageService.getViewElements('scan').subscribe(
//console.log('SCAN.chgUILanguage Called ');
this.languageService.getViewElements('scan').subscribe({
next:
response => {
console.log('Received >> ', response );
console.log('Language Code : ', response.language);
console.log('Component Name : ',response.component);
console.log('Language data : ',response.data);
//console.log('Received >> ', response );
//console.log('Language Code : ', response.language);
//console.log('Component Name : ',response.component);
//console.log('Language data : ',response.data);
this.vE.scanScanqrCode = response.data.scan_scanqr_code;
this.vE.scanTextInfo = response.data.scan_text_info;
@ -172,8 +172,8 @@ export class ScanComponent implements OnInit{
this.vE.scanOrButton = response.data.scan_or_button;
},
error => { console.log('Error >> ',error); }
);
error: error => { console.log('Error >> ',error); }
});
}
}

View file

@ -8,7 +8,6 @@ import { NotifierService } from './notifier.service';
import { User } from './user.model';
import { Owner } from './owner.model';
import { Country } from './country.model';
import { Tx } from './tx.model';
import { ConfigData } from './configdata';
@ -18,7 +17,7 @@ var Buffer = require('buffer/').Buffer;
export class UserService{
beUrl = ConfigData.Be_URL;
private dataStore: { user: User, owner: Owner, txs: Tx[], countries: Country[]} = {
private dataStore: { user: User, owner: Owner, countries: Country[]} = {
user: {
address: '',
session: '',
@ -41,7 +40,6 @@ export class UserService{
payconf: false,
crmToken: ''
},
txs : [],
countries: []
};
private uZaddr = '';
@ -49,13 +47,11 @@ export class UserService{
private _uZaddrUpdated: BehaviorSubject<string> = new BehaviorSubject(this.uZaddr);
private _userUpdated: BehaviorSubject<User> = new BehaviorSubject(this.dataStore.user);
private _ownerUpdated: BehaviorSubject<Owner> = new BehaviorSubject(this.dataStore.owner);
private _txsUpdated: BehaviorSubject<Tx[]> = new BehaviorSubject(this.dataStore.txs);
private _paidUpdated: BehaviorSubject<boolean> = new BehaviorSubject(this.dataStore.owner.paid);
private _countriesUpdated: BehaviorSubject<Country[]> = new BehaviorSubject(this.dataStore.countries);
public readonly uZaddrUpdate: Observable<string> = this._uZaddrUpdated.asObservable();
public readonly ownerUpdate: Observable<Owner> = this._ownerUpdated.asObservable();
public readonly userUpdate: Observable<User> = this._userUpdated.asObservable();
public readonly txUpdate: Observable<Tx[]> = this._txsUpdated.asObservable();
public readonly paidUpdate: Observable<boolean> = this._paidUpdated.asObservable();
public readonly countriesUpdate: Observable<Country[]> = this._countriesUpdated.asObservable();
private reqHeaders: HttpHeaders;
@ -68,9 +64,9 @@ export class UserService{
//console.log('US:', this.reqHeaders);
this.session = localStorage.getItem('s4z_token');
this.reqParams = new HttpParams().append('session', this.session!);
if (this.session != null) {
this.findUser();
}
//if (this.session != null) {
//this.findUser();
//}
}
getCountries() {
@ -84,6 +80,17 @@ export class UserService{
});
}
checkUser() {
if (this.session != null) {
console.log('calling checkUser');
let obs = this.http.get<{validated: boolean}>(this.beUrl + 'checkuser', {headers: this.reqHeaders, params: this.reqParams, observe: 'response'});
return obs;
} else {
return null;
}
}
findUser() {
if (this.session != null) {
let obs = this.http.get<{message: string, user: any}>(this.beUrl+'api/user', { headers: this.reqHeaders, params: this.reqParams, observe: 'response'});
@ -95,7 +102,7 @@ export class UserService{
//console.log(`US: Found user, returning it`);
this._uZaddrUpdated.next(Object.assign({},this.dataStore).user.address);
this._userUpdated.next(Object.assign({}, this.dataStore).user);
this.getOwner(Object.assign({},this.dataStore.user).address);
this.getOwner();
} else {
this.dataStore.user = {
address: '',
@ -140,7 +147,7 @@ export class UserService{
obs.subscribe({
next: () => {
//console.log("Entra a console log");
this.getOwner(this.dataStore.user.address);
this.getOwner();
},
error: (error) => {
//console.log("Status is : [" + error.status + "]");
@ -153,10 +160,10 @@ export class UserService{
return obs;
}
getOwner(address: string) {
getOwner() {
//console.log('getOwner', address);
const ownParams = this.reqParams.append('address', address)
let obs = this.http.get<{message:string, owner: any}>(this.beUrl+'api/owner', { headers: this.reqHeaders, params: ownParams, observe: 'response'});
//const ownParams = this.reqParams.append('address', address)
let obs = this.http.get<{message:string, owner: any}>(this.beUrl+'api/owner', { headers: this.reqHeaders, params: this.reqParams, observe: 'response'});
obs.subscribe((OwnerDataResponse) => {
//console.log('api/getowner', OwnerDataResponse.status);

View file

@ -6,7 +6,7 @@
"outDir": "./dist/out-tsc",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitReturns": true,
"noImplicitReturns": false,
"noFallthroughCasesInSwitch": true,
"sourceMap": true,
"declaration": false,