CW-289-Fix bitcoin pending send receive transactions not showing until confirmed (#878)

* Fix error in rendering pending transactions in different device * Show pending status * Fix broken subscription stream

Godwin Asuquo committed Apr 20, 2023 at 23:20 UTC 3fc927f742c1217cbfdffcb6306fedcf173050c7
3 files changed +9 -7
cw_bitcoin/lib/electrum.dart
+6 -4
@@ -410,7 +410,7 @@ class ElectrumClient {
410 switch (method) {
411 case 'blockchain.scripthash.subscribe':
412 final params = request['params'] as List<dynamic>;
413 - final scripthash = params.first as String;
413 + final scripthash = params.first as String?;
414 final id = 'blockchain.scripthash.subscribe:$scripthash';
415
416 _tasks[id]?.subject?.add(params.last);
@@ -430,15 +430,17 @@ class ElectrumClient {
430
431 void _handleResponse(Map<String, dynamic> response) {
432 final method = response['method'];
433 - final id = response['id'] as String;
433 + final id = response['id'] as String?;
434 final result = response['result'];
435
436 if (method is String) {
437 _methodHandler(method: method, request: response);
438 return;
439 }
440 -
441 - _finish(id, result);
440 +
441 + if (id != null){
442 + _finish(id, result);
443 + }
444 }
445 }
446
cw_bitcoin/lib/electrum_transaction_info.dart
+1 -1
@@ -136,7 +136,7 @@ class ElectrumTransactionInfo extends TransactionInfo {
136 return ElectrumTransactionInfo(type,
137 id: bundle.originalTransaction.getId(),
138 height: height,
139 - isPending: false,
139 + isPending: bundle.confirmations == 0,
140 fee: fee,
141 direction: direction,
142 amount: amount,
cw_bitcoin/lib/electrum_wallet.dart
+2 -2
@@ -537,8 +537,8 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
537 final transactionHex = verboseTransaction['hex'] as String;
538 final original = bitcoin.Transaction.fromHex(transactionHex);
539 final ins = <bitcoin.Transaction>[];
540 - final time = verboseTransaction['time'] as int;
541 - final confirmations = verboseTransaction['confirmations'] as int ?? 0;
540 + final time = verboseTransaction['time'] as int?;
541 + final confirmations = verboseTransaction['confirmations'] as int? ?? 0;
542
543 for (final vin in original.ins) {
544 final id = HEX.encode(vin.hash!.reversed.toList());