cake_wallet/cw_ethereum/lib/pending_ethereum_transaction.dart

33 lines
909 B
Dart
Raw Normal View History

2023-03-16 17:24:21 +00:00
import 'package:cw_core/pending_transaction.dart';
2023-04-05 16:01:20 +00:00
import 'package:web3dart/web3dart.dart';
2023-03-16 17:24:21 +00:00
class PendingEthereumTransaction with PendingTransaction {
2023-04-05 17:20:25 +00:00
final Function sendTransaction;
final TransactionInformation transactionInformation;
2023-03-16 17:24:21 +00:00
PendingEthereumTransaction({
2023-04-05 17:20:25 +00:00
required this.sendTransaction,
required this.transactionInformation,
2023-03-16 17:24:21 +00:00
});
@override
2023-04-05 17:20:25 +00:00
String get amountFormatted =>
transactionInformation.value.getValueInUnit(EtherUnit.ether).toString();
2023-03-16 17:24:21 +00:00
@override
2023-04-05 17:20:25 +00:00
Future<void> commit() async => sendTransaction();
2023-03-16 17:24:21 +00:00
@override
2023-04-05 17:20:25 +00:00
String get feeFormatted {
final fee = transactionInformation.gasPrice.getInWei * BigInt.from(transactionInformation.gas);
return EtherAmount.inWei(fee).getValueInUnit(EtherUnit.ether).toString();
}
2023-03-16 17:24:21 +00:00
@override
2023-04-05 17:20:25 +00:00
String get hex => transactionInformation.hash;
2023-03-16 17:24:21 +00:00
@override
2023-04-05 17:20:25 +00:00
String get id => transactionInformation.hashCode.toString();
2023-03-16 17:24:21 +00:00
}