CW-608-Fetch-And-Save-Icons-Of-ERC20-And-SPL-Tokens-When-Adding-Them (#1365)

* feat: Fetch and save icons of SPL tokens when adding them

* feat: Implement fetch and save icons for ERC20 tokens when adding them

* fix: Add moralisApiKey to evm secrets

* Add check to ensure decimals cannot be zero

* - Fallback to adding erc20 token from web3dart
- Wrap fetching spl token icon in a try/catch block

---------

Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
This commit is contained in:
Adegoke David 2024-04-08 23:53:14 +01:00 committed by GitHub
parent d4b317b3a0
commit 2877cc160c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
41 changed files with 182 additions and 69 deletions

View file

@ -439,11 +439,16 @@ abstract class EVMChainWalletBase
Future<void> addErc20Token(Erc20Token token) async {
String? iconPath;
try {
iconPath = CryptoCurrency.all
.firstWhere((element) => element.title.toUpperCase() == token.symbol.toUpperCase())
.iconPath;
} catch (_) {}
if (token.iconPath == null || token.iconPath!.isEmpty) {
try {
iconPath = CryptoCurrency.all
.firstWhere((element) => element.title.toUpperCase() == token.symbol.toUpperCase())
.iconPath;
} catch (_) {}
} else {
iconPath = token.iconPath;
}
final newToken = createNewErc20TokenObject(token, iconPath);
@ -466,8 +471,8 @@ abstract class EVMChainWalletBase
_updateBalance();
}
Future<Erc20Token?> getErc20Token(String contractAddress) async =>
await _client.getErc20Token(contractAddress);
Future<Erc20Token?> getErc20Token(String contractAddress, String chainName) async =>
await _client.getErc20Token(contractAddress, chainName);
void _onNewTransaction() {
_updateBalance();