loadAccountData method
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) {
return;
}
// Get the chain balance.
final namespace = ReownAppKitModalNetworks.getNamespaceForChainId(
_currentSelectedChainId!,
);
try {
_chainBalance = await _blockchainService.getBalance(
address: _currentSession!.getAddress(namespace)!,
namespace: namespace,
chainId: _currentSelectedChainId!,
);
final tokenName = selectedChain?.currency ?? '';
final formattedBalance = CoreUtils.formatChainBalance(_chainBalance);
balanceNotifier.value = '$formattedBalance $tokenName';
} catch (_) {
// Calling getBalanceFallback defined by user
_chainBalance = await _getBalance?.call();
final tokenName = selectedChain?.currency ?? '';
final formattedBalance = CoreUtils.formatChainBalance(_chainBalance);
balanceNotifier.value = '$formattedBalance $tokenName';
}
if (namespace == NetworkUtils.eip155) {
// Get the avatar, each chainId is just a number in string form.
try {
final blockchainId = await _blockchainService.getIdentity(
_currentSession!.getAddress(namespace)!,
);
_avatarUrl = blockchainId.avatar;
} catch (_) {}
}
_notify();
}