diff --git a/lib/wallets/wallet/wallet_mixin_interfaces/electrumx_interface.dart b/lib/wallets/wallet/wallet_mixin_interfaces/electrumx_interface.dart index a640034a2..6b90245eb 100644 --- a/lib/wallets/wallet/wallet_mixin_interfaces/electrumx_interface.dart +++ b/lib/wallets/wallet/wallet_mixin_interfaces/electrumx_interface.dart @@ -35,6 +35,8 @@ mixin ElectrumXInterface on Bip39HDWallet { int? get maximumFeerate => null; + int? latestHeight; + static const _kServerBatchCutoffVersion = [1, 6]; List? _serverVersion; bool get serverCanBatch { @@ -802,6 +804,16 @@ mixin ElectrumXInterface on Bip39HDWallet { final subscription = subscribableElectrumXClient.subscribeToBlockHeaders(); + // Don't add a listener if one already exists. + if (subscription.hasListeners) { + if (latestHeight != null) { + return latestHeight!; + } else { + // Wait for first response. + return completer.future; + } + } + // Make sure we only complete once. bool isFirstResponse = true; @@ -813,6 +825,7 @@ mixin ElectrumXInterface on Bip39HDWallet { response.containsKey('height')) { final int chainHeight = response['height'] as int; // print("Current chain height: $chainHeight"); + latestHeight = chainHeight; if (isFirstResponse) { isFirstResponse = false;