From 3a19c119f8c158950065da772dc02acd838537d0 Mon Sep 17 00:00:00 2001 From: Bibash Shrestha Date: Tue, 18 Jul 2023 14:28:41 +0545 Subject: [PATCH] feat: Support for polygon Id for civic and ethereum transaction update --- .../model/ethereum_transaction.dart | 4 +- .../cubit/wallet_connect_cubit.dart | 74 +++++++++++-------- .../cubit/qr_code_scan_cubit.dart | 4 +- 3 files changed, 48 insertions(+), 34 deletions(-) diff --git a/lib/connection_bridge/model/ethereum_transaction.dart b/lib/connection_bridge/model/ethereum_transaction.dart index 4ba5613ca..975359495 100644 --- a/lib/connection_bridge/model/ethereum_transaction.dart +++ b/lib/connection_bridge/model/ethereum_transaction.dart @@ -7,7 +7,7 @@ class EthereumTransaction { EthereumTransaction({ required this.from, required this.to, - required this.value, + this.value, this.nonce, this.gasPrice, this.maxFeePerGas, @@ -21,7 +21,7 @@ class EthereumTransaction { _$EthereumTransactionFromJson(json); final String from; final String to; - final String value; + final String? value; final String? nonce; final String? gasPrice; final String? maxFeePerGas; diff --git a/lib/connection_bridge/wallet_connect/cubit/wallet_connect_cubit.dart b/lib/connection_bridge/wallet_connect/cubit/wallet_connect_cubit.dart index 6a642a41a..f47bf51ad 100644 --- a/lib/connection_bridge/wallet_connect/cubit/wallet_connect_cubit.dart +++ b/lib/connection_bridge/wallet_connect/cubit/wallet_connect_cubit.dart @@ -357,7 +357,7 @@ class WalletConnectCubit extends Cubit { log.i('completer initialise'); completer.add(Completer()); - final transaction = getTransaction(parameters); + final Transaction transaction = getTransaction(parameters); emit( state.copyWith( @@ -422,38 +422,50 @@ class WalletConnectCubit extends Cubit { parameters[0] as Map, ); + final from = EthereumAddress.fromHex(ethTransaction.from); + final to = EthereumAddress.fromHex(ethTransaction.to); + final value = EtherAmount.fromBigInt( + EtherUnit.wei, + ethTransaction.value != null + ? BigInt.tryParse(ethTransaction.value!) ?? BigInt.zero + : BigInt.zero, + ); + // final gasPrice = ethTransaction.gasPrice != null + // ? EtherAmount.fromBigInt( + // EtherUnit.gwei, + // BigInt.tryParse(ethTransaction.gasPrice!) ?? BigInt.zero, + // ) + // : null; + // final maxFeePerGas = ethTransaction.maxFeePerGas != null + // ? EtherAmount.fromBigInt( + // EtherUnit.gwei, + // BigInt.tryParse(ethTransaction.maxFeePerGas!) ?? BigInt.zero, + // ) + // : null; + // final maxPriorityFeePerGas = ethTransaction.maxPriorityFeePerGas != null + // ? EtherAmount.fromBigInt( + // EtherUnit.gwei, + // BigInt.tryParse(ethTransaction.maxPriorityFeePerGas!) ?? + // BigInt.zero, + // ) + // : null; + // final maxGas = int.tryParse(ethTransaction.gasLimit ?? ''); + // final nonce = int.tryParse(ethTransaction.nonce ?? ''); + final data = (ethTransaction.data != null && ethTransaction.data != '0x') + ? Uint8List.fromList(utf8.encode(ethTransaction.data!)) + : null; + // Construct a transaction from the EthereumTransaction object final transaction = Transaction( - from: EthereumAddress.fromHex(ethTransaction.from), - to: EthereumAddress.fromHex(ethTransaction.to), - value: EtherAmount.fromBigInt( - EtherUnit.wei, - BigInt.tryParse(ethTransaction.value) ?? BigInt.zero, - ), - gasPrice: ethTransaction.gasPrice != null - ? EtherAmount.fromBigInt( - EtherUnit.gwei, - BigInt.tryParse(ethTransaction.gasPrice!) ?? BigInt.zero, - ) - : null, - maxFeePerGas: ethTransaction.maxFeePerGas != null - ? EtherAmount.fromBigInt( - EtherUnit.gwei, - BigInt.tryParse(ethTransaction.maxFeePerGas!) ?? BigInt.zero, - ) - : null, - maxPriorityFeePerGas: ethTransaction.maxPriorityFeePerGas != null - ? EtherAmount.fromBigInt( - EtherUnit.gwei, - BigInt.tryParse(ethTransaction.maxPriorityFeePerGas!) ?? - BigInt.zero, - ) - : null, - maxGas: int.tryParse(ethTransaction.gasLimit ?? ''), - nonce: int.tryParse(ethTransaction.nonce ?? ''), - data: (ethTransaction.data != null && ethTransaction.data != '0x') - ? Uint8List.fromList(hex.decode(ethTransaction.data!)) - : null, + from: from, + to: to, + value: value, + // gasPrice: gasPrice, + // maxFeePerGas: maxFeePerGas, + // maxPriorityFeePerGas: maxPriorityFeePerGas, + // maxGas: maxGas, + // nonce: nonce, + data: data, ); return transaction; diff --git a/lib/dashboard/qr_code/qr_code_scan/cubit/qr_code_scan_cubit.dart b/lib/dashboard/qr_code/qr_code_scan/cubit/qr_code_scan_cubit.dart index a36f5ee24..806a308f3 100644 --- a/lib/dashboard/qr_code/qr_code_scan/cubit/qr_code_scan_cubit.dart +++ b/lib/dashboard/qr_code/qr_code_scan/cubit/qr_code_scan_cubit.dart @@ -89,7 +89,9 @@ class QRCodeScanCubit extends Cubit { /// wallet connect await walletConnectCubit.connect(scannedResponse); emit(state.copyWith(qrScanStatus: QrScanStatus.goBack)); - } else if (scannedResponse.startsWith('{"id":')) { + } else if (scannedResponse.startsWith('{"id":') || + scannedResponse.startsWith('{"body":{"callbackUrl":"') || + scannedResponse.startsWith('{"from": "did:polygonid:')) { /// polygon id emit(state.copyWith(qrScanStatus: QrScanStatus.goBack)); await polygonIdCubit.polygonIdFunction(scannedResponse);