From fd2bd2bcc63d7bcae0ea952a867cd65704897fc8 Mon Sep 17 00:00:00 2001 From: Ivan Date: Mon, 8 Apr 2024 17:33:32 +0300 Subject: [PATCH 1/3] fix the toTransaction method in TransactionExtension2 to correctly process the data parameter in sample wallet application --- lib/apis/utils/extensions.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/apis/utils/extensions.dart b/lib/apis/utils/extensions.dart index e5efa51e..2a6b08ee 100644 --- a/lib/apis/utils/extensions.dart +++ b/lib/apis/utils/extensions.dart @@ -37,7 +37,9 @@ extension TransactionExtension2 on Map { maxGas: (this['maxGas'] as String?).toIntFromHex(), nonce: (this['nonce'] as String?).toInt(), data: (this['data'] != null && this['data'] != '0x') - ? Uint8List.fromList(hex.decode(this['data']!)) + ? Uint8List.fromList(hex.decode(this['data']!.startsWith('0x') + ? this['data']!.substring(2) + : this['data']!)) : null, ); } From 9a416959d3f1e36af9ec2b1570a42c833fd34fe1 Mon Sep 17 00:00:00 2001 From: Ivan Date: Mon, 8 Apr 2024 20:29:30 +0300 Subject: [PATCH 2/3] move transaction data parsing to separate method --- lib/apis/utils/extensions.dart | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/apis/utils/extensions.dart b/lib/apis/utils/extensions.dart index 2a6b08ee..ddfa776e 100644 --- a/lib/apis/utils/extensions.dart +++ b/lib/apis/utils/extensions.dart @@ -36,13 +36,17 @@ extension TransactionExtension2 on Map { (this['maxPriorityFeePerGas'] as String?).toEthereAmount(), maxGas: (this['maxGas'] as String?).toIntFromHex(), nonce: (this['nonce'] as String?).toInt(), - data: (this['data'] != null && this['data'] != '0x') - ? Uint8List.fromList(hex.decode(this['data']!.startsWith('0x') - ? this['data']!.substring(2) - : this['data']!)) - : null, + data: _parseTransactionData(this['data']), ); } + + Uint8List? _parseTransactionData(dynamic data) { + if (data != null && data != '0x') { + return Uint8List.fromList(hex.decode( + data.startsWith('0x') ? data.substring(2) : data)); + } + return null; + } } extension EtheraAmountExtension on String? { From 61aceb6ef24b7fc3d8de602ef694ab78d105aac7 Mon Sep 17 00:00:00 2001 From: Alfreedom <00tango.bromine@icloud.com> Date: Tue, 9 Apr 2024 13:08:37 +0200 Subject: [PATCH 3/3] Move new method outside of extension --- lib/apis/utils/extensions.dart | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/apis/utils/extensions.dart b/lib/apis/utils/extensions.dart index ddfa776e..41cf73cc 100644 --- a/lib/apis/utils/extensions.dart +++ b/lib/apis/utils/extensions.dart @@ -39,14 +39,16 @@ extension TransactionExtension2 on Map { data: _parseTransactionData(this['data']), ); } +} - Uint8List? _parseTransactionData(dynamic data) { - if (data != null && data != '0x') { - return Uint8List.fromList(hex.decode( - data.startsWith('0x') ? data.substring(2) : data)); +Uint8List? _parseTransactionData(dynamic data) { + if (data != null && data != '0x') { + if (data.startsWith('0x')) { + return Uint8List.fromList(hex.decode(data.substring(2))); } - return null; + return Uint8List.fromList(hex.decode(data)); } + return null; } extension EtheraAmountExtension on String? {