loadAccountData method

  1. @override
Future<void> loadAccountData()
override

Loads account balance and avatar. Returns true if it was able to actually load data (i.e. there is a selected chain and session)

Implementation

@override
Future<void> loadAccountData() async {
  // If there is no selected chain or session, stop. No account to load in.
  if (_currentSelectedChainId == null ||
      _currentSession == null ||
      _currentSession?.address == null) {
    return;
  }

  // Get the chain balance.
  _chainBalance = await blockchainService.instance.getRpcRequest(
    method: 'eth_getBalance',
    params: [_currentSession!.address!, 'latest'],
    chain: 'eip155:$_currentSelectedChainId',
  );
  final tokenName = selectedChain?.tokenName ?? '';
  balanceNotifier.value = '$_chainBalance $tokenName';

  // Get the avatar, each chainId is just a number in string form.
  try {
    final blockchainId = await blockchainService.instance.getIdentity(
      _currentSession!.address!,
    );
    _avatarUrl = blockchainId.avatar;
    _logger.i('[$runtimeType] loadAccountData');
  } catch (e) {
    _logger.e('[$runtimeType] loadAccountData $e');
  }
  _notify();
}