diff --git a/cw_core/lib/crypto_currency.dart b/cw_core/lib/crypto_currency.dart index f1c1cd8ae..a7edd409f 100644 --- a/cw_core/lib/crypto_currency.dart +++ b/cw_core/lib/crypto_currency.dart @@ -10,7 +10,7 @@ class CryptoCurrency extends EnumerableItem with Serializable implemen this.fullName, this.iconPath, this.tag, - this.enabled = false, + this.enabled = true, }) : super(title: title, raw: raw); diff --git a/cw_evm/lib/evm_chain_client.dart b/cw_evm/lib/evm_chain_client.dart index eebbe4f4f..8f0df3926 100644 --- a/cw_evm/lib/evm_chain_client.dart +++ b/cw_evm/lib/evm_chain_client.dart @@ -234,14 +234,17 @@ abstract class EVMChainClient { final decodedResponse = jsonDecode(response.body)[0] as Map; + + final symbol = (decodedResponse['symbol'] ?? '') as String; + String filteredSymbol = symbol.replaceFirst(RegExp('^\\\$'), ''); + final name = decodedResponse['name'] ?? ''; - final symbol = decodedResponse['symbol'] ?? ''; final decimal = decodedResponse['decimals'] ?? '0'; final iconPath = decodedResponse['logo'] ?? ''; return Erc20Token( name: name, - symbol: symbol, + symbol: filteredSymbol, contractAddress: contractAddress, decimal: int.tryParse(decimal) ?? 0, iconPath: iconPath, diff --git a/cw_evm/lib/evm_chain_wallet.dart b/cw_evm/lib/evm_chain_wallet.dart index 4193e590a..558013252 100644 --- a/cw_evm/lib/evm_chain_wallet.dart +++ b/cw_evm/lib/evm_chain_wallet.dart @@ -468,9 +468,15 @@ abstract class EVMChainWalletBase await token.delete(); balance.remove(token); + await _removeTokenTransactionsInHistory(token); _updateBalance(); } + Future _removeTokenTransactionsInHistory(Erc20Token token) async { + transactionHistory.transactions.removeWhere((key, value) => value.tokenSymbol == token.title); + await transactionHistory.save(); + } + Future getErc20Token(String contractAddress, String chainName) async => await _client.getErc20Token(contractAddress, chainName); diff --git a/cw_solana/lib/solana_transaction_info.dart b/cw_solana/lib/solana_transaction_info.dart index 1b7610e34..7a0844e52 100644 --- a/cw_solana/lib/solana_transaction_info.dart +++ b/cw_solana/lib/solana_transaction_info.dart @@ -34,10 +34,7 @@ class SolanaTransactionInfo extends TransactionInfo { @override String amountFormatted() { String stringBalance = solAmount.toString(); - - if (stringBalance.toString().length >= 6) { - stringBalance = stringBalance.substring(0, 6); - } + return '$stringBalance $tokenSymbol'; } diff --git a/cw_solana/lib/solana_wallet.dart b/cw_solana/lib/solana_wallet.dart index 43a6d0b83..f3eef465c 100644 --- a/cw_solana/lib/solana_wallet.dart +++ b/cw_solana/lib/solana_wallet.dart @@ -273,32 +273,12 @@ abstract class SolanaWalletBase final transactions = await _client.fetchTransactions(address); - final Map result = {}; - - for (var transactionModel in transactions) { - result[transactionModel.id] = SolanaTransactionInfo( - id: transactionModel.id, - to: transactionModel.to, - from: transactionModel.from, - blockTime: transactionModel.blockTime, - direction: transactionModel.isOutgoingTx - ? TransactionDirection.outgoing - : TransactionDirection.incoming, - solAmount: transactionModel.amount, - isPending: false, - txFee: transactionModel.fee, - tokenSymbol: transactionModel.tokenSymbol, - ); - } - - transactionHistory.addMany(result); - - await transactionHistory.save(); + await _addTransactionsToTransactionHistory(transactions); } /// Fetches the SPL Tokens transactions linked to the token account Public Key Future _updateSPLTokenTransactions() async { - List splTokenTransactions = []; + // List splTokenTransactions = []; // Make a copy of keys to avoid concurrent modification var tokenKeys = List.from(balance.keys); @@ -312,13 +292,20 @@ abstract class SolanaWalletBase _walletKeyPair!, ); - splTokenTransactions.addAll(tokenTxs); + // splTokenTransactions.addAll(tokenTxs); + await _addTransactionsToTransactionHistory(tokenTxs); } } + // await _addTransactionsToTransactionHistory(splTokenTransactions); + } + + Future _addTransactionsToTransactionHistory( + List transactions, + ) async { final Map result = {}; - for (var transactionModel in splTokenTransactions) { + for (var transactionModel in transactions) { result[transactionModel.id] = SolanaTransactionInfo( id: transactionModel.id, to: transactionModel.to, @@ -460,12 +447,23 @@ abstract class SolanaWalletBase await token.delete(); balance.remove(token); + await _removeTokenTransactionsInHistory(token); _updateBalance(); } + Future _removeTokenTransactionsInHistory(SPLToken token) async { + transactionHistory.transactions.removeWhere((key, value) => value.tokenSymbol == token.title); + await transactionHistory.save(); + } + Future getSPLToken(String mintAddress) async { // Convert SPL token mint address to public key - final mintPublicKey = Ed25519HDPublicKey.fromBase58(mintAddress); + final Ed25519HDPublicKey mintPublicKey; + try { + mintPublicKey = Ed25519HDPublicKey.fromBase58(mintAddress); + } catch (_) { + return null; + } // Fetch token's metadata account try { @@ -480,10 +478,12 @@ abstract class SolanaWalletBase iconPath = await _client.getIconImageFromTokenUri(token.uri); } catch (_) {} + String filteredTokenSymbol = token.symbol.replaceFirst(RegExp('^\\\$'), ''); + return SPLToken.fromMetadata( name: token.name, mint: token.mint, - symbol: token.symbol, + symbol: filteredTokenSymbol, mintAddress: mintAddress, iconPath: iconPath, ); diff --git a/cw_solana/lib/spl_token.dart b/cw_solana/lib/spl_token.dart index 0b3b8b372..a40eb0b86 100644 --- a/cw_solana/lib/spl_token.dart +++ b/cw_solana/lib/spl_token.dart @@ -19,7 +19,7 @@ class SPLToken extends CryptoCurrency with HiveObjectMixin { @HiveField(3) final int decimal; - @HiveField(4, defaultValue: false) + @HiveField(4, defaultValue: true) bool _enabled; @HiveField(5) @@ -39,7 +39,7 @@ class SPLToken extends CryptoCurrency with HiveObjectMixin { required this.mint, this.iconPath, this.tag = 'SOL', - bool enabled = false, + bool enabled = true, }) : _enabled = enabled, super( name: mint.toLowerCase(), diff --git a/lib/entities/calculate_fiat_amount.dart b/lib/entities/calculate_fiat_amount.dart index 689ada31b..b0b38eacb 100644 --- a/lib/entities/calculate_fiat_amount.dart +++ b/lib/entities/calculate_fiat_amount.dart @@ -3,6 +3,8 @@ String calculateFiatAmount({double? price, String? cryptoAmount}) { return '0.00'; } + cryptoAmount = cryptoAmount.replaceAll(',', '.'); + final _amount = double.parse(cryptoAmount); final _result = price * _amount; final result = _result < 0 ? _result * -1 : _result; diff --git a/lib/ethereum/cw_ethereum.dart b/lib/ethereum/cw_ethereum.dart index 13fe3aafd..61d5b6ae3 100644 --- a/lib/ethereum/cw_ethereum.dart +++ b/lib/ethereum/cw_ethereum.dart @@ -142,8 +142,10 @@ class CWEthereum extends Ethereum { } wallet as EthereumWallet; - return wallet.erc20Currencies - .firstWhere((element) => transaction.tokenSymbol == element.symbol); + + return wallet.erc20Currencies.firstWhere( + (element) => transaction.tokenSymbol == element.symbol, + ); } @override diff --git a/lib/polygon/cw_polygon.dart b/lib/polygon/cw_polygon.dart index 9f0f9a1bf..5baf4fbbc 100644 --- a/lib/polygon/cw_polygon.dart +++ b/lib/polygon/cw_polygon.dart @@ -140,8 +140,10 @@ class CWPolygon extends Polygon { } wallet as PolygonWallet; + return wallet.erc20Currencies.firstWhere( - (element) => transaction.tokenSymbol.toLowerCase() == element.symbol.toLowerCase()); + (element) => transaction.tokenSymbol.toLowerCase() == element.symbol.toLowerCase(), + ); } @override diff --git a/lib/solana/cw_solana.dart b/lib/solana/cw_solana.dart index 6f4b17309..af66cf3e5 100644 --- a/lib/solana/cw_solana.dart +++ b/lib/solana/cw_solana.dart @@ -110,8 +110,10 @@ class CWSolana extends Solana { } wallet as SolanaWallet; - return wallet.splTokenCurrencies - .firstWhere((element) => transaction.tokenSymbol == element.symbol); + + return wallet.splTokenCurrencies.firstWhere( + (element) => transaction.tokenSymbol == element.symbol, + ); } @override