diff --git a/src/status/libstatus/stickers.nim b/src/status/libstatus/stickers.nim index 0c6e53bd54..a05d0677ed 100644 --- a/src/status/libstatus/stickers.nim +++ b/src/status/libstatus/stickers.nim @@ -137,6 +137,7 @@ proc getPackData*(id: Stuint[256], running: var Atomic[bool]): StickerPack = sticker.packId = truncate(id, int)) result.id = truncate(id, int) result.price = packData.price + client.close() proc tokenOfOwnerByIndex*(address: Address, idx: Stuint[256]): int = let diff --git a/src/status/wallet.nim b/src/status/wallet.nim index cafa6a00ad..a1f90f5742 100644 --- a/src/status/wallet.nim +++ b/src/status/wallet.nim @@ -356,16 +356,18 @@ proc getGasPricePredictions*(): GasPricePrediction = if status_settings.getCurrentNetwork() != Network.Mainnet: # TODO: what about other chains like xdai? return GasPricePrediction(safeLow: 1.0, standard: 2.0, fast: 3.0, fastest: 4.0) + let secureSSLContext = newContext() + let client = newHttpClient(sslContext = secureSSLContext) try: let url: string = fmt"https://etherchain.org/api/gasPriceOracle" - let secureSSLContext = newContext() - let client = newHttpClient(sslContext = secureSSLContext) client.headers = newHttpHeaders({ "Content-Type": "application/json" }) let response = client.request(url) result = Json.decode(response.body, GasPricePrediction) except Exception as e: echo "error getting gas price predictions" echo e.msg + finally: + client.close() proc checkRecentHistory*(self: WalletModel, addresses: seq[string]): string = result = status_wallet.checkRecentHistory(addresses) diff --git a/src/status/wallet/balance_manager.nim b/src/status/wallet/balance_manager.nim index fc983735a2..048e423786 100644 --- a/src/status/wallet/balance_manager.nim +++ b/src/status/wallet/balance_manager.nim @@ -21,10 +21,10 @@ proc newBalanceManager*(): BalanceManager = var balanceManager = newBalanceManager() proc getPrice(crypto: string, fiat: string): string = + let secureSSLContext = newContext() + let client = newHttpClient(sslContext = secureSSLContext) try: let url: string = fmt"https://min-api.cryptocompare.com/data/price?fsym={crypto}&tsyms={fiat}" - let secureSSLContext = newContext() - let client = newHttpClient(sslContext = secureSSLContext) client.headers = newHttpHeaders({ "Content-Type": "application/json" }) let response = client.request(url) @@ -32,6 +32,8 @@ proc getPrice(crypto: string, fiat: string): string = except Exception as e: error "Error getting price", message = e.msg result = "0.0" + finally: + client.close() proc getEthBalance(address: string): string = var balance = status_wallet.getBalance(address)