cake_wallet/cw_evm/lib/evm_chain_transaction_info.dart
Serhii 1690f6af1e
Erc20 token transactions are displaying incorrectly (#1493)
* evm signature name

* hide depositWithExpiry and transfer transactions

* Update contact_list_view_model.dart

* remove erc20 token history when disabled
2024-06-21 02:13:12 +03:00

80 lines
2.2 KiB
Dart

// ignore_for_file: overridden_fields, annotate_overrides
import 'dart:math';
import 'package:cw_core/format_amount.dart';
import 'package:cw_core/transaction_direction.dart';
import 'package:cw_core/transaction_info.dart';
abstract class EVMChainTransactionInfo extends TransactionInfo {
EVMChainTransactionInfo({
required this.id,
required this.height,
required this.ethAmount,
required this.ethFee,
required this.tokenSymbol,
this.exponent = 18,
required this.direction,
required this.isPending,
required this.date,
required this.confirmations,
required this.to,
required this.from,
this.evmSignatureName,
}) : amount = ethAmount.toInt(),
fee = ethFee.toInt();
final String id;
final int height;
final int amount;
final BigInt ethAmount;
final int exponent;
final TransactionDirection direction;
final DateTime date;
final bool isPending;
final int fee;
final BigInt ethFee;
final int confirmations;
final String tokenSymbol;
String? _fiatAmount;
final String? to;
final String? from;
final String? evmSignatureName;
//! Getter to be overridden in child classes
String get feeCurrency;
@override
String amountFormatted() {
final amount = formatAmount((ethAmount / BigInt.from(10).pow(exponent)).toString());
return '${amount.substring(0, min(10, amount.length))} $tokenSymbol';
}
@override
String fiatAmount() => _fiatAmount ?? '';
@override
void changeFiatAmount(String amount) => _fiatAmount = formatAmount(amount);
@override
String feeFormatted() {
final amount = (ethFee / BigInt.from(10).pow(18)).toString();
return '${amount.substring(0, min(10, amount.length))} $feeCurrency';
}
Map<String, dynamic> toJson() => {
'id': id,
'height': height,
'amount': ethAmount.toString(),
'exponent': exponent,
'fee': ethFee.toString(),
'direction': direction.index,
'date': date.millisecondsSinceEpoch,
'isPending': isPending,
'confirmations': confirmations,
'tokenSymbol': tokenSymbol,
'to': to,
'from': from,
'evmSignatureName': evmSignatureName,
};
}