add missing http client close() so it doesn't run out of files

This commit is contained in:
Iuri Matias 2021-08-04 17:38:40 -04:00
parent 1d4beeb041
commit 553a698900
3 changed files with 9 additions and 4 deletions

View File

@ -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

View File

@ -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)
try:
let url: string = fmt"https://etherchain.org/api/gasPriceOracle"
let secureSSLContext = newContext()
let client = newHttpClient(sslContext = secureSSLContext)
try:
let url: string = fmt"https://etherchain.org/api/gasPriceOracle"
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)

View File

@ -21,10 +21,10 @@ proc newBalanceManager*(): BalanceManager =
var balanceManager = newBalanceManager()
proc getPrice(crypto: string, fiat: string): string =
try:
let url: string = fmt"https://min-api.cryptocompare.com/data/price?fsym={crypto}&tsyms={fiat}"
let secureSSLContext = newContext()
let client = newHttpClient(sslContext = secureSSLContext)
try:
let url: string = fmt"https://min-api.cryptocompare.com/data/price?fsym={crypto}&tsyms={fiat}"
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)