Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update getAccountBalances method in Kraken to safely unrwarp arrayOfCryptoBalances #17

Closed
maakle opened this issue Jul 3, 2018 · 1 comment

Comments

@maakle
Copy link
Contributor

maakle commented Jul 3, 2018

Hey,

you should update the getAccountBalances method to this once here and safely unwrap arrayOfCryptoBalances since it will lead to a fatal crash in case a user has once set up the API correctly but then deletes the keys on the website and comes back to the App. This here at least won't lead to the App crashing:

public func getAccountBalances(completion: @escaping (ResponseType) -> Void) {
            let apiType = Kraken.API.getAccountBalance
            if apiType.checkInterval(response: store.balanceResponse) {
                completion(.cached)
            } else {
                krakenDataTaskFor(api: apiType) { (response) in
                    
                    guard let json = response.json as? Dictionary<String, Any> else {
                        print("Error: Cast Failed in \(#function)")
                        return
                    }
                    if let arrayOfCryptoBalances = json["result"] as? Dictionary<String,String> {
                        var balances: [Balance] = []
                        
                        for cryptoBalance in arrayOfCryptoBalances {
                            let newBalance = ["type": cryptoBalance.key,
                                              "amount": cryptoBalance.value,
                                              "available": cryptoBalance.value]
                            
                            balances.append(Balance(json: newBalance, currencyStore: self))
                        }
                        
                        self.store.balances = balances
                        self.store.balanceResponse = response.httpResponse
                        completion(.fetched)
                    }
                }.resume()
            }
        }
@trsathya
Copy link
Owner

trsathya commented Jan 3, 2019

This is fixed in #19

@trsathya trsathya closed this as completed Jan 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants