Fix: add defensive check to avoid crash when attempting to update native crypto currency balance

pull/1658/head
Hwee-Boon Yar 5 years ago
parent f2b02804e3
commit 95ba65e5fa
  1. 5
      AlphaWallet/Tokens/Types/TokensDataStore.swift

@ -507,9 +507,10 @@ class TokensDataStore {
guard let strongSelf = self else { return }
switch result {
case .success(let balance):
let token = strongSelf.token(forContract: Constants.nativeCryptoAddressInDatabase)
//Defensive check, instead of force unwrapping the result. At least one crash due to token being nil. Perhaps a Realm bug or in our code, perhaps in between enabling/disabling of chains? Harmless to do an early return
guard let token = strongSelf.token(forContract: Constants.nativeCryptoAddressInDatabase) else { return }
//TODO why is each chain's balance updated so many times? (if we add console logs)
strongSelf.update(token: token!, action: .value(balance.value))
strongSelf.update(token: token, action: .value(balance.value))
strongSelf.updateDelegate()
case .failure: break
}

Loading…
Cancel
Save