From 25228a316382ec4292fe5dc8a0306fe7de6d6875 Mon Sep 17 00:00:00 2001 From: OmarHatem Date: Fri, 21 Jul 2023 04:51:22 +0300 Subject: [PATCH] Adjust transactions fiat price for ERC20 tokens --- cw_ethereum/lib/ethereum_transaction_model.dart | 3 +++ cw_ethereum/lib/ethereum_wallet.dart | 4 ++++ lib/ethereum/cw_ethereum.dart | 12 ++++++++++++ lib/view_model/dashboard/transaction_list_item.dart | 2 ++ tool/configure.dart | 2 ++ 5 files changed, 23 insertions(+) diff --git a/cw_ethereum/lib/ethereum_transaction_model.dart b/cw_ethereum/lib/ethereum_transaction_model.dart index b60c6e9b0..c1260795a 100644 --- a/cw_ethereum/lib/ethereum_transaction_model.dart +++ b/cw_ethereum/lib/ethereum_transaction_model.dart @@ -11,6 +11,7 @@ class EthereumTransactionModel { final int blockNumber; final String? tokenSymbol; final int? tokenDecimal; + final bool isError; EthereumTransactionModel({ required this.date, @@ -25,6 +26,7 @@ class EthereumTransactionModel { required this.blockNumber, required this.tokenSymbol, required this.tokenDecimal, + required this.isError, }); factory EthereumTransactionModel.fromJson(Map json) => EthereumTransactionModel( @@ -40,5 +42,6 @@ class EthereumTransactionModel { blockNumber: int.parse(json["blockNumber"]), tokenSymbol: json["tokenSymbol"] ?? "ETH", tokenDecimal: int.tryParse(json["tokenDecimal"] ?? ""), + isError: json["isError"] == "1", ); } diff --git a/cw_ethereum/lib/ethereum_wallet.dart b/cw_ethereum/lib/ethereum_wallet.dart index aa4611330..94f69b253 100644 --- a/cw_ethereum/lib/ethereum_wallet.dart +++ b/cw_ethereum/lib/ethereum_wallet.dart @@ -210,6 +210,10 @@ abstract class EthereumWalletBase final Map result = {}; for (var transactionModel in transactions) { + if (transactionModel.isError) { + continue; + } + result[transactionModel.hash] = EthereumTransactionInfo( id: transactionModel.hash, height: transactionModel.blockNumber, diff --git a/lib/ethereum/cw_ethereum.dart b/lib/ethereum/cw_ethereum.dart index 4fefa95ee..773bb63d2 100644 --- a/lib/ethereum/cw_ethereum.dart +++ b/lib/ethereum/cw_ethereum.dart @@ -106,4 +106,16 @@ class CWEthereum extends Ethereum { final ethereumWallet = wallet as EthereumWallet; return await ethereumWallet.getErc20Token(contractAddress); } + + @override + CryptoCurrency assetOfTransaction(WalletBase wallet, TransactionInfo transaction) { + transaction as EthereumTransactionInfo; + if (transaction.tokenSymbol == CryptoCurrency.eth.title) { + return CryptoCurrency.eth; + } + + wallet as EthereumWallet; + return wallet.erc20Currencies + .firstWhere((element) => transaction.tokenSymbol == element.symbol); + } } diff --git a/lib/view_model/dashboard/transaction_list_item.dart b/lib/view_model/dashboard/transaction_list_item.dart index b19e374d9..ac74df89d 100644 --- a/lib/view_model/dashboard/transaction_list_item.dart +++ b/lib/view_model/dashboard/transaction_list_item.dart @@ -86,6 +86,8 @@ class TransactionListItem extends ActionListItem with Keyable { price: price); break; case WalletType.ethereum: + final asset = ethereum!.assetOfTransaction(balanceViewModel.wallet, transaction); + final price = balanceViewModel.fiatConvertationStore.prices[asset]; amount = calculateFiatAmountRaw( cryptoAmount: ethereum!.formatterEthereumAmountToDouble(transaction: transaction), price: price); diff --git a/tool/configure.dart b/tool/configure.dart index 5ff470dcf..a34d06e47 100644 --- a/tool/configure.dart +++ b/tool/configure.dart @@ -533,6 +533,8 @@ abstract class Ethereum { Future addErc20Token(WalletBase wallet, Erc20Token token); Future deleteErc20Token(WalletBase wallet, Erc20Token token); Future getErc20Token(WalletBase wallet, String contractAddress); + + CryptoCurrency assetOfTransaction(WalletBase wallet, TransactionInfo transaction); } """;