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

210 lines
5.4 KiB
TypeScript
Raw Normal View History

2022-01-22 13:49:22 +00:00
import { Component, OnInit, ViewChild, AfterViewInit } from '@angular/core';
2022-07-13 12:20:47 +00:00
import { UntypedFormBuilder, Validators, UntypedFormGroup, FormControl } 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';
import { filter, startWith, map, switchMap } from 'rxjs/operators';
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';
2022-01-19 20:50:00 +00:00
import { SearchOptionsPipe } from '../searchoptions.pipe';
2022-01-22 13:49:22 +00:00
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
@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 = '';
tickets = [
{
value: 0.005,
viewValue: '1 day: 0.005 ZEC'
},{
value: 0.025,
viewValue: '1 week: 0.025 ZEC'
},{
value: 0.1,
viewValue: '1 month: 0.1 ZEC'
}
];
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,
expiration: new Date(Date.now()).toISOString()
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>;
sessionId = '';
ownerKnown = false;
2022-01-28 20:03:35 +00:00
termsChecked = false;
2022-01-18 22:40:50 +00:00
constructor(
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-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 {
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-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,
expiration: new Date(Date.now()).toISOString()
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 = {
totalZec: this.payForm.get('session')!.value,
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) {
this.router.navigate(['/shop']);
}
});
}
2022-01-18 22:40:50 +00:00
}