Skip to content

Commit

Permalink
Add try catch
Browse files Browse the repository at this point in the history
  • Loading branch information
ppupha committed Jan 8, 2025
1 parent b9fa4f4 commit 8f6721b
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions lib/view/account_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,22 @@ Future<Pair<BigInt?, String>> getAddressBalance(
final tokens = await tokenDao.findTokenIDsOwnersOwn([address]);
final nftBalance =
"${tokens.length} ${tokens.length == 1 ? 'nft'.tr() : 'nfts'.tr()}";
switch (cryptoType) {
case CryptoType.ETH:
final etherAmount = await injector<EthereumService>().getBalance(address);
return Pair(etherAmount.getInWei, nftBalance);
case CryptoType.XTZ:
final tezosAmount = await injector<TezosService>().getBalance(address);
return Pair(BigInt.from(tezosAmount), nftBalance);
case CryptoType.USDC:
case CryptoType.UNKNOWN:
return Pair(null, '');
BigInt? cryptoBalance;
try {
switch (cryptoType) {
case CryptoType.ETH:
final etherAmount =
await injector<EthereumService>().getBalance(address);
cryptoBalance = etherAmount.getInWei;
case CryptoType.XTZ:
final tezosAmount = await injector<TezosService>().getBalance(address);
cryptoBalance = BigInt.from(tezosAmount);
case CryptoType.USDC:
case CryptoType.UNKNOWN:
cryptoBalance = null;
}
} catch (e) {
cryptoBalance = null;
}
return Pair(cryptoBalance, nftBalance);
}

0 comments on commit 8f6721b

Please sign in to comment.