mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-23 03:59:23 +00:00
Adjust transactions fiat price for ERC20 tokens
This commit is contained in:
parent
09fd6a8241
commit
25228a3163
5 changed files with 23 additions and 0 deletions
|
@ -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<String, dynamic> 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",
|
||||
);
|
||||
}
|
||||
|
|
|
@ -210,6 +210,10 @@ abstract class EthereumWalletBase
|
|||
final Map<String, EthereumTransactionInfo> result = {};
|
||||
|
||||
for (var transactionModel in transactions) {
|
||||
if (transactionModel.isError) {
|
||||
continue;
|
||||
}
|
||||
|
||||
result[transactionModel.hash] = EthereumTransactionInfo(
|
||||
id: transactionModel.hash,
|
||||
height: transactionModel.blockNumber,
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -533,6 +533,8 @@ abstract class Ethereum {
|
|||
Future<void> addErc20Token(WalletBase wallet, Erc20Token token);
|
||||
Future<void> deleteErc20Token(WalletBase wallet, Erc20Token token);
|
||||
Future<Erc20Token?> getErc20Token(WalletBase wallet, String contractAddress);
|
||||
|
||||
CryptoCurrency assetOfTransaction(WalletBase wallet, TransactionInfo transaction);
|
||||
}
|
||||
""";
|
||||
|
||||
|
|
Loading…
Reference in a new issue