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 (_selectedChainID == null || _currentSession == null) {
return;
}
_status = ReownAppKitModalStatus.initializing;
_notify();
// Get the chain balance.
final namespace = NamespaceUtils.getNamespaceFromChain(_selectedChainID!);
try {
_chainBalance = await _blockchainService.getTokenBalance(
address: _currentSession!.getAddress(namespace)!,
namespace: namespace,
chainId: _selectedChainID!,
);
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 address = _currentSession!.getAddress(namespace)!;
final blockchainId = await _blockchainService.getIdentity(
address: address,
);
_blockchainIdentity = BlockchainIdentity.fromJson(
blockchainId.toJson(),
);
} catch (_) {}
} else {
_blockchainIdentity = null;
}
_status = ReownAppKitModalStatus.initialized;
_notify();
}