From 3036c40c18de9850ccdca6ac65c48e973421ece0 Mon Sep 17 00:00:00 2001 From: James Sangalli Date: Wed, 27 Jun 2018 23:13:25 +1000 Subject: [PATCH 1/9] almost working with web3swift ecrecover --- .../UniversalLinkCoordinator.swift | 177 +++++++++--------- 1 file changed, 93 insertions(+), 84 deletions(-) diff --git a/AlphaWallet/Market/Coordinators/UniversalLinkCoordinator.swift b/AlphaWallet/Market/Coordinators/UniversalLinkCoordinator.swift index f3c157b87..63a7c6724 100644 --- a/AlphaWallet/Market/Coordinators/UniversalLinkCoordinator.swift +++ b/AlphaWallet/Market/Coordinators/UniversalLinkCoordinator.swift @@ -5,7 +5,7 @@ import Alamofire import BigInt import Realm import TrustKeystore -//import web3swift +import web3swift protocol UniversalLinkCoordinatorDelegate: class { func viewControllerForPresenting(in coordinator: UniversalLinkCoordinator) -> UIViewController? @@ -114,8 +114,7 @@ class UniversalLinkCoordinator: Coordinator { return true } - //Returns true if handled - + //Returns true if handled func handleUniversalLink(url: URL) -> Bool { let prefix = UniversalLinkHandler().urlPrefix let matchedPrefix = url.description.hasPrefix(prefix) @@ -132,27 +131,57 @@ class UniversalLinkCoordinator: Coordinator { let isStormBirdContract = xmlAddress.eip55String.sameContract(as: signedOrder.order.contractAddress) importTicketViewController?.url = url importTicketViewController?.contract = signedOrder.order.contractAddress - //let recoveredSigner = web3.personal.ecrecover(personalMessage: Data(bytes: signedOrder.message), signature: signature) - getTicketDetailsAndEcRecover(signedOrder: signedOrder) { result in - if let goodResult = result { - //user can pay gas for free import links if they are not covered by our server - if signedOrder.order.price > 0 || !isStormBirdContract { - if let balance = self.ethBalance { - balance.subscribeOnce { value in - if value > signedOrder.order.price { - let _ = self.handlePaidUniversalLink(signedOrder: signedOrder, ticketHolder: goodResult) - } else { - if let price = self.ethPrice { - if price.value == nil { - let ethCost = self.convert(ethCost: signedOrder.order.price) - self.showImportError(errorMessage: R.string.localizable.aClaimTicketFailedNotEnoughEthTitle(), ticketHolder: goodResult, ethCost: ethCost.description) - } - price.subscribe { [weak self] value in - if let celf = self { - if let price = price.value { - let (ethCost, dollarCost) = celf.convert(ethCost: signedOrder.order.price, rate: price) - celf.showImportError(errorMessage: R.string.localizable.aClaimTicketFailedNotEnoughEthTitle(), ticketHolder: goodResult, ethCost: ethCost.description, dollarCost: dollarCost.description) - } + //need to hash message here because the web3swift implementation adds prefix + let messageHash = Data(bytes: signedOrder.message).sha3(.keccak256) + //note: web3swift takes the v value as v - 27, so we need to manually convert this + let vValue = signedOrder.signature.drop0x.substring(from: 128) + let vInt = Int(vValue, radix: 16)! - 27 + let vString = "0" + String(vInt) + let signature = "0x" + signedOrder.signature.drop0x.substring(from: 128) + vString + let nodeURL = Config().rpcURL + let recoveredSigner = web3(provider: Web3HttpProvider(nodeURL)!).personal.ecrecover( + hash: messageHash, + signature: Data(bytes: signature.hexa2Bytes) + ) + let recoverAddress = Address(string: try! recoveredSigner.dematerialize().address)! + let contractAsAddress = Address(string: signedOrder.order.contractAddress)! + //gather signer address balance + GetStormBirdBalanceCoordinator(web3: Web3Swift()).getStormBirdBalance(for: recoverAddress, contract: contractAsAddress) { result in + //filter null tickets + let filteredTokens = self.checkERC875TokensAreAvailable( + indices: signedOrder.order.indices, + balance: try! result.dematerialize() + ) + if filteredTokens.isEmpty { + self.showImportError(errorMessage: R.string.localizable.aClaimTicketInvalidLinkTryAgain()) + } + + let ticketHolder = self.sortTickets( + filteredTokens, + signedOrder.order.indices, + signedOrder.order.contractAddress + ) + + if signedOrder.order.price > 0 || !isStormBirdContract { + if let balance = self.ethBalance { + balance.subscribeOnce { value in + if value > signedOrder.order.price { + let _ = self.handlePaidUniversalLink(signedOrder: signedOrder, ticketHolder: ticketHolder) + } else { + if let price = self.ethPrice { + if price.value == nil { + let ethCost = self.convert(ethCost: signedOrder.order.price) + self.showImportError( + errorMessage: R.string.localizable.aClaimTicketFailedNotEnoughEthTitle(), + ticketHolder: ticketHolder, + ethCost: ethCost.description + ) + } + price.subscribe { [weak self] value in + if let celf = self { + if let price = price.value { + let (ethCost, dollarCost) = celf.convert(ethCost: signedOrder.order.price, rate: price) + celf.showImportError(errorMessage: R.string.localizable.aClaimTicketFailedNotEnoughEthTitle(), ticketHolder: ticketHolder, ethCost: ethCost.description, dollarCost: dollarCost.description) } } } @@ -160,79 +189,42 @@ class UniversalLinkCoordinator: Coordinator { } } } - else { - let _ = self.usePaymentServerForFreeTransferLinks( - signedOrder: signedOrder, - ticketHolder: goodResult - ) - } - } else { - self.showImportError(errorMessage: R.string.localizable.aClaimTicketInvalidLinkTryAgain()) + } + else { + //free transfer + let _ = self.usePaymentServerForFreeTransferLinks( + signedOrder: signedOrder, + ticketHolder: ticketHolder + ) } } return true - } - - func importPaidSignedOrder(signedOrder: SignedOrder, tokenObject: TokenObject) { - updateImportTicketController(with: .processing) - delegate?.importPaidSignedOrder(signedOrder: signedOrder, tokenObject: tokenObject) { successful in - if self.importTicketViewController != nil { - if let vc = self.importTicketViewController, var _ = vc.viewModel { - if successful { - self.showImportSuccessful() - } else { - //TODO Pass in error message - self.showImportError(errorMessage: R.string.localizable.aClaimTicketFailedTitle()) - } - } - } - } - } private func stringEncodeIndices(_ indices: [UInt16]) -> String { return indices.map(String.init).joined(separator: ",") } - - private func getTicketDetailsAndEcRecover( - signedOrder: SignedOrder, - completion: @escaping( _ response: TicketHolder?) -> Void - ) { - let indices = signedOrder.order.indices - let parameters = createHTTPParametersForPaymentServer( - signedOrder: signedOrder, - isForTransfer: false - ) - - Alamofire.request(Constants.getTicketInfoFromServer, method: .get, parameters: parameters).responseJSON { response in - if let data = response.data, let utf8Text = String(data: data, encoding: .utf8) { - if let statusCode = response.response?.statusCode { - if statusCode > 299 { - completion(nil) - return - } - } - var array = utf8Text.split(separator: ",").map(String.init) - if array.isEmpty || array[0] == "invalid indices" { - completion(nil) - return + + func checkERC875TokensAreAvailable(indices: [UInt16], balance: [String]) -> [String] { + var filteredTokens = [String]() + if balance.count < indices.count { + return [String]() + } + for i in 0.. TicketHolder { var tickets = [Ticket]() let xmlHandler = XMLHandler() @@ -300,6 +292,23 @@ class UniversalLinkCoordinator: Coordinator { private func showImportError(errorMessage: String, ticketHolder: TicketHolder? = nil, ethCost: String? = nil, dollarCost: String? = nil) { updateImportTicketController(with: .failed(errorMessage: errorMessage), ticketHolder: ticketHolder, ethCost: ethCost, dollarCost: dollarCost) } + + func importPaidSignedOrder(signedOrder: SignedOrder, tokenObject: TokenObject) { + updateImportTicketController(with: .processing) + delegate?.importPaidSignedOrder(signedOrder: signedOrder, tokenObject: tokenObject) { successful in + if self.importTicketViewController != nil { + if let vc = self.importTicketViewController, var _ = vc.viewModel { + if successful { + self.showImportSuccessful() + } else { + //TODO Pass in error message + self.showImportError(errorMessage: R.string.localizable.aClaimTicketFailedTitle()) + } + } + } + } + + } //handling free transfers, sell links cannot be handled here private func importUniversalLink(query: String, parameters: Parameters) { From a17499e3f697682da5f829ef6308bbe8a24bee8d Mon Sep 17 00:00:00 2001 From: Hwee-Boon Yar Date: Thu, 28 Jun 2018 17:40:17 +0800 Subject: [PATCH 2/9] Add switch to handle ecrecover result enum --- .../UniversalLinkCoordinator.swift | 100 ++++++++++-------- 1 file changed, 55 insertions(+), 45 deletions(-) diff --git a/AlphaWallet/Market/Coordinators/UniversalLinkCoordinator.swift b/AlphaWallet/Market/Coordinators/UniversalLinkCoordinator.swift index 63a7c6724..dacf409ff 100644 --- a/AlphaWallet/Market/Coordinators/UniversalLinkCoordinator.swift +++ b/AlphaWallet/Market/Coordinators/UniversalLinkCoordinator.swift @@ -143,45 +143,50 @@ class UniversalLinkCoordinator: Coordinator { hash: messageHash, signature: Data(bytes: signature.hexa2Bytes) ) - let recoverAddress = Address(string: try! recoveredSigner.dematerialize().address)! - let contractAsAddress = Address(string: signedOrder.order.contractAddress)! - //gather signer address balance - GetStormBirdBalanceCoordinator(web3: Web3Swift()).getStormBirdBalance(for: recoverAddress, contract: contractAsAddress) { result in - //filter null tickets - let filteredTokens = self.checkERC875TokensAreAvailable( - indices: signedOrder.order.indices, - balance: try! result.dematerialize() - ) - if filteredTokens.isEmpty { - self.showImportError(errorMessage: R.string.localizable.aClaimTicketInvalidLinkTryAgain()) - } + switch recoveredSigner { + case .success(let ethereumAddress): + //TODO extract method for the whole .success? Quite long + //TODO return false? + guard let recoverAddress = Address(string: ethereumAddress.address) else { return false } + let contractAsAddress = Address(string: signedOrder.order.contractAddress)! + //gather signer address balance + GetStormBirdBalanceCoordinator(web3: Web3Swift()).getStormBirdBalance(for: recoverAddress, contract: contractAsAddress) { result in + //filter null tickets + let filteredTokens = self.checkERC875TokensAreAvailable( + indices: signedOrder.order.indices, + balance: try! result.dematerialize() + ) + if filteredTokens.isEmpty { + self.showImportError(errorMessage: R.string.localizable.aClaimTicketInvalidLinkTryAgain()) + } - let ticketHolder = self.sortTickets( - filteredTokens, - signedOrder.order.indices, - signedOrder.order.contractAddress - ) + let ticketHolder = self.sortTickets( + filteredTokens, + signedOrder.order.indices, + signedOrder.order.contractAddress + ) - if signedOrder.order.price > 0 || !isStormBirdContract { - if let balance = self.ethBalance { - balance.subscribeOnce { value in - if value > signedOrder.order.price { - let _ = self.handlePaidUniversalLink(signedOrder: signedOrder, ticketHolder: ticketHolder) - } else { - if let price = self.ethPrice { - if price.value == nil { - let ethCost = self.convert(ethCost: signedOrder.order.price) - self.showImportError( - errorMessage: R.string.localizable.aClaimTicketFailedNotEnoughEthTitle(), - ticketHolder: ticketHolder, - ethCost: ethCost.description - ) - } - price.subscribe { [weak self] value in - if let celf = self { - if let price = price.value { - let (ethCost, dollarCost) = celf.convert(ethCost: signedOrder.order.price, rate: price) - celf.showImportError(errorMessage: R.string.localizable.aClaimTicketFailedNotEnoughEthTitle(), ticketHolder: ticketHolder, ethCost: ethCost.description, dollarCost: dollarCost.description) + if signedOrder.order.price > 0 || !isStormBirdContract { + if let balance = self.ethBalance { + balance.subscribeOnce { value in + if value > signedOrder.order.price { + let _ = self.handlePaidUniversalLink(signedOrder: signedOrder, ticketHolder: ticketHolder) + } else { + if let price = self.ethPrice { + if price.value == nil { + let ethCost = self.convert(ethCost: signedOrder.order.price) + self.showImportError( + errorMessage: R.string.localizable.aClaimTicketFailedNotEnoughEthTitle(), + ticketHolder: ticketHolder, + ethCost: ethCost.description + ) + } + price.subscribe { [weak self] value in + if let celf = self { + if let price = price.value { + let (ethCost, dollarCost) = celf.convert(ethCost: signedOrder.order.price, rate: price) + celf.showImportError(errorMessage: R.string.localizable.aClaimTicketFailedNotEnoughEthTitle(), ticketHolder: ticketHolder, ethCost: ethCost.description, dollarCost: dollarCost.description) + } } } } @@ -189,15 +194,20 @@ class UniversalLinkCoordinator: Coordinator { } } } - } - else { - //free transfer - let _ = self.usePaymentServerForFreeTransferLinks( - signedOrder: signedOrder, - ticketHolder: ticketHolder - ) - } + else { + //free transfer + let _ = self.usePaymentServerForFreeTransferLinks( + signedOrder: signedOrder, + ticketHolder: ticketHolder + ) + } + } + case .failure(let error): + //TODO handle. Show error maybe? + NSLog("xxx error during ecrecover: \(error.localizedDescription)") + //TODO return true or false? + return false } return true } From 5bbb8ceedc4a35f612194e4f7781110ab20cbe80 Mon Sep 17 00:00:00 2001 From: James Sangalli Date: Thu, 28 Jun 2018 20:50:09 +1000 Subject: [PATCH 3/9] ecrecover working --- AlphaWallet/Market/Coordinators/UniversalLinkCoordinator.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AlphaWallet/Market/Coordinators/UniversalLinkCoordinator.swift b/AlphaWallet/Market/Coordinators/UniversalLinkCoordinator.swift index 63a7c6724..88aa09ffd 100644 --- a/AlphaWallet/Market/Coordinators/UniversalLinkCoordinator.swift +++ b/AlphaWallet/Market/Coordinators/UniversalLinkCoordinator.swift @@ -137,7 +137,7 @@ class UniversalLinkCoordinator: Coordinator { let vValue = signedOrder.signature.drop0x.substring(from: 128) let vInt = Int(vValue, radix: 16)! - 27 let vString = "0" + String(vInt) - let signature = "0x" + signedOrder.signature.drop0x.substring(from: 128) + vString + let signature = "0x" + signedOrder.signature.drop0x.substring(to: 128) + vString let nodeURL = Config().rpcURL let recoveredSigner = web3(provider: Web3HttpProvider(nodeURL)!).personal.ecrecover( hash: messageHash, From d5a9811af105ea3493443da1c77fe1e343422c78 Mon Sep 17 00:00:00 2001 From: Hwee-Boon Yar Date: Thu, 28 Jun 2018 23:41:13 +0800 Subject: [PATCH 4/9] Fix: ecrecover stuck --- .../Market/Coordinators/UniversalLinkCoordinator.swift | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/AlphaWallet/Market/Coordinators/UniversalLinkCoordinator.swift b/AlphaWallet/Market/Coordinators/UniversalLinkCoordinator.swift index aec350fb6..f3826449e 100644 --- a/AlphaWallet/Market/Coordinators/UniversalLinkCoordinator.swift +++ b/AlphaWallet/Market/Coordinators/UniversalLinkCoordinator.swift @@ -150,7 +150,9 @@ class UniversalLinkCoordinator: Coordinator { guard let recoverAddress = Address(string: ethereumAddress.address) else { return false } let contractAsAddress = Address(string: signedOrder.order.contractAddress)! //gather signer address balance - GetStormBirdBalanceCoordinator(web3: Web3Swift()).getStormBirdBalance(for: recoverAddress, contract: contractAsAddress) { result in + let web3Swift = Web3Swift() + web3Swift.start() + GetStormBirdBalanceCoordinator(web3: web3Swift).getStormBirdBalance(for: recoverAddress, contract: contractAsAddress) { result in //filter null tickets let filteredTokens = self.checkERC875TokensAreAvailable( indices: signedOrder.order.indices, @@ -221,7 +223,7 @@ class UniversalLinkCoordinator: Coordinator { if balance.count < indices.count { return [String]() } - for i in 0.. Date: Sat, 30 Jun 2018 16:37:33 +0800 Subject: [PATCH 5/9] Suggested (but commented out) fix for balance coordinator not working while ecrecover --- .../Coordinators/UniversalLinkCoordinator.swift | 9 ++++++++- .../GetStormBirdBalanceCoordinator.swift | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/AlphaWallet/Market/Coordinators/UniversalLinkCoordinator.swift b/AlphaWallet/Market/Coordinators/UniversalLinkCoordinator.swift index b24b04e62..842dcbea7 100644 --- a/AlphaWallet/Market/Coordinators/UniversalLinkCoordinator.swift +++ b/AlphaWallet/Market/Coordinators/UniversalLinkCoordinator.swift @@ -22,6 +22,7 @@ class UniversalLinkCoordinator: Coordinator { var ethBalance: Subscribable? var hasCompleted = false var addressOfNewWallet: String? + private var getStormbirdBalanceCoordinator: GetStormBirdBalanceCoordinator? init(config: Config) { self.config = config @@ -157,7 +158,13 @@ class UniversalLinkCoordinator: Coordinator { //gather signer address balance let web3Swift = Web3Swift() web3Swift.start() - GetStormBirdBalanceCoordinator(web3: web3Swift).getStormBirdBalance(for: recoverAddress, contract: contractAsAddress) { result in + //TODO Need to store strong reference like this: +// getStormbirdBalanceCoordinator = GetStormBirdBalanceCoordinator(web3: web3Swift) +// getStormbirdBalanceCoordinator?.tag = "foo" +// getStormbirdBalanceCoordinator?.getStormBirdBalance(for: recoverAddress, contract: contractAsAddress) { result in + let coordinator = GetStormBirdBalanceCoordinator(web3: web3Swift) + coordinator.tag = "foo" + coordinator.getStormBirdBalance(for: recoverAddress, contract: contractAsAddress) { result in //filter null tickets let filteredTokens = self.checkERC875TokensAreAvailable( indices: signedOrder.order.indices, diff --git a/AlphaWallet/Tokens/Coordinators/GetStormBirdBalanceCoordinator.swift b/AlphaWallet/Tokens/Coordinators/GetStormBirdBalanceCoordinator.swift index 866193c31..1b7f504b3 100644 --- a/AlphaWallet/Tokens/Coordinators/GetStormBirdBalanceCoordinator.swift +++ b/AlphaWallet/Tokens/Coordinators/GetStormBirdBalanceCoordinator.swift @@ -11,6 +11,14 @@ import JavaScriptKit class GetStormBirdBalanceCoordinator { private let web3: Web3Swift + //TODO remove + var tag = "" + //TODO remove + deinit { + if tag == "foo" { + NSLog("xxx deinit balance coordinator") + } + } init( web3: Web3Swift @@ -24,12 +32,19 @@ class GetStormBirdBalanceCoordinator { completion: @escaping (Result<[String], AnyError>) -> Void ) { let request = GetStormBirdBalanceEncode(address: address) + //TODO remove + let tag2 = tag web3.request(request: request) { result in switch result { case .success(let res): let request2 = EtherServiceRequest( batch: BatchFactory().create(CallRequest(to: contract.description, data: res)) ) + //TODO remove + if tag2 == "foo" { + NSLog("xxx back in balance coordinator") + } + //TODO immediately after this next Session.send() call, this instance of GetStormBirdBalanceEncode will be destroyed if we don't store a strong reference to it because the block passed on Session.send() does not hold a strong reference to self (because of the weak self) Session.send(request2) { [weak self] result2 in switch result2 { case .success(let balance): From 93538a79548f96f4782895707b25556b02b85bc0 Mon Sep 17 00:00:00 2001 From: James Sangalli Date: Sun, 1 Jul 2018 18:42:18 +1000 Subject: [PATCH 6/9] handle coordinator with strong reference --- .../UniversalLinkCoordinator.swift | 68 +++++++++---------- .../GetStormBirdBalanceCoordinator.swift | 16 ----- 2 files changed, 33 insertions(+), 51 deletions(-) diff --git a/AlphaWallet/Market/Coordinators/UniversalLinkCoordinator.swift b/AlphaWallet/Market/Coordinators/UniversalLinkCoordinator.swift index 842dcbea7..e0972d95c 100644 --- a/AlphaWallet/Market/Coordinators/UniversalLinkCoordinator.swift +++ b/AlphaWallet/Market/Coordinators/UniversalLinkCoordinator.swift @@ -158,13 +158,8 @@ class UniversalLinkCoordinator: Coordinator { //gather signer address balance let web3Swift = Web3Swift() web3Swift.start() - //TODO Need to store strong reference like this: -// getStormbirdBalanceCoordinator = GetStormBirdBalanceCoordinator(web3: web3Swift) -// getStormbirdBalanceCoordinator?.tag = "foo" -// getStormbirdBalanceCoordinator?.getStormBirdBalance(for: recoverAddress, contract: contractAsAddress) { result in - let coordinator = GetStormBirdBalanceCoordinator(web3: web3Swift) - coordinator.tag = "foo" - coordinator.getStormBirdBalance(for: recoverAddress, contract: contractAsAddress) { result in + getStormbirdBalanceCoordinator = GetStormBirdBalanceCoordinator(web3: web3Swift) + getStormbirdBalanceCoordinator?.getStormBirdBalance(for: recoverAddress, contract: contractAsAddress) { result in //filter null tickets let filteredTokens = self.checkERC875TokensAreAvailable( indices: signedOrder.order.indices, @@ -181,34 +176,8 @@ class UniversalLinkCoordinator: Coordinator { ) if signedOrder.order.price > 0 || !isStormBirdContract { - if let balance = self.ethBalance { - balance.subscribeOnce { value in - if value > signedOrder.order.price { - let _ = self.handlePaidUniversalLink(signedOrder: signedOrder, ticketHolder: ticketHolder) - } else { - if let price = self.ethPrice { - if price.value == nil { - let ethCost = self.convert(ethCost: signedOrder.order.price) - self.showImportError( - errorMessage: R.string.localizable.aClaimTicketFailedNotEnoughEthTitle(), - ticketHolder: ticketHolder, - ethCost: ethCost.description - ) - } - price.subscribe { [weak self] value in - if let celf = self { - if let price = price.value { - let (ethCost, dollarCost) = celf.convert(ethCost: signedOrder.order.price, rate: price) - celf.showImportError(errorMessage: R.string.localizable.aClaimTicketFailedNotEnoughEthTitle(), ticketHolder: ticketHolder, ethCost: ethCost.description, dollarCost: dollarCost.description) - } - } - } - } - } - } - } - } - else { + self.handlePaidImports(signedOrder: signedOrder, ticketHolder: ticketHolder) + } else { //free transfer let _ = self.usePaymentServerForFreeTransferLinks( signedOrder: signedOrder, @@ -225,6 +194,35 @@ class UniversalLinkCoordinator: Coordinator { } return true } + + private func handlePaidImports(signedOrder: SignedOrder, ticketHolder: TicketHolder) { + if let balance = self.ethBalance { + balance.subscribeOnce { value in + if value > signedOrder.order.price { + let _ = self.handlePaidUniversalLink(signedOrder: signedOrder, ticketHolder: ticketHolder) + } else { + if let price = self.ethPrice { + if price.value == nil { + let ethCost = self.convert(ethCost: signedOrder.order.price) + self.showImportError( + errorMessage: R.string.localizable.aClaimTicketFailedNotEnoughEthTitle(), + ticketHolder: ticketHolder, + ethCost: ethCost.description + ) + } + price.subscribe { [weak self] value in + if let celf = self { + if let price = price.value { + let (ethCost, dollarCost) = celf.convert(ethCost: signedOrder.order.price, rate: price) + celf.showImportError(errorMessage: R.string.localizable.aClaimTicketFailedNotEnoughEthTitle(), ticketHolder: ticketHolder, ethCost: ethCost.description, dollarCost: dollarCost.description) + } + } + } + } + } + } + } + } private func stringEncodeIndices(_ indices: [UInt16]) -> String { return indices.map(String.init).joined(separator: ",") diff --git a/AlphaWallet/Tokens/Coordinators/GetStormBirdBalanceCoordinator.swift b/AlphaWallet/Tokens/Coordinators/GetStormBirdBalanceCoordinator.swift index 1b7f504b3..5470eedb6 100644 --- a/AlphaWallet/Tokens/Coordinators/GetStormBirdBalanceCoordinator.swift +++ b/AlphaWallet/Tokens/Coordinators/GetStormBirdBalanceCoordinator.swift @@ -11,15 +11,6 @@ import JavaScriptKit class GetStormBirdBalanceCoordinator { private let web3: Web3Swift - //TODO remove - var tag = "" - //TODO remove - deinit { - if tag == "foo" { - NSLog("xxx deinit balance coordinator") - } - } - init( web3: Web3Swift ) { @@ -32,19 +23,12 @@ class GetStormBirdBalanceCoordinator { completion: @escaping (Result<[String], AnyError>) -> Void ) { let request = GetStormBirdBalanceEncode(address: address) - //TODO remove - let tag2 = tag web3.request(request: request) { result in switch result { case .success(let res): let request2 = EtherServiceRequest( batch: BatchFactory().create(CallRequest(to: contract.description, data: res)) ) - //TODO remove - if tag2 == "foo" { - NSLog("xxx back in balance coordinator") - } - //TODO immediately after this next Session.send() call, this instance of GetStormBirdBalanceEncode will be destroyed if we don't store a strong reference to it because the block passed on Session.send() does not hold a strong reference to self (because of the weak self) Session.send(request2) { [weak self] result2 in switch result2 { case .success(let balance): From d07677c0210932db40128db56d4006002f17bd2d Mon Sep 17 00:00:00 2001 From: James Sangalli Date: Sun, 1 Jul 2018 19:01:33 +1000 Subject: [PATCH 7/9] handle required init in TransferTicketsQuantitySelectionVIewControllerTests --- .../TransferTicketsQuantitySelectionViewController.swift | 6 ++++-- ...ransferTicketsQuantitySelectionViewControllerTests.swift | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/AlphaWallet/Transfer/ViewControllers/TransferTicketsQuantitySelectionViewController.swift b/AlphaWallet/Transfer/ViewControllers/TransferTicketsQuantitySelectionViewController.swift index 1a1b2f08e..e17213862 100644 --- a/AlphaWallet/Transfer/ViewControllers/TransferTicketsQuantitySelectionViewController.swift +++ b/AlphaWallet/Transfer/ViewControllers/TransferTicketsQuantitySelectionViewController.swift @@ -89,9 +89,11 @@ class TransferTicketsQuantitySelectionViewController: UIViewController, Verifiab footerBar.bottomAnchor.constraint(equalTo: view.bottomAnchor), ] + roundedBackground.createConstraintsWithContainer(view: view)) } - + required init?(coder aDecoder: NSCoder) { - fatalError("init(coder:) has not been implemented") + self.config = Config() + self.paymentFlow = PaymentFlow.request + super.init(coder: aDecoder) } @objc diff --git a/AlphaWalletTests/Transfer/ViewControllers/TransferTicketsQuantitySelectionViewControllerTests.swift b/AlphaWalletTests/Transfer/ViewControllers/TransferTicketsQuantitySelectionViewControllerTests.swift index c1e06f2b2..754ebe421 100644 --- a/AlphaWalletTests/Transfer/ViewControllers/TransferTicketsQuantitySelectionViewControllerTests.swift +++ b/AlphaWalletTests/Transfer/ViewControllers/TransferTicketsQuantitySelectionViewControllerTests.swift @@ -16,7 +16,7 @@ class TransferTicketsQuantitySelectionViewControllerTests: FBSnapshotTestCase { let type = PaymentFlow.send(type: .stormBird(token)) let ticket = Ticket(id: "1", index: 1, city: "", name: "", venue: "", match: 9, date: GeneralisedTime(string: "20010203160500+0300")!, seatId: 1, category: "MATCH CLUB", countryA: "Team A", countryB: "Team B") let ticketHolder = TicketHolder(tickets: [ticket], status: .available, contractAddress: "0x1") - let controller = TransferTicketsQuantitySelectionViewController(paymentFlow: type) + let controller = TransferTicketsQuantitySelectionViewController(config: Config(), paymentFlow: type) let viewModel = TransferTicketsQuantitySelectionViewModel(token: TokenObject(), ticketHolder: ticketHolder) controller.configure(viewModel: viewModel) From ced9bd1f7757f982cfee52db9ec5f0ec1a921221 Mon Sep 17 00:00:00 2001 From: Hwee-Boon Yar Date: Sun, 1 Jul 2018 17:30:22 +0800 Subject: [PATCH 8/9] Fix broken TransferTicketsQuantitySelectionViewControllerTests build error --- .../TransferTicketsQuantitySelectionViewController.swift | 5 ++--- ...TransferTicketsQuantitySelectionViewControllerTests.swift | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/AlphaWallet/Transfer/ViewControllers/TransferTicketsQuantitySelectionViewController.swift b/AlphaWallet/Transfer/ViewControllers/TransferTicketsQuantitySelectionViewController.swift index e17213862..bb79ddc5b 100644 --- a/AlphaWallet/Transfer/ViewControllers/TransferTicketsQuantitySelectionViewController.swift +++ b/AlphaWallet/Transfer/ViewControllers/TransferTicketsQuantitySelectionViewController.swift @@ -21,7 +21,7 @@ class TransferTicketsQuantitySelectionViewController: UIViewController, Verifiab var paymentFlow: PaymentFlow weak var delegate: TransferTicketsQuantitySelectionViewControllerDelegate? - init(config: Config, paymentFlow: PaymentFlow) { + init(config: Config = Config(), paymentFlow: PaymentFlow) { self.config = config self.paymentFlow = paymentFlow super.init(nibName: nil, bundle: nil) @@ -91,8 +91,7 @@ class TransferTicketsQuantitySelectionViewController: UIViewController, Verifiab } required init?(coder aDecoder: NSCoder) { - self.config = Config() - self.paymentFlow = PaymentFlow.request + fatalError("init(coder:) has not been implemented") super.init(coder: aDecoder) } diff --git a/AlphaWalletTests/Transfer/ViewControllers/TransferTicketsQuantitySelectionViewControllerTests.swift b/AlphaWalletTests/Transfer/ViewControllers/TransferTicketsQuantitySelectionViewControllerTests.swift index 754ebe421..c1e06f2b2 100644 --- a/AlphaWalletTests/Transfer/ViewControllers/TransferTicketsQuantitySelectionViewControllerTests.swift +++ b/AlphaWalletTests/Transfer/ViewControllers/TransferTicketsQuantitySelectionViewControllerTests.swift @@ -16,7 +16,7 @@ class TransferTicketsQuantitySelectionViewControllerTests: FBSnapshotTestCase { let type = PaymentFlow.send(type: .stormBird(token)) let ticket = Ticket(id: "1", index: 1, city: "", name: "", venue: "", match: 9, date: GeneralisedTime(string: "20010203160500+0300")!, seatId: 1, category: "MATCH CLUB", countryA: "Team A", countryB: "Team B") let ticketHolder = TicketHolder(tickets: [ticket], status: .available, contractAddress: "0x1") - let controller = TransferTicketsQuantitySelectionViewController(config: Config(), paymentFlow: type) + let controller = TransferTicketsQuantitySelectionViewController(paymentFlow: type) let viewModel = TransferTicketsQuantitySelectionViewModel(token: TokenObject(), ticketHolder: ticketHolder) controller.configure(viewModel: viewModel) From 697f0f946e18ce2953138320252cb03855cd8808 Mon Sep 17 00:00:00 2001 From: James Sangalli Date: Sun, 1 Jul 2018 23:34:49 +1000 Subject: [PATCH 9/9] filter null tickets properly and fix loop on tickets --- AlphaWallet/Info.plist | 2 +- .../Market/Coordinators/UniversalLinkCoordinator.swift | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/AlphaWallet/Info.plist b/AlphaWallet/Info.plist index fe7966585..c5b128b24 100644 --- a/AlphaWallet/Info.plist +++ b/AlphaWallet/Info.plist @@ -28,7 +28,7 @@ CFBundleVersion - 206 + 208 ITSAppUsesNonExemptEncryption LSApplicationQueriesSchemes diff --git a/AlphaWallet/Market/Coordinators/UniversalLinkCoordinator.swift b/AlphaWallet/Market/Coordinators/UniversalLinkCoordinator.swift index e0972d95c..1423ac9bb 100644 --- a/AlphaWallet/Market/Coordinators/UniversalLinkCoordinator.swift +++ b/AlphaWallet/Market/Coordinators/UniversalLinkCoordinator.swift @@ -236,11 +236,9 @@ class UniversalLinkCoordinator: Coordinator { for i in 0.. TicketHolder { var tickets = [Ticket]() let xmlHandler = XMLHandler() - for i in 0...bytes32Tickets.count - 1 { + for i in 0..