From bcb39c39065d04c3907855e1139358732b3c184c Mon Sep 17 00:00:00 2001 From: julian Date: Fri, 3 May 2024 15:42:21 -0600 Subject: [PATCH] no need for class wide htt client property, and close the client before assigning a new one --- lib/wallets/wallet/impl/stellar_wallet.dart | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/wallets/wallet/impl/stellar_wallet.dart b/lib/wallets/wallet/impl/stellar_wallet.dart index edea60fe5..a2ad93083 100644 --- a/lib/wallets/wallet/impl/stellar_wallet.dart +++ b/lib/wallets/wallet/impl/stellar_wallet.dart @@ -46,7 +46,6 @@ class StellarWallet extends Bip39Wallet { // ============== Private ==================================================== stellar.StellarSDK? _stellarSdk; - HttpClient? _httpClient; Future _getBaseFee() async { final fees = await stellarSdk.feeStats.execute(); @@ -55,6 +54,7 @@ class StellarWallet extends Bip39Wallet { void _updateSdk() { final currentNode = getCurrentNode(); + HttpClient? _httpClient; // TODO [prio=med]: refactor out and call before requests in case Tor is enabled/disabled, listen to prefs change, or similar. if (prefs.useTor) { @@ -63,13 +63,21 @@ class StellarWallet extends Bip39Wallet { _httpClient = HttpClient(); SocksTCPClient.assignToHttpClient( - _httpClient!, [ProxySettings(proxyInfo.host, proxyInfo.port)]); - } else { - _httpClient = null; + _httpClient, + [ + ProxySettings( + proxyInfo.host, + proxyInfo.port, + ), + ], + ); } - _stellarSdk = stellar.StellarSDK("${currentNode.host}:${currentNode.port}", - httpClient: _httpClient); + _stellarSdk?.httpClient.close(); + _stellarSdk = stellar.StellarSDK( + "${currentNode.host}:${currentNode.port}", + httpClient: _httpClient, + ); } Future _accountExists(String accountId) async {