changeAccount method

Future<void> changeAccount(
  1. KeyPairData account
)

This method will be called while App user changes account.

Implementation

Future<void> changeAccount(KeyPairData account) async {
  onAccountChanged(account);
  if (account.pubKey == account.address) {
    //eth
    final data = await sdk.api.eth.account
        .getNativeTokenBalance(account.address ?? '');

    _updateBalances(
        account,
        BalanceData()
          ..accountId = account.address
          ..freeBalance = data
          ..availableBalance = data
          ..lockedBalance = '0'
          ..reservedBalance = '0');
  } else {
    sdk.api.account.unsubscribeBalance();
    loadBalances(account);
    sdk.api.account.subscribeBalance(account.address, (BalanceData data) {
      _updateBalances(account, data);
    });
  }
}