Sfoglia il codice sorgente

reorg components structure

kunickyd 3 anni fa
parent
commit
00e896da87

+ 9 - 1
src/app/bc-info/bc-info.component.html

@@ -45,6 +45,14 @@ Data URL: {{bcInfoService.dataUrl}} -->
 
         <div>
             <p>Purchase history</p>
-            <purchase-history [user]="user"></purchase-history>
+            <div>
+                <purchase                    
+                    *ngFor="let purchase of lastPurchases; index as i"
+                    [hash]="purchase.hash"
+                    [amount]="purchase.amount"
+                    [extent]="purchase.extent"
+                    [timestamp]="purchase.timestamp"
+                ></purchase>
+            </div>
     </div>
 </div>

+ 15 - 29
src/app/bc-info/bc-info.component.ts

@@ -22,6 +22,7 @@ import {
 } from 'hslayers-ng';
 
 import { BcInfoService } from './bc-info.service';
+import { Purchase } from './purchase/purchase.component';
 
 @Component({
   selector: 'blockchain-info',
@@ -47,32 +48,7 @@ export class BcInfoComponent implements HsPanelComponent, OnInit {
   data: any;
   name: string = "bc-panel";
 
-  lastTransfers: Array<any> = [
-    {
-      hash: "dafsdfagfsdgsrggfsdfasdfgghvccvbgdfgdsf",
-      user: "kunickyd@test",
-      timestamp: "20.3.2021 14:35",
-      extent: "[36, 58, 78, 65]",
-      amount: "58.5",
-      expanded: true
-    },
-    {
-      hash: "ddafs65432df456d4fsa54as9d8f4df",
-      user: "kunickyd@test",
-      timestamp: "20.3.2021 14:35",
-      extent: "[36, 58, 78, 65]",
-      amount: "58.5",
-      expanded: false
-    },
-    {
-      hash: "54d6afs54df488d8da98f7d75dddafdf5d5f5d5f5d5fd",
-      user: "kunickyd@test",
-      timestamp: "20.3.2021 14:35",
-      extent: "[36, 58, 78, 65]",
-      amount: "58.5",
-      expanded: true
-    }
-  ];
+  lastPurchases: Array<Purchase>;
 
   constructor(
     private bcInfoService: BcInfoService,
@@ -86,8 +62,9 @@ export class BcInfoComponent implements HsPanelComponent, OnInit {
     this.onExtentChanged = this.onExtentChanged.bind(this);
   }
 
-  async ngOnInit(): Promise<void> {
-    await this.refreshUserBalance();
+  ngOnInit(): void {
+    this.refreshUserBalance();
+    this.refreshPurchaseHistory();
   }
 
   async refreshUserBalance(): Promise<void> {
@@ -96,6 +73,10 @@ export class BcInfoComponent implements HsPanelComponent, OnInit {
     this.getUserBalanceInProgress = false;
   }
 
+  async refreshPurchaseHistory(): Promise<void> {
+    this.lastPurchases = (await this.bcInfoService.getTransfers(this.user)) as Array<Purchase>;
+  }
+
   isVisible(): boolean {
     return this.hsLayoutService.panelVisible(this.name);
   }
@@ -123,7 +104,12 @@ export class BcInfoComponent implements HsPanelComponent, OnInit {
     //console.log(transformedExtent);
 
     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;
@@ -155,7 +141,7 @@ export class BcInfoComponent implements HsPanelComponent, OnInit {
     }
   }
 
-  
+
 
   onTest() {
     //this.bcInfoService.getUserTransactions(this.user, this.userPrivateKey);

+ 2 - 3
src/app/bc-info/bc-info.module.ts

@@ -4,13 +4,12 @@ import {CommonModule} from '@angular/common'
 import { HsPanelHelpersModule } from 'hslayers-ng';
 
 import {BcInfoComponent} from './bc-info.component';
-import { PurchaseHistory } from './purchase-history/purchase-history.component';
-import { Purchase } from './purchase-history/purchase/purchase.component';
+import { Purchase } from './purchase/purchase.component';
 
 @NgModule({
   imports: [CommonModule, HsPanelHelpersModule],
   exports: [BcInfoComponent],
-  declarations: [BcInfoComponent, PurchaseHistory, Purchase],
+  declarations: [BcInfoComponent, Purchase],
   providers: [],
 })
 export class BcInfoModule {}

+ 8 - 0
src/app/bc-info/bc-info.service.ts

@@ -105,4 +105,12 @@ export class BcInfoService {
 
     return response as Array<Object>;
   }
+
+  async archiveTransfer(user: string, amount: number, txHash: string, extent: number[], timestamp: number){
+    let response = await this.httpClient.post(
+      this._bcConfig.CHAIN4ALL_SERVICE_URL + '/transfer',
+      { txHash, user, extent, amount, timestamp },
+      { headers: this.basicAuthHeaders }
+    ).toPromise();
+  }
 }

+ 0 - 10
src/app/bc-info/purchase-history/purchase-history.component.html

@@ -1,10 +0,0 @@
-<div id="tx-history">
-    <purchase 
-        class="card"
-        *ngFor="let purchase of lastPurchases; index as i"
-        [hash]="purchase.hash"
-        [amount]="purchase.amount"
-        [extent]="purchase.extent"
-        [timestamp]="purchase.timestamp"
-    ></purchase>
-</div>

+ 0 - 21
src/app/bc-info/purchase-history/purchase-history.component.ts

@@ -1,21 +0,0 @@
-import { Component, OnInit, Input } from '@angular/core'
-import { BcInfoService } from '../bc-info.service'
-import { Purchase } from './purchase/purchase.component'
-
-
-@Component({
-    selector: 'purchase-history',
-    templateUrl: 'purchase-history.component.html',
-})
-export class PurchaseHistory implements OnInit {
-    lastPurchases: Array<Purchase>;
-    @Input() user: string;
-
-    constructor(private bcInfoService: BcInfoService) {
-
-    }
-
-    async ngOnInit(): Promise<void> {
-        this.lastPurchases = (await this.bcInfoService.getTransfers(this.user)) as Array<Purchase>;
-    }
-}

+ 0 - 0
src/app/bc-info/purchase-history/purchase/purchase.component.html → src/app/bc-info/purchase/purchase.component.html


+ 1 - 1
src/app/bc-info/purchase-history/purchase/purchase.component.ts → src/app/bc-info/purchase/purchase.component.ts

@@ -1,6 +1,6 @@
 import { Component, Input } from '@angular/core'
 import { Extent } from 'ol/extent'
-import { BcInfoService } from '../../bc-info.service'
+import { BcInfoService } from '../bc-info.service'
 
 @Component({
     selector: 'purchase',