Skip to content

Commit

Permalink
feat: Support for polygon Id for civic and ethereum transaction update
Browse files Browse the repository at this point in the history
  • Loading branch information
bibash28 committed Jul 18, 2023
1 parent 1cd3653 commit 3a19c11
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 34 deletions.
4 changes: 2 additions & 2 deletions lib/connection_bridge/model/ethereum_transaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class EthereumTransaction {
EthereumTransaction({
required this.from,
required this.to,
required this.value,
this.value,
this.nonce,
this.gasPrice,
this.maxFeePerGas,
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ class WalletConnectCubit extends Cubit<WalletConnectState> {
log.i('completer initialise');
completer.add(Completer<String>());

final transaction = getTransaction(parameters);
final Transaction transaction = getTransaction(parameters);

emit(
state.copyWith(
Expand Down Expand Up @@ -422,38 +422,50 @@ class WalletConnectCubit extends Cubit<WalletConnectState> {
parameters[0] as Map<String, dynamic>,
);

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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
/// 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);
Expand Down

0 comments on commit 3a19c11

Please sign in to comment.