mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-01-19 05:45:15 +01:00
Update WidgetAPI+Electrum.swift
This commit is contained in:
parent
52fa81c30b
commit
28349782d3
@ -32,11 +32,17 @@ extension WidgetAPI {
|
||||
completion(nil, APIError())
|
||||
return
|
||||
}
|
||||
if let response = String(bytes: data, encoding: .utf8), let nextBlockResponse = response.components(separatedBy: #"result":"#).last?.components(separatedBy: ",").first, let nextBlockResponseDouble = Double(nextBlockResponse.trimmingCharacters(in: .whitespacesAndNewlines)) {
|
||||
let characterSet = Set("0123456789.")
|
||||
if let response = String(bytes: data, encoding: .utf8), let nextBlockResponse = response.components(separatedBy: #"result":"#).last?.components(separatedBy: ",").first, let nextBlockResponseDouble = Double(nextBlockResponse.filter({characterSet.contains($0)}).trimmingCharacters(in: .whitespacesAndNewlines)) {
|
||||
print("Successfully obtained response from Electrum sever")
|
||||
print(userElectrumSettings)
|
||||
let marketData = MarketData(nextBlock: String(format: "%.0f", (nextBlockResponseDouble / 1024) * 100000000), sats: "0", price: "0", rate: 0)
|
||||
client.close()
|
||||
completion(MarketData(nextBlock: String(format: "%.0f", (nextBlockResponseDouble / 1024) * 100000000), sats: "0", price: "0", rate: 0), nil)
|
||||
completion(marketData, nil)
|
||||
} else {
|
||||
client.close()
|
||||
completion(nil, APIError())
|
||||
}
|
||||
case .failure(let error):
|
||||
print(error)
|
||||
@ -49,7 +55,7 @@ extension WidgetAPI {
|
||||
if userElectrumSettings.host == DefaultElectrumPeers.last?.host {
|
||||
completion(nil, APIError())
|
||||
} else if let currentIndex = DefaultElectrumPeers.firstIndex(where: {$0.host == userElectrumSettings.host}) {
|
||||
fetchNextBlockFee(completion: completion, userElectrumSettings: DefaultElectrumPeers[DefaultElectrumPeers.index(after: currentIndex)])
|
||||
fetchNextBlockFee(completion: completion, userElectrumSettings: DefaultElectrumPeers[DefaultElectrumPeers.index(after: currentIndex)])
|
||||
} else {
|
||||
if let first = DefaultElectrumPeers.first {
|
||||
fetchNextBlockFee(completion: completion, userElectrumSettings: first)
|
||||
|
Loading…
Reference in New Issue
Block a user