mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-22 18:44:31 +00:00
don't add a listener if one already exists
This commit is contained in:
parent
a3b3314be8
commit
7863b7f209
1 changed files with 13 additions and 0 deletions
|
@ -35,6 +35,8 @@ mixin ElectrumXInterface<T extends Bip39HDCurrency> on Bip39HDWallet<T> {
|
|||
|
||||
int? get maximumFeerate => null;
|
||||
|
||||
int? latestHeight;
|
||||
|
||||
static const _kServerBatchCutoffVersion = [1, 6];
|
||||
List<int>? _serverVersion;
|
||||
bool get serverCanBatch {
|
||||
|
@ -802,6 +804,16 @@ mixin ElectrumXInterface<T extends Bip39HDCurrency> on Bip39HDWallet<T> {
|
|||
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<T extends Bip39HDCurrency> on Bip39HDWallet<T> {
|
|||
response.containsKey('height')) {
|
||||
final int chainHeight = response['height'] as int;
|
||||
// print("Current chain height: $chainHeight");
|
||||
latestHeight = chainHeight;
|
||||
|
||||
if (isFirstResponse) {
|
||||
isFirstResponse = false;
|
||||
|
|
Loading…
Reference in a new issue