kunickyd пре 3 година
родитељ
комит
e8ac6d7630
1 измењених фајлова са 22 додато и 13 уклоњено
  1. 22 13
      src/app/bc-info/bc-info.service.ts

+ 22 - 13
src/app/bc-info/bc-info.service.ts

@@ -6,21 +6,22 @@ import {
 } from 'iroha-helpers/lib/proto/endpoint_pb_service'
 import { queries } from 'iroha-helpers'
 
+
 @Injectable({ providedIn: 'root' })
 export class BcInfoService {
 
   BASE_URL = 'https://chain4all.lesprojekt.cz' as const;
-  IROHA_ADDRESS = "localhost:50051" as const;
+  IROHA_ADDRESS = "http://localhost:8080" as const;
   ASSET = "testcoin#test" as const;
 
   commandService: CommandService;
   queryService: QueryService;
-  user = 'jmacura';
-  userPrivateKey = 'test';
+  user = 'admin@test';
+  userPrivateKey = 'f101537e319568c765b2cc89698325604991dca57b9716b58016b253506cab70';
   userBalance = -1;
   private _requestInProcess = false;
 
-  constructor(public httpClient: HttpClient) { 
+  constructor(public httpClient: HttpClient) {
     this.commandService = new CommandService(this.IROHA_ADDRESS);
     this.queryService = new QueryService(this.IROHA_ADDRESS);
     this.getUserBalance();
@@ -33,16 +34,16 @@ export class BcInfoService {
     this.userBalance = await this.getUserBalanceFromIroha()
   }
 
-  async getUserBalanceFromIroha(): Promise<any> {
+  async getUserBalanceFromIroha(): Promise<number> {
+
     this._requestInProcess = true;
     let queryOptions = {
       privateKey: this.userPrivateKey,
       creatorAccountId: this.user,
       queryService: this.queryService,
-      timeoutLimit: 5000
+      timeoutLimit: 10000
     };
 
-    let data;
     try {
       // For testing
       /*data = await new Promise((resolve, reject) => {
@@ -50,17 +51,25 @@ export class BcInfoService {
           resolve(Math.random()*100);
         }, 1500);
       });*/
-      data = await queries.getAccountAssets(queryOptions, {
+
+      let data = await queries.getAccountAssets(queryOptions, {
         accountId: this.user,
-        firstAssetId: undefined,
+        firstAssetId: this.ASSET,
         pageSize: 10
-      })
-    } catch(err) {
+      });
+
+      console.debug(data);
+
+      let balance: number = parseFloat(data[0].balance);
+
+      this._requestInProcess = false;
+      return balance;
+
+    } catch (err) {
       this._requestInProcess = false
       console.error(err)
     }
+
     this._requestInProcess = false
-    console.log(data)
-    return data
   }
 }