5 Commit-ok 98f8428dfb ... 88fe1fed4c

Szerző SHA1 Üzenet Dátum
  kunickyd 88fe1fed4c reorg components structure 3 éve
  kunickyd e84e0615a9 load last purchases 3 éve
  kunickyd 5c5c77c92e rename transfer to purchase 3 éve
  kunickyd 751100d8f5 register and modify new components 3 éve
  kunickyd a4ce0cfad9 getTransfers 3 éve

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

@@ -44,33 +44,15 @@ Data URL: {{bcInfoService.dataUrl}} -->
         </div>
 
         <div>
-            <p>Transaction history</p>
-            <div id="tx-history">
-                <div *ngFor="let transfer of lastTransfers; index as i" class="card">
-                    <div class="card-header">
-                        <small>{{transfer.timestamp}}</small>
-
-                        <span style="float: right;">                            
-                            <button style="margin-right: 5px" class="btn btn-secondary btn-sm" (click)="onRequestData()">
-                                Data
-                            </button>
-                            <button style="margin-right: 5px" class="btn btn-sm" (click)="transfer.expanded = !transfer.expanded">
-                                <i [class]="transfer.expanded ? 'icon-arrow-up' : 'icon-arrow-down'"></i>
-                            </button>
-                        </span>
-                        
-                    </div>
-
-                    <div [class]="transfer.expanded ? '' : 'collapse'">
-                        <div class="card-body">
-                            Extent: {{transfer.extent}}
-                            Amount: {{transfer.amount}}
-                        </div>
-                    </div>
-                </div>
+            <p>Purchase history</p>
+            <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>
 </div>

+ 15 - 31
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,9 +141,7 @@ export class BcInfoComponent implements HsPanelComponent, OnInit {
     }
   }
 
-  onRequestData(){
-    window.open("https://eo.lesprojekt.cz/produkty/S2/2020/S2A_MSIL2A_20200422T095031_N9999_R079_T33UXQ_20201127T165009_NDVI.tif");
-  }
+
 
   onTest() {
     //this.bcInfoService.getUserTransactions(this.user, this.userPrivateKey);

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

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

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

@@ -96,4 +96,21 @@ export class BcInfoService {
 
     return response["dataUrl"];
   }
+
+  async getTransfers(user: string): Promise<Array<Object>>{
+    let response = await this.httpClient.get(
+      this._bcConfig.CHAIN4ALL_SERVICE_URL + "/transfers/" + user,
+      { headers: this.basicAuthHeaders }
+    ).toPromise();
+
+    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 - 24
src/app/bc-info/purchase-history/purchase-history.component.html

@@ -1,24 +0,0 @@
-<div id="tx-history">
-    <div *ngFor="let transfer of lastTransfers; index as i" class="card">
-        <div class="card-header">
-            <small>{{transfer.timestamp}}</small>
-
-            <span style="float: right;">                            
-                <button style="margin-right: 5px" class="btn btn-secondary btn-sm">
-                    Data
-                </button>
-                <button style="margin-right: 5px" class="btn btn-sm" (click)="transfer.expanded = !transfer.expanded">
-                    <i [class]="transfer.expanded ? 'icon-arrow-up' : 'icon-arrow-down'"></i>
-                </button>
-            </span>
-            
-        </div>
-
-        <div [class]="transfer.expanded ? '' : 'collapse'">
-            <div class="card-body">
-                Extent: {{transfer.extent}}
-                Amount: {{transfer.amount}}
-            </div>
-        </div>
-    </div>
-</div>

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

@@ -1,20 +0,0 @@
-import { Component, OnInit } 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>;
-
-    constructor(bcInfoService: BcInfoService) {
-
-    }
-    
-    ngOnInit(): void {
-        throw new Error('Method not implemented.');
-    }
-}

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

@@ -1,20 +0,0 @@
-import { Component } from '@angular/core'
-import {Extent} from 'ol/extent'
-import {BcInfoService} from '../../bc-info.service'
-
-@Component({
-    selector: 'purchase',
-    templateUrl: 'purchase.component.html',
-})
-export class Purchase {
-    hash: string;    
-    timestamp: string;
-    extent: Extent;
-    amount: number;  
-    expanded: boolean = false;
-    loadingData: boolean = false;
-
-    constructor(bcInfoService: BcInfoService){
-
-    }
-}

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

@@ -3,7 +3,7 @@
     <div class="card-header">
         <small>{{timestamp}}</small>
         <span style="float: right;">                            
-            <button style="margin-right: 5px" class="btn btn-secondary btn-sm">
+            <button style="margin-right: 5px" class="btn btn-secondary btn-sm" (click)="onRequestData()">
                 Data
             </button>
             <button style="margin-right: 5px" class="btn btn-sm" (click)="expanded = !expanded">

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

@@ -0,0 +1,26 @@
+import { Component, Input } from '@angular/core'
+import { Extent } from 'ol/extent'
+import { BcInfoService } from '../bc-info.service'
+
+@Component({
+    selector: 'purchase',
+    templateUrl: 'purchase.component.html'
+})
+export class Purchase {
+    @Input() hash: string;
+    @Input() timestamp: string;
+    @Input() extent: Extent;
+    @Input() amount: number;
+
+    expanded: boolean = false;
+    loadingData: boolean = false;
+
+    constructor(bcInfoService: BcInfoService) {
+
+    }
+
+
+    onRequestData() {
+        window.open("https://eo.lesprojekt.cz/produkty/S2/2020/S2A_MSIL2A_20200422T095031_N9999_R079_T33UXQ_20201127T165009_NDVI.tif");
+    }
+}