|
@@ -22,6 +22,7 @@ import {
|
|
|
} from 'hslayers-ng';
|
|
} from 'hslayers-ng';
|
|
|
|
|
|
|
|
import { BcInfoService } from './bc-info.service';
|
|
import { BcInfoService } from './bc-info.service';
|
|
|
|
|
+import { Purchase } from './purchase/purchase.component';
|
|
|
|
|
|
|
|
@Component({
|
|
@Component({
|
|
|
selector: 'blockchain-info',
|
|
selector: 'blockchain-info',
|
|
@@ -47,6 +48,8 @@ export class BcInfoComponent implements HsPanelComponent, OnInit {
|
|
|
data: any;
|
|
data: any;
|
|
|
name: string = "bc-panel";
|
|
name: string = "bc-panel";
|
|
|
|
|
|
|
|
|
|
+ lastPurchases: Array<Purchase>;
|
|
|
|
|
+
|
|
|
constructor(
|
|
constructor(
|
|
|
private bcInfoService: BcInfoService,
|
|
private bcInfoService: BcInfoService,
|
|
|
private mapService: HsMapService,
|
|
private mapService: HsMapService,
|
|
@@ -59,14 +62,25 @@ export class BcInfoComponent implements HsPanelComponent, OnInit {
|
|
|
this.onExtentChanged = this.onExtentChanged.bind(this);
|
|
this.onExtentChanged = this.onExtentChanged.bind(this);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- async ngOnInit(): Promise<void> {
|
|
|
|
|
- await this.refreshUserBalance();
|
|
|
|
|
|
|
+ ngOnInit(): void {
|
|
|
|
|
+ this.refreshUserBalance();
|
|
|
|
|
+ this.refreshPurchaseHistory();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async refreshUserBalance(): Promise<void> {
|
|
async refreshUserBalance(): Promise<void> {
|
|
|
- this.getUserBalanceInProgress = true;
|
|
|
|
|
- this.userBalance = await this.bcInfoService.getUserBalance(this.user, this.userPrivateKey, this.assetId);
|
|
|
|
|
- this.getUserBalanceInProgress = false;
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ this.getUserBalanceInProgress = true;
|
|
|
|
|
+ this.userBalance = await this.bcInfoService.getUserBalance(this.user, this.userPrivateKey, this.assetId);
|
|
|
|
|
+ this.getUserBalanceInProgress = false;
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (err) {
|
|
|
|
|
+ this.getUserBalanceInProgress = false;
|
|
|
|
|
+ throw err;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ async refreshPurchaseHistory(): Promise<void> {
|
|
|
|
|
+ this.lastPurchases = (await this.bcInfoService.getTransfers(this.user)) as Array<Purchase>;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
isVisible(): boolean {
|
|
isVisible(): boolean {
|
|
@@ -85,21 +99,33 @@ export class BcInfoComponent implements HsPanelComponent, OnInit {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async onBuy(): Promise<void> {
|
|
async onBuy(): Promise<void> {
|
|
|
- if (!confirm("You sure?")) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (!confirm("You sure?")) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- this.buyInProgress = true;
|
|
|
|
|
|
|
+ this.buyInProgress = true;
|
|
|
|
|
|
|
|
- let transformedExtent = transformExtent(this.extent, this.mapService.getMap().getView().getProjection(), "EPSG:4326");
|
|
|
|
|
- transformedExtent = this.roundExtentCoords(transformedExtent);
|
|
|
|
|
- //console.log(transformedExtent);
|
|
|
|
|
|
|
+ let transformedExtent = transformExtent(this.extent, this.mapService.getMap().getView().getProjection(), "EPSG:4326");
|
|
|
|
|
+ transformedExtent = this.roundExtentCoords(transformedExtent);
|
|
|
|
|
+ //console.log(transformedExtent);
|
|
|
|
|
|
|
|
- this.paymentHash = await this.bcInfoService.transferAssets(this.user, this.userPrivateKey, this.assetId, transformedExtent, this.price);
|
|
|
|
|
- this.refreshUserBalance();
|
|
|
|
|
- this.dataUrl = await this.bcInfoService.requestData(this.paymentHash, this.user);//"https://eo.lesprojekt.cz/produkty/S2/2020/S2A_MSIL2A_20200422T095031_N9999_R079_T33UXQ_20201127T165009_NDVI.tif"
|
|
|
|
|
|
|
+ this.paymentHash = await this.bcInfoService.transferAssets(this.user, this.userPrivateKey, this.assetId, transformedExtent, this.price);
|
|
|
|
|
+
|
|
|
|
|
+ await this.bcInfoService.archiveTransfer(this.user, this.price, this.paymentHash, transformedExtent, Date.now());
|
|
|
|
|
+
|
|
|
|
|
+ this.refreshPurchaseHistory();
|
|
|
|
|
+ this.refreshUserBalance();
|
|
|
|
|
+
|
|
|
|
|
+ this.dataUrl = await this.bcInfoService.requestData(this.paymentHash, this.user);//"https://eo.lesprojekt.cz/produkty/S2/2020/S2A_MSIL2A_20200422T095031_N9999_R079_T33UXQ_20201127T165009_NDVI.tif"
|
|
|
|
|
+
|
|
|
|
|
+ this.buyInProgress = false;
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (err) {
|
|
|
|
|
+ this.buyInProgress = false;
|
|
|
|
|
+ throw err;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- this.buyInProgress = false;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
onCancel(): void {
|
|
onCancel(): void {
|
|
@@ -128,8 +154,10 @@ export class BcInfoComponent implements HsPanelComponent, OnInit {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
onTest() {
|
|
onTest() {
|
|
|
- this.bcInfoService.getUserTransactions(this.user, this.userPrivateKey);
|
|
|
|
|
|
|
+ //this.bcInfoService.getUserTransactions(this.user, this.userPrivateKey);
|
|
|
//console.log(this.mapService.getMap().getView().getProjection());
|
|
//console.log(this.mapService.getMap().getView().getProjection());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -138,7 +166,7 @@ export class BcInfoComponent implements HsPanelComponent, OnInit {
|
|
|
let roundedExtent: number[] = new Array<number>(4);
|
|
let roundedExtent: number[] = new Array<number>(4);
|
|
|
|
|
|
|
|
for (let i = 0; i !== extent.length; i++) {
|
|
for (let i = 0; i !== extent.length; i++) {
|
|
|
- roundedExtent[i] = this.roundTwoDecimalPlaces(extent[i]);
|
|
|
|
|
|
|
+ roundedExtent[i] = Math.round((extent[i] + Number.EPSILON) * 1000000) / 1000000;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return roundedExtent;
|
|
return roundedExtent;
|