Add logging for accessing URLs

pull/3237/head
Vladyslav shepitko 3 years ago committed by Hwee-Boon Yar
parent 5d6a477b3e
commit 9ff766da56
  1. 12
      AlphaWallet.xcodeproj/project.pbxproj
  2. 1
      AlphaWallet/Browser/ViewControllers/BrowserViewController.swift
  3. 14
      AlphaWallet/Core/Coordinators/WalletBalance/PrivateBalanceFetcher.swift
  4. 34
      AlphaWallet/Rest/RestClient.swift
  5. 4
      AlphaWallet/TokenScriptClient/Coordinators/AssetDefinitionStoreCoordinator.swift
  6. 1
      AlphaWallet/Tokens/Coordinators/SingleChainTokenCoordinator.swift
  7. 1
      AlphaWallet/Tokens/Helpers/TokenAdaptor.swift
  8. 2
      AlphaWallet/Tokens/Logic/Erc1155TokenIdsFetcher.swift
  9. 1
      AlphaWallet/Tokens/Views/TokenListFormatRowView.swift
  10. 4
      AlphaWallet/Transactions/Storage/TransactionsStorage.swift
  11. 20
      AlphaWallet/UI/TokenObject+UI.swift

@ -926,7 +926,6 @@
AA26C62420412A4100318B9B /* Double.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA26C62220412A4100318B9B /* Double.swift */; }; AA26C62420412A4100318B9B /* Double.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA26C62220412A4100318B9B /* Double.swift */; };
AA26C628204134C500318B9B /* TokenCardTableViewCellWithoutCheckbox.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA26C627204134C500318B9B /* TokenCardTableViewCellWithoutCheckbox.swift */; }; AA26C628204134C500318B9B /* TokenCardTableViewCellWithoutCheckbox.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA26C627204134C500318B9B /* TokenCardTableViewCellWithoutCheckbox.swift */; };
AA4E531820425A9500143A09 /* Date.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA4E531720425A9500143A09 /* Date.swift */; }; AA4E531820425A9500143A09 /* Date.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA4E531720425A9500143A09 /* Date.swift */; };
AA574E632054ECA400F4B3AF /* RestClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA574E622054ECA400F4B3AF /* RestClient.swift */; };
AA893ED5203C3E5400CDCED1 /* TokenBalance.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA893ED4203C3E5400CDCED1 /* TokenBalance.swift */; }; AA893ED5203C3E5400CDCED1 /* TokenBalance.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA893ED4203C3E5400CDCED1 /* TokenBalance.swift */; };
AAEF2CAB2050A68A0038BE0D /* SignatureHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAEF2CAA2050A68A0038BE0D /* SignatureHelper.swift */; }; AAEF2CAB2050A68A0038BE0D /* SignatureHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAEF2CAA2050A68A0038BE0D /* SignatureHelper.swift */; };
BB5D6A9E20232EE8000FC5AB /* CurrencyRate+Fee.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB5D6A9D20232EE8000FC5AB /* CurrencyRate+Fee.swift */; }; BB5D6A9E20232EE8000FC5AB /* CurrencyRate+Fee.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB5D6A9D20232EE8000FC5AB /* CurrencyRate+Fee.swift */; };
@ -1927,7 +1926,6 @@
AA26C62220412A4100318B9B /* Double.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Double.swift; sourceTree = "<group>"; }; AA26C62220412A4100318B9B /* Double.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Double.swift; sourceTree = "<group>"; };
AA26C627204134C500318B9B /* TokenCardTableViewCellWithoutCheckbox.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TokenCardTableViewCellWithoutCheckbox.swift; sourceTree = "<group>"; }; AA26C627204134C500318B9B /* TokenCardTableViewCellWithoutCheckbox.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TokenCardTableViewCellWithoutCheckbox.swift; sourceTree = "<group>"; };
AA4E531720425A9500143A09 /* Date.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Date.swift; sourceTree = "<group>"; }; AA4E531720425A9500143A09 /* Date.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Date.swift; sourceTree = "<group>"; };
AA574E622054ECA400F4B3AF /* RestClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RestClient.swift; sourceTree = "<group>"; };
AA893ED4203C3E5400CDCED1 /* TokenBalance.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TokenBalance.swift; sourceTree = "<group>"; }; AA893ED4203C3E5400CDCED1 /* TokenBalance.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TokenBalance.swift; sourceTree = "<group>"; };
AAEF2CAA2050A68A0038BE0D /* SignatureHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignatureHelper.swift; sourceTree = "<group>"; }; AAEF2CAA2050A68A0038BE0D /* SignatureHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignatureHelper.swift; sourceTree = "<group>"; };
B1CCA9D1215B615A0000FBF7 /* ja */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ja; path = ja.lproj/Localizable.strings; sourceTree = "<group>"; }; B1CCA9D1215B615A0000FBF7 /* ja */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ja; path = ja.lproj/Localizable.strings; sourceTree = "<group>"; };
@ -2062,7 +2060,6 @@
87BBF9682563DD7500FF4846 /* WalletConnect */, 87BBF9682563DD7500FF4846 /* WalletConnect */,
878EE942255BC352000210DE /* Share */, 878EE942255BC352000210DE /* Share */,
C80DC77C22AB7FAD009CFA1C /* TokenScriptFiles */, C80DC77C22AB7FAD009CFA1C /* TokenScriptFiles */,
AA574E612054EC8B00F4B3AF /* Rest */,
C8803302205436EE00D73D6F /* ImagesOutsideAssetCatalog */, C8803302205436EE00D73D6F /* ImagesOutsideAssetCatalog */,
C876FF69204A77B400B7D0EA /* Fonts */, C876FF69204A77B400B7D0EA /* Fonts */,
73ACEEF620163B4E003DD71D /* Lock */, 73ACEEF620163B4E003DD71D /* Lock */,
@ -4610,14 +4607,6 @@
path = ABI; path = ABI;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
AA574E612054EC8B00F4B3AF /* Rest */ = {
isa = PBXGroup;
children = (
AA574E622054ECA400F4B3AF /* RestClient.swift */,
);
path = Rest;
sourceTree = "<group>";
};
AAEF2CA92050A64F0038BE0D /* Helpers */ = { AAEF2CA92050A64F0038BE0D /* Helpers */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
@ -5282,7 +5271,6 @@
291D73C61F7F500D00A8AB56 /* TransactionItemState.swift in Sources */, 291D73C61F7F500D00A8AB56 /* TransactionItemState.swift in Sources */,
29BE3FD21F707DC300F6BFC2 /* TransactionDataCoordinator.swift in Sources */, 29BE3FD21F707DC300F6BFC2 /* TransactionDataCoordinator.swift in Sources */,
29F1C85120032688003780D8 /* Address.swift in Sources */, 29F1C85120032688003780D8 /* Address.swift in Sources */,
AA574E632054ECA400F4B3AF /* RestClient.swift in Sources */,
29FA00D4201EC662002F7DC5 /* NSObject.swift in Sources */, 29FA00D4201EC662002F7DC5 /* NSObject.swift in Sources */,
771AA94E1FF971CD00D25403 /* DappAction.swift in Sources */, 771AA94E1FF971CD00D25403 /* DappAction.swift in Sources */,
29FF6D6B2011D2AF00A3011C /* InCoordinatorError.swift in Sources */, 29FF6D6B2011D2AF00A3011C /* InCoordinatorError.swift in Sources */,

@ -148,6 +148,7 @@ final class BrowserViewController: UIViewController {
func goTo(url: URL) { func goTo(url: URL) {
hideErrorView() hideErrorView()
verbose("Loading URL: \(url.absoluteString)")
webView.load(URLRequest(url: url)) webView.load(URLRequest(url: url))
} }

@ -273,13 +273,14 @@ class PrivateBalanceFetcher: PrivateBalanceFetcherType {
}.then { contractsAndTokenIds in }.then { contractsAndTokenIds in
self.addUnknownErc1155ContractsToDatabase(contractsAndTokenIds: contractsAndTokenIds.tokens, tokens: tokens) self.addUnknownErc1155ContractsToDatabase(contractsAndTokenIds: contractsAndTokenIds.tokens, tokens: tokens)
}.then { (contractsAndTokenIds: Erc1155TokenIds.ContractsAndTokenIds) -> Promise<(contractsAndTokenIds: Erc1155TokenIds.ContractsAndTokenIds, tokenIdMetaDatas: [TokenIdMetaData])> in }.then { (contractsAndTokenIds: Erc1155TokenIds.ContractsAndTokenIds) -> Promise<(contractsAndTokenIds: Erc1155TokenIds.ContractsAndTokenIds, tokenIdMetaDatas: [TokenIdMetaData])> in
self.fetchErc1155NonFungibleJsons(contractsAndTokenIds: contractsAndTokenIds, tokens: tokens).map { (contractsAndTokenIds: contractsAndTokenIds, tokenIdMetaDatas: $0)} self.fetchErc1155NonFungibleJsons(contractsAndTokenIds: contractsAndTokenIds, tokens: tokens)
.map { (contractsAndTokenIds: contractsAndTokenIds, tokenIdMetaDatas: $0) }
}.then { (contractsAndTokenIds: Erc1155TokenIds.ContractsAndTokenIds, tokenIdMetaDatas: [TokenIdMetaData]) -> Promise<[TokenBatchOperation]> in }.then { (contractsAndTokenIds: Erc1155TokenIds.ContractsAndTokenIds, tokenIdMetaDatas: [TokenIdMetaData]) -> Promise<[TokenBatchOperation]> in
let contractsToTokenIds: [AlphaWallet.Address: [BigInt]] = contractsAndTokenIds.mapValues { tokenIds -> [BigInt] in let contractsToTokenIds: [AlphaWallet.Address: [BigInt]] = contractsAndTokenIds.mapValues { tokenIds -> [BigInt] in
tokenIds.compactMap { BigInt($0) } tokenIds.compactMap { BigInt($0) }
} }
let promises = contractsToTokenIds.map { contract, tokenIds in let promises = contractsToTokenIds.map { contract, tokenIds in
Erc1155BalanceFetcher(address: account.address, server: server).fetch(contract: contract, tokenIds: Set(tokenIds)).map { (contract: contract, balances: $0 )} Erc1155BalanceFetcher(address: account.address, server: server).fetch(contract: contract, tokenIds: Set(tokenIds)).map { (contract: contract, balances: $0 ) }
} }
return firstly { return firstly {
when(fulfilled: promises) when(fulfilled: promises)
@ -356,6 +357,7 @@ class PrivateBalanceFetcher: PrivateBalanceFetcherType {
struct Error: Swift.Error { struct Error: Swift.Error {
} }
let uri = originalUri.rewrittenIfIpfs let uri = originalUri.rewrittenIfIpfs
return firstly { return firstly {
//Must not use `SessionManager.default.request` or `Alamofire.request` which uses the former. See comment in var //Must not use `SessionManager.default.request` or `Alamofire.request` which uses the former. See comment in var
sessionManagerWithDefaultHttpHeaders.request(uri, method: .get).responseData() sessionManagerWithDefaultHttpHeaders.request(uri, method: .get).responseData()
@ -371,7 +373,7 @@ class PrivateBalanceFetcher: PrivateBalanceFetcherType {
jsonDictionary["contractName"] = JSON(tokenObject.name) jsonDictionary["contractName"] = JSON(tokenObject.name)
jsonDictionary["symbol"] = JSON(tokenObject.symbol) jsonDictionary["symbol"] = JSON(tokenObject.symbol)
jsonDictionary["tokenId"] = JSON(tokenId) jsonDictionary["tokenId"] = JSON(tokenId)
jsonDictionary["decimals"] = JSON(jsonDictionary["decimals"].intValue ?? 0) jsonDictionary["decimals"] = JSON(jsonDictionary["decimals"].intValue)
jsonDictionary["name"] = JSON(jsonDictionary["name"].stringValue) jsonDictionary["name"] = JSON(jsonDictionary["name"].stringValue)
jsonDictionary["imageUrl"] = JSON(jsonDictionary["image"].string ?? jsonDictionary["image_url"].string ?? "") jsonDictionary["imageUrl"] = JSON(jsonDictionary["image"].string ?? jsonDictionary["image_url"].string ?? "")
jsonDictionary["thumbnailUrl"] = jsonDictionary["imageUrl"] jsonDictionary["thumbnailUrl"] = jsonDictionary["imageUrl"]
@ -401,7 +403,9 @@ class PrivateBalanceFetcher: PrivateBalanceFetcherType {
} }
//OpenSea API output doesn't include the balance ("value") for each tokenId, it seems. So we have to fetch them: //OpenSea API output doesn't include the balance ("value") for each tokenId, it seems. So we have to fetch them:
let promises = contractsToTokenIds.map { contract, tokenIds in let promises = contractsToTokenIds.map { contract, tokenIds in
Erc1155BalanceFetcher(address: account.address, server: server).fetch(contract: contract, tokenIds: Set(tokenIds)).map { (contract: contract, balances: $0 )} Erc1155BalanceFetcher(address: account.address, server: server)
.fetch(contract: contract, tokenIds: Set(tokenIds))
.map { (contract: contract, balances: $0) }
} }
return firstly { return firstly {
when(fulfilled: promises) when(fulfilled: promises)
@ -437,7 +441,7 @@ extension PrivateBalanceFetcher {
fileprivate extension PrivateBalanceFetcher.functional { fileprivate extension PrivateBalanceFetcher.functional {
static func fetchUnknownErc1155ContractsDetails(contractsAndTokenIds: Erc1155TokenIds.ContractsAndTokenIds, tokens: [Activity.AssignedToken], server: RPCServer, account: Wallet, assetDefinitionStore: AssetDefinitionStore) -> Promise<[ERCToken]> { static func fetchUnknownErc1155ContractsDetails(contractsAndTokenIds: Erc1155TokenIds.ContractsAndTokenIds, tokens: [Activity.AssignedToken], server: RPCServer, account: Wallet, assetDefinitionStore: AssetDefinitionStore) -> Promise<[ERCToken]> {
let contractsToAdd: [AlphaWallet.Address] = contractsAndTokenIds.keys.filter { contract in let contractsToAdd: [AlphaWallet.Address] = contractsAndTokenIds.keys.filter { contract in
!tokens.contains(where: { $0.contractAddress.sameContract(as: contract)}) !tokens.contains(where: { $0.contractAddress.sameContract(as: contract) })
} }
guard !contractsToAdd.isEmpty else { return Promise<[ERCToken]>.value(.init()) } guard !contractsToAdd.isEmpty else { return Promise<[ERCToken]>.value(.init()) }
let (promise, seal) = Promise<[ERCToken]>.pending() let (promise, seal) = Promise<[ERCToken]>.pending()

@ -1,34 +0,0 @@
//
// RestClient.swift
// Alpha-Wallet
//
// Created by Oguzhan Gungor on 3/11/18.
// Copyright © 2018 Alpha-Wallet. All rights reserved.
//
import Foundation
import Alamofire
enum RestError: Error {
case invalidResponse(String)
}
struct RestClient {
static func get(endPoint: String,
parameters: [String: AnyHashable]? = nil,
completion: @escaping (_ response: DataResponse<Any>) -> Void) {
// TODO: params
Alamofire.request(endPoint, method: .get).responseJSON { response in
completion(response)
}
}
static func cancel() {
Alamofire.SessionManager.default.session.getTasksWithCompletionHandler { (sessionDataTask, uploadData, downloadData) in
sessionDataTask.forEach { $0.cancel() }
uploadData.forEach { $0.cancel() }
downloadData.forEach { $0.cancel() }
}
}
}

@ -120,9 +120,9 @@ class AssetDefinitionStoreCoordinator: Coordinator {
///For development ///For development
private func printInboxContents() { private func printInboxContents() {
guard let contents = inboxContents else { return } guard let contents = inboxContents else { return }
NSLog("Contents of inbox:") verbose("Contents of inbox:")
for each in contents { for each in contents {
NSLog(" In inbox: \(each)") verbose(" In inbox: \(each)")
} }
} }

@ -2,7 +2,6 @@
import Foundation import Foundation
import UIKit import UIKit
import Alamofire
import BigInt import BigInt
import RealmSwift import RealmSwift
import PromiseKit import PromiseKit

@ -210,7 +210,6 @@ class TokenAdaptor {
values["contractImageUrl"] = .init(directoryString: nonFungible.contractImageUrl) values["contractImageUrl"] = .init(directoryString: nonFungible.contractImageUrl)
values["thumbnailUrl"] = .init(directoryString: nonFungible.thumbnailUrl) values["thumbnailUrl"] = .init(directoryString: nonFungible.thumbnailUrl)
values["externalLink"] = .init(directoryString: nonFungible.externalLink) values["externalLink"] = .init(directoryString: nonFungible.externalLink)
values["externalLink"] = .init(directoryString: nonFungible.externalLink)
values["backgroundColor"] = nonFungible.backgroundColor.flatMap { .init(directoryString: $0) } values["backgroundColor"] = nonFungible.backgroundColor.flatMap { .init(directoryString: $0) }
values["traits"] = .init(openSeaTraits: nonFungible.traits) values["traits"] = .init(openSeaTraits: nonFungible.traits)
values["value"] = .init(int: nonFungible.value) values["value"] = .init(int: nonFungible.value)

@ -27,7 +27,7 @@ fileprivate struct Erc1155TransferEvent: Comparable {
let transactionIndex: BigUInt let transactionIndex: BigUInt
let logIndex: BigUInt let logIndex: BigUInt
static func <(lhs: Erc1155TransferEvent, rhs: Erc1155TransferEvent) -> Bool { static func < (lhs: Erc1155TransferEvent, rhs: Erc1155TransferEvent) -> Bool {
if lhs.blockNumber == rhs.blockNumber { if lhs.blockNumber == rhs.blockNumber {
if lhs.transactionIndex == rhs.transactionIndex { if lhs.transactionIndex == rhs.transactionIndex {
return lhs.logIndex < rhs.logIndex return lhs.logIndex < rhs.logIndex

@ -188,6 +188,7 @@ class TokenListFormatRowView: UIView {
//TODO cancel the request if we reuse the cell before it's finished downloading //TODO cancel the request if we reuse the cell before it's finished downloading
if let url = viewModel.thumbnailImageUrl { if let url = viewModel.thumbnailImageUrl {
var request = URLRequest(url: url) var request = URLRequest(url: url)
verbose("Loading thumbnail URL: \(url.absoluteString)")
request.httpMethod = "GET" request.httpMethod = "GET"
request.cachePolicy = .returnCacheDataElseLoad request.cachePolicy = .returnCacheDataElseLoad
Alamofire.request(request).response { [weak self] response in Alamofire.request(request).response { [weak self] response in

@ -315,9 +315,9 @@ class TransactionsStorage: Hashable {
do { do {
let data = try functional.generateJsonForTransactions(transactionStorage: self, toUrl: url) let data = try functional.generateJsonForTransactions(transactionStorage: self, toUrl: url)
try data.write(to: url) try data.write(to: url)
NSLog("Written transactions for \(server) to JSON to: \(url.absoluteString)") verbose("Written transactions for \(server) to JSON to: \(url.absoluteString)")
} catch { } catch {
NSLog("Error writing transactions for \(server) to JSON: \(url.absoluteString) error: \(error)") verbose("Error writing transactions for \(server) to JSON: \(url.absoluteString) error: \(error)")
} }
} }

@ -158,21 +158,11 @@ class TokenImageFetcher {
} }
private static func fetch(request: URLRequest, queue: DispatchQueue) -> Promise<UIImage> { private static func fetch(request: URLRequest, queue: DispatchQueue) -> Promise<UIImage> {
Promise { seal in Alamofire.request(request).responseData().map(on: queue) { response -> UIImage in
queue.async { if let img = UIImage(data: response.data) {
let task = URLSession.shared.dataTask(with: request) { data, _, _ in return img
if let data = data { } else {
let image = UIImage(data: data) throw ImageAvailabilityError.notAvailable
if let img = image {
seal.fulfill(img)
} else {
seal.reject(ImageAvailabilityError.notAvailable)
}
} else {
seal.reject(ImageAvailabilityError.notAvailable)
}
}
task.resume()
} }
} }
} }

Loading…
Cancel
Save