2021-10-25 20:01:06 +00:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
2021-10-27 20:21:55 +00:00
|
|
|
import { MatDialog, MatDialogConfig} from '@angular/material/dialog';
|
2021-10-25 20:01:06 +00:00
|
|
|
import { Observable } from 'rxjs';
|
|
|
|
import { Order } from './order.model';
|
|
|
|
import { FullnodeService } from '../fullnode.service';
|
|
|
|
import { UserService } from '../user.service';
|
|
|
|
import { OrderService } from './order.service';
|
2021-10-27 20:21:55 +00:00
|
|
|
import { CancelComponent } from '../cancel/cancel.component';
|
2021-10-28 18:22:54 +00:00
|
|
|
import { CheckoutComponent} from '../checkout/checkout.component';
|
2021-10-25 20:01:06 +00:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-order',
|
|
|
|
templateUrl: './order.component.html',
|
|
|
|
styleUrls: ['./order.component.css']
|
|
|
|
})
|
|
|
|
|
|
|
|
export class OrderComponent implements OnInit{
|
2021-10-27 12:59:43 +00:00
|
|
|
public order: Order = {address: '', session: '', timestamp: '', closed: false, lines: [{qty: 1, name: '', cost: 0}]};
|
2021-10-25 20:01:06 +00:00
|
|
|
public price: number = 1;
|
2021-10-27 20:21:55 +00:00
|
|
|
public total: number = 0;
|
2021-10-25 20:01:06 +00:00
|
|
|
public orderUpdate: Observable<Order>;
|
|
|
|
public priceUpdate: Observable<number>;
|
2021-10-27 20:21:55 +00:00
|
|
|
public totalUpdate: Observable<number>;
|
2021-10-25 20:01:06 +00:00
|
|
|
|
|
|
|
constructor(
|
|
|
|
public fullnodeService: FullnodeService,
|
2021-10-27 20:21:55 +00:00
|
|
|
public orderService: OrderService,
|
|
|
|
private dialog: MatDialog
|
2021-10-25 20:01:06 +00:00
|
|
|
) {
|
|
|
|
this.priceUpdate = fullnodeService.priceUpdate;
|
2021-10-27 20:21:55 +00:00
|
|
|
this.priceUpdate.subscribe((price) => {
|
|
|
|
this.price = price;
|
|
|
|
});
|
2021-10-25 20:01:06 +00:00
|
|
|
this.orderUpdate = orderService.orderUpdate;
|
2021-10-27 12:59:43 +00:00
|
|
|
this.orderUpdate.subscribe((order) => {
|
|
|
|
this.order = order;
|
|
|
|
});
|
2021-10-27 20:21:55 +00:00
|
|
|
this.totalUpdate = orderService.totalUpdate;
|
|
|
|
this.totalUpdate.subscribe((total) => {
|
|
|
|
this.total = total;
|
|
|
|
});
|
2021-10-25 20:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
}
|
2021-10-27 20:21:55 +00:00
|
|
|
|
|
|
|
cancelOrder() {
|
|
|
|
const dialogConfig = new MatDialogConfig();
|
|
|
|
|
|
|
|
dialogConfig.disableClose = true;
|
|
|
|
dialogConfig.autoFocus = true;
|
|
|
|
|
|
|
|
const dialogRef = this.dialog.open(CancelComponent, dialogConfig);
|
|
|
|
dialogRef.afterClosed().subscribe((val) => {
|
|
|
|
if (val) {
|
|
|
|
console.log('Canceling');
|
|
|
|
this.orderService.cancelOrder(this.order._id!).subscribe((response) => {
|
|
|
|
this.orderService.getOrder();
|
|
|
|
});;
|
|
|
|
} else {
|
|
|
|
console.log('Returning to page');
|
|
|
|
}
|
|
|
|
this.orderService.getOrder();
|
|
|
|
});
|
|
|
|
}
|
2021-10-28 18:22:54 +00:00
|
|
|
|
|
|
|
checkout() {
|
|
|
|
const dialogConfig = new MatDialogConfig();
|
|
|
|
|
|
|
|
dialogConfig.disableClose = true;
|
|
|
|
dialogConfig.autoFocus = true;
|
|
|
|
dialogConfig.data = {
|
|
|
|
totalZec: this.total/this.price,
|
|
|
|
addr: this.order.address,
|
|
|
|
orderId: this.order._id
|
|
|
|
};
|
|
|
|
|
|
|
|
const dialogRef = this.dialog.open(CheckoutComponent, dialogConfig);
|
|
|
|
dialogRef.afterClosed().subscribe((val) => {
|
|
|
|
if (val) {
|
|
|
|
console.log('Payment confirmed!');
|
2021-11-02 15:35:22 +00:00
|
|
|
this.orderService.closeOrder();
|
2021-10-28 18:22:54 +00:00
|
|
|
} else {
|
|
|
|
console.log('Returning to order');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2021-10-25 20:01:06 +00:00
|
|
|
}
|