Files
hash-wallet/cw_evm/lib/pending_evm_chain_transaction.dart
ee0996f535 CW-1175-Implement-swaps.xyz-swap-provider (#2526)
* Integrate SwapsXYZ

* Remove print

* enhance SwapsXyz EVM token swap handling

* Disable fixed rate support in SwapsXyz provider

* enable fixed rate swap

* fix timestamp parsing

* remove sender and recipient address from fetchRate

* Improve SwapsXYZ trade approval logic

* fix trade ID overflow

* add Base chain support for  swaps xyz

* Update lib/view_model/exchange/exchange_trade_view_model.dart

Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>

* add missing support for Base

---------

Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
2025-10-20 23:22:01 +02:00

68 lines
1.7 KiB
Dart

import 'dart:typed_data';
import 'package:cw_core/format_fixed.dart';
import 'package:cw_core/pending_transaction.dart';
import 'package:web3dart/crypto.dart';
import 'package:hex/hex.dart' as Hex;
class PendingEVMChainTransaction with PendingTransaction {
final Function sendTransaction;
final Uint8List signedTransaction;
final BigInt fee;
final String feeCurrency;
final String amount;
final int exponent;
final bool isInfiniteApproval;
PendingEVMChainTransaction({
required this.sendTransaction,
required this.signedTransaction,
required this.fee,
required this.feeCurrency,
required this.amount,
required this.exponent,
this.isInfiniteApproval = false,
});
@override
String get amountFormatted {
if (isInfiniteApproval) return "∞";
return formatFixed(BigInt.parse(amount), exponent);
}
@override
Future<void> commit() async => await sendTransaction();
@override
String get feeFormatted => "$feeFormattedValue $feeCurrency";
@override
String get feeFormattedValue => formatFixed(fee, 18, fractionalDigits: 10);
@override
String get hex => bytesToHex(signedTransaction, include0x: true);
@override
String get id {
final String eip1559Hex = '0x02${hex.substring(2)}';
final Uint8List bytes = Uint8List.fromList(Hex.HEX.decode(eip1559Hex.substring(2)));
final txid = keccak256(bytes);
return '0x${Hex.HEX.encode(txid)}';
}
@override
String? get evmTxHashFromRawHex {
final no0x = hex.startsWith('0x') ? hex.substring(2) : hex;
final bytes = Uint8List.fromList(Hex.HEX.decode(no0x));
final digest = keccak256(bytes);
return '0x${Hex.HEX.encode(digest)}';
}
@override
Future<Map<String, String>> commitUR() {
throw UnimplementedError();
}
}