import {Component, OnInit} from '@angular/core';
import {EthService} from '../eth.service';
import {TestContractService} from './test-contract.service';

@Component({
  selector: 'app-test-contract',
  templateUrl: './test-contract.component.html',
  styleUrls: ['./test-contract.component.scss']
})
export class TestContractComponent implements OnInit {

  private result: number;
  accounts: string | null = '';
  balance: string | null = null;

  constructor(private testContractService: TestContractService,
              private ethService: EthService) {

  }

  async increment() {
    await this.testContractService.increment();
    await this.update();
  }

  async update() {
    this.result = await this.testContractService.update();
  }

  ngOnInit(): void {
    this.ethService.getDefaultAccount()
      .then(() => this.setAccountInfo());
  }

  async setAccountInfo() {
    const accounts = await this.ethService.getAccounts();
    this.accounts = accounts.join(' ');
    this.balance = await this.ethService.getBalance();
  }

}
