zgo/src/app/business/business.component.ts

316 lines
9.7 KiB
TypeScript
Raw Normal View History

2022-08-26 17:36:15 +00:00
import { Component, OnInit, ViewChild } from '@angular/core';
import { UntypedFormBuilder, Validators, UntypedFormGroup } from '@angular/forms';
2022-01-22 13:49:22 +00:00
import { MatDialog, MatDialogConfig} from '@angular/material/dialog';
import { ProgressBarMode } from '@angular/material/progress-bar';
import { Router } from '@angular/router';
2022-01-19 20:50:00 +00:00
import { Observable } from 'rxjs';
2022-01-22 13:49:22 +00:00
import { MatStepper } from '@angular/material/stepper';
2022-01-28 20:03:35 +00:00
import { MatSlideToggleChange } from '@angular/material/slide-toggle';
2022-01-19 20:50:00 +00:00
import { Country } from '../country.model';
2022-01-18 22:40:50 +00:00
import { Owner } from '../owner.model';
2022-01-22 13:49:22 +00:00
import { User } from '../user.model';
2022-01-18 22:40:50 +00:00
import { UserService } from '../user.service';
2022-01-22 13:49:22 +00:00
import { FullnodeService } from '../fullnode.service';
import { ScanComponent } from '../scan/scan.component';
2022-01-28 20:03:35 +00:00
import { TermsComponent } from '../terms/terms.component';
2022-01-18 22:40:50 +00:00
import { LanguageService } from '../language.service';
import { LanguageData } from '../language.model';
2022-01-18 22:40:50 +00:00
@Component({
selector: 'app-business',
templateUrl: './business.component.html',
styleUrls: ['./business.component.css']
})
export class BusinessComponent implements OnInit {
2022-01-22 13:49:22 +00:00
@ViewChild('stepper', { static: false}) stepper: MatStepper|undefined;
2022-02-01 18:04:16 +00:00
intervalHolder: any;
2022-01-22 13:49:22 +00:00
nodeAddress: string = '';
2022-08-26 17:36:15 +00:00
zecPrice: number = 1;
2022-01-22 13:49:22 +00:00
tickets = [
{
2022-08-26 17:36:15 +00:00
value: 1,
viewValue: '1 day: USD $1'
2022-01-22 13:49:22 +00:00
},{
2022-08-26 17:36:15 +00:00
value: 6,
viewValue: '1 week: USD $6'
2022-01-22 13:49:22 +00:00
},{
2022-08-26 17:36:15 +00:00
value: 22,
viewValue: '1 month: USD $22'
},{
value: 30,
viewValue: '1 month Pro: USD $30'
2022-01-22 13:49:22 +00:00
}
];
2022-07-13 12:20:47 +00:00
bizForm: UntypedFormGroup;
payForm: UntypedFormGroup;
2022-01-22 13:49:22 +00:00
barMessage = 'Awaiting for transaction';
barMode: ProgressBarMode = 'indeterminate';
barValue = 0;
2022-01-19 20:50:00 +00:00
countries: Country[] = [];
2022-01-22 13:49:22 +00:00
owner: Owner = {
address: '',
currency: 'usd',
tax: false,
taxValue: 0,
vat: false,
vatValue: 0,
phone: '',
paid: false,
2022-01-28 20:03:35 +00:00
first: '',
last: '',
2022-01-22 13:49:22 +00:00
name: '',
street: '',
city: '',
state: '',
postal: '',
country: '',
email: '',
2022-03-07 17:14:29 +00:00
website: '',
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: ''
2022-01-22 13:49:22 +00:00
}
2022-01-19 20:50:00 +00:00
public countriesUpdate: Observable<Country[]>;
2022-01-22 13:49:22 +00:00
public ownerUpdate: Observable<Owner>;
public addrUpdate: Observable<string>;
public userUpdate: Observable<User>;
2022-08-26 17:36:15 +00:00
public priceUpdate: Observable<number>;
2022-01-22 13:49:22 +00:00
sessionId = '';
ownerKnown = false;
2022-01-28 20:03:35 +00:00
termsChecked = false;
// -------------------------------------
//
// Language Support
//
vE = {
businessSignupTitle : '',
businessBizInfo : '',
businessAddrsNobiz : '',
businessBizNamelbl : '',
businessBizNameholder : '',
businessContactFnamelbl : '',
businessContactFnholder : '',
businessContactLnamelbl : '',
businessContactLnholder : '',
businessBizAddresslbl : '',
businessBizAddressholder : '',
businessBizCitylbl : '',
businessBizCityholder : '',
businessBizStatelbl : '',
businessBizStateholder : '',
businessBizPcodelbl : '',
businessBizPcodeholder : '',
businessBizCountrylbl : '',
businessBizCountryholder : '',
businessBizMaillbl : '',
businessBizMailholder : '',
businessBizWebsitelbl : '',
businessBizWebsiteholder : '',
businessAcceptTerms : '',
businessTermsOfuse : '',
businessSaveBtn : '',
businessSessionLengthlbl : '',
businessSelectSession : '',
businessSessionLabel : '',
businessSessionPaylbl : '',
businessZGoConfirmlbl : ''
2022-01-18 22:40:50 +00:00
};
//
//
2022-01-18 22:40:50 +00:00
constructor(
private languageService : LanguageService,
2022-07-13 12:20:47 +00:00
private fb: UntypedFormBuilder,
2022-01-22 13:49:22 +00:00
private userService: UserService,
private fullnodeService: FullnodeService,
private dialog: MatDialog,
private router: Router
2022-01-18 22:40:50 +00:00
) {
2022-08-26 17:36:15 +00:00
this.priceUpdate = fullnodeService.priceUpdate;
this.priceUpdate.subscribe(priceInfo => {
this.zecPrice = priceInfo;
});
2022-01-19 20:50:00 +00:00
this.countriesUpdate = userService.countriesUpdate;
2022-01-22 13:49:22 +00:00
this.ownerUpdate = userService.ownerUpdate;
this.userUpdate = userService.userUpdate;
this.userUpdate.subscribe(userInfo => {
this.sessionId = userInfo.session;
});
this.addrUpdate = fullnodeService.addrUpdate;
this.addrUpdate.subscribe(nodeAdd => {
this.nodeAddress = nodeAdd;
});
2022-01-18 22:40:50 +00:00
this.bizForm = fb.group({
2022-01-19 20:50:00 +00:00
name: ['', Validators.required],
2022-01-28 20:03:35 +00:00
first: ['', Validators.required],
last: ['', Validators.required],
2022-01-19 20:50:00 +00:00
street: ['', Validators.required],
city: ['', Validators.required],
state: ['', Validators.required],
postal: ['', Validators.required],
country: ['', Validators.required],
2022-01-22 13:49:22 +00:00
email: ['', [Validators.email, Validators.required]],
2022-01-28 20:03:35 +00:00
website: [''],
terms: [false]
2022-01-22 13:49:22 +00:00
});
this.payForm= fb.group({
session: ['', Validators.required]
2022-01-19 20:50:00 +00:00
});
this.userService.getCountries();
this.countriesUpdate.subscribe((countries) => {
this.countries = countries;
2022-01-18 22:40:50 +00:00
});
2022-01-22 13:49:22 +00:00
this.ownerUpdate.subscribe((owner) => {
this.owner = owner;
});
2022-01-18 22:40:50 +00:00
}
ngOnInit(): void {
this.chgUILanguage();
2022-02-01 18:04:16 +00:00
this.intervalHolder = setInterval(() => {
this.loginCheck();
}, 1000 * 60);
2022-01-18 22:40:50 +00:00
}
2022-01-22 13:49:22 +00:00
ngAfterViewInit(): void {
this.ownerUpdate.subscribe(ownerData => {
if(ownerData.name.length > 0 && this.stepper!.selectedIndex == 0){
this.stepper!.next();
2022-07-14 16:11:04 +00:00
this.loginCheck();
2022-01-22 13:49:22 +00:00
}
});
}
2022-01-28 20:03:35 +00:00
onChange(ob: MatSlideToggleChange){
console.log(ob.checked);
this.termsChecked = ob.checked;
}
showTerms() {
const dialogConfig = new MatDialogConfig();
dialogConfig.disableClose = true;
dialogConfig.autoFocus = true;
const dialogRef = this.dialog.open(TermsComponent, dialogConfig);
dialogRef.afterClosed().subscribe(val => {
console.log('Terms read');
});
}
2022-01-22 13:49:22 +00:00
save() {
this.owner = {
2022-05-18 20:51:39 +00:00
_id: '',
2022-01-22 13:49:22 +00:00
address: '',
currency: 'usd',
tax: false,
taxValue: 0,
vat: false,
vatValue: 0,
2022-02-01 18:04:16 +00:00
first: this.bizForm.get('first')!.value,
last: this.bizForm.get('last')!.value,
2022-01-22 13:49:22 +00:00
phone: '',
paid: false,
name: this.bizForm.get('name')!.value,
street: this.bizForm.get('street')!.value,
city: this.bizForm.get('city')!.value,
state: this.bizForm.get('state')!.value,
postal: this.bizForm.get('postal')!.value,
country: this.bizForm.get('country')!.value,
email: this.bizForm.get('email')!.value,
2022-03-07 17:14:29 +00:00
website: this.bizForm.get('website')!.value,
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: ''
2022-01-22 13:49:22 +00:00
};
this.userService.addOwner(this.owner);
this.stepper!.next();
}
pay(){
const dialogConfig = new MatDialogConfig();
dialogConfig.disableClose = true;
dialogConfig.autoFocus = true;
dialogConfig.data = {
2022-08-26 17:36:15 +00:00
totalZec: (this.payForm.get('session')!.value)/this.zecPrice,
2022-01-22 13:49:22 +00:00
addr: this.nodeAddress,
session: this.sessionId,
pay: true
};
const dialogRef = this.dialog.open(ScanComponent, dialogConfig);
dialogRef.afterClosed().subscribe(val => {
console.log('Awaiting payment');
if(val){
this.stepper!.next();
}
});
}
2022-02-01 18:04:16 +00:00
loginCheck(){
2022-02-02 18:26:58 +00:00
this.userService.findUser();
2022-02-01 18:04:16 +00:00
this.ownerUpdate.subscribe((owner) => {
if(owner.paid) {
2022-07-26 16:26:42 +00:00
clearInterval(this.intervalHolder);
2022-02-01 18:04:16 +00:00
this.router.navigate(['/shop']);
}
});
}
chgUILanguage(){
console.log('BUSINESS.chgUILanguage Called ');
this.languageService.getViewElements('business').subscribe(
response => {
console.log('Received >> ', response );
console.log('Language Code : ', response.language);
console.log('Component Name : ',response.component);
console.log('Language data : ',response.data);
this.vE.businessSignupTitle = response.data.business_signup_title;
this.vE.businessBizInfo = response.data.business_biz_info;
this.vE.businessAddrsNobiz = response.data.business_addrs_nobiz;
this.vE.businessBizNamelbl = response.data.business_biz_namelbl;
this.vE.businessBizNameholder = response.data.business_biz_nameholder;
this.vE.businessContactFnamelbl = response.data.business_contact_fnamelbl;
this.vE.businessContactFnholder = response.data.business_contact_fnholder;
this.vE.businessContactLnamelbl = response.data.business_contact_lnamelbl;
this.vE.businessBizAddresslbl = response.data.business_biz_addresslbl;
this.vE.businessBizAddressholder = response.data.business_biz_addressholder;
this.vE.businessBizCitylbl = response.data.business_biz_citylbl;
this.vE.businessBizCityholder = response.data.business_biz_cityholder;
this.vE.businessBizStatelbl = response.data.business_biz_statelbl;
this.vE.businessBizStateholder = response.data.business_biz_stateholder;
this.vE.businessBizPcodelbl = response.data.business_biz_pcodelbl;
this.vE.businessBizPcodeholder = response.data.business_biz_pcodeholder;
this.vE.businessBizCitylbl = response.data.business_biz_citylbl;
this.vE.businessBizCityholder = response.data.business_biz_cityholder;
this.vE.businessBizCountrylbl = response.data.business_biz_countrylbl;
this.vE.businessBizCountryholder = response.data.business_biz_countryholder;
this.vE.businessBizMaillbl = response.data.business_biz_maillbl;
this.vE.businessBizMailholder = response.data.business_biz_mailholder;
this.vE.businessBizWebsitelbl = response.data.business_biz_websitelbl;
this.vE.businessBizWebsiteholder = response.data.business_biz_websiteholder;
this.vE.businessAcceptTerms = response.data.business_accept_terms;
this.vE.businessTermsOfuse = response.data.business_terms_ofuse;
this.vE.businessSaveBtn = response.data.business_save_btn;
this.vE.businessSessionLengthlbl = response.data.business_session_lengthlbl;
this.vE.businessSelectSession = response.data.business_select_session;
this.vE.businessSessionLabel = response.data.business_session_label;
this.vE.businessSessionPaylbl = response.data.business_session_paylbl;
this.vE.businessZGoConfirmlbl = response.data.business_zgo_confirmlbl;
},
error => { console.log('Error >> ',error); }
);
}
2022-01-18 22:40:50 +00:00
}