|
|
@@ -13,35 +13,54 @@ export class BcInfoService {
|
|
|
IROHA_ADDRESS = "localhost:50051" as const;
|
|
|
ASSET = "testcoin#test" as const;
|
|
|
|
|
|
- user = 'jmacura';
|
|
|
- userPrivateKey = 'test';
|
|
|
- user_balance = -1;
|
|
|
-
|
|
|
commandService: CommandService;
|
|
|
queryService: QueryService;
|
|
|
+ user = 'jmacura';
|
|
|
+ userPrivateKey = 'test';
|
|
|
+ userBalance = -1;
|
|
|
+ private _requestInProcess = false;
|
|
|
|
|
|
constructor(public httpClient: HttpClient) {
|
|
|
this.commandService = new CommandService(this.IROHA_ADDRESS);
|
|
|
this.queryService = new QueryService(this.IROHA_ADDRESS);
|
|
|
+ this.getUserBalance();
|
|
|
+ }
|
|
|
+
|
|
|
+ async getUserBalance(): Promise<any> {
|
|
|
+ if (this._requestInProcess) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.userBalance = await this.getUserBalanceFromIroha()
|
|
|
}
|
|
|
|
|
|
- getUserBalance() : any{
|
|
|
+ async getUserBalanceFromIroha(): Promise<any> {
|
|
|
+ this._requestInProcess = true;
|
|
|
let queryOptions = {
|
|
|
privateKey: this.userPrivateKey,
|
|
|
creatorAccountId: this.user,
|
|
|
queryService: this.queryService,
|
|
|
timeoutLimit: 5000
|
|
|
};
|
|
|
-
|
|
|
- queries.getAccountAssets(queryOptions, {
|
|
|
- accountId: this.user,
|
|
|
- firstAssetId: undefined,
|
|
|
- pageSize: 10
|
|
|
- })
|
|
|
- .then((data) => console.log(data))
|
|
|
- .catch((err) => console.error(err));
|
|
|
-
|
|
|
- return "test";
|
|
|
|
|
|
+ let data;
|
|
|
+ try {
|
|
|
+ // For testing
|
|
|
+ /*data = await new Promise((resolve, reject) => {
|
|
|
+ setTimeout(() => {
|
|
|
+ resolve(Math.random()*100);
|
|
|
+ }, 1500);
|
|
|
+ });*/
|
|
|
+ data = await queries.getAccountAssets(queryOptions, {
|
|
|
+ accountId: this.user,
|
|
|
+ firstAssetId: undefined,
|
|
|
+ pageSize: 10
|
|
|
+ })
|
|
|
+ } catch(err) {
|
|
|
+ this._requestInProcess = false
|
|
|
+ console.error(err)
|
|
|
+ }
|
|
|
+ this._requestInProcess = false
|
|
|
+ console.log(data)
|
|
|
+ return data
|
|
|
}
|
|
|
}
|