From 766984ca30a490dce5ede9e7f468c1d3b82f862b Mon Sep 17 00:00:00 2001 From: Hwee-Boon Yar Date: Sun, 29 Apr 2018 17:06:29 +0800 Subject: [PATCH 1/2] Fix: crash when going through transfer ticket flow --- Trust.xcodeproj/project.pbxproj | 12 ++++++++++++ ...cketsQuantitySelectionViewController.swift | 1 + ...QuantitySelectionViewControllerTests.swift | 19 +++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 TrustTests/Transfer/ViewControllers/TransferTicketsQuantitySelectionViewControllerTests.swift diff --git a/Trust.xcodeproj/project.pbxproj b/Trust.xcodeproj/project.pbxproj index 0680dfc81..5c6720fb8 100644 --- a/Trust.xcodeproj/project.pbxproj +++ b/Trust.xcodeproj/project.pbxproj @@ -371,6 +371,7 @@ 5E7C7E4B4054AAD41C5BE3EC /* SettingsAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C7564AF453BAB0BDAAA57 /* SettingsAction.swift */; }; 5E7C7E5C30EFDC70DF1E00C1 /* TicketsViewControllerHeaderViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C77316522DF2B256F1F92 /* TicketsViewControllerHeaderViewModel.swift */; }; 5E7C7EAEBB435F3909DA36FB /* TransferTicketsViaWalletAddressViewControllerViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C76D3CFA12C2236E73E10 /* TransferTicketsViaWalletAddressViewControllerViewModel.swift */; }; + 5E7C7EAED92E4AE8B99217AB /* TransferTicketsQuantitySelectionViewControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C7021EE19C4B81CAAF3C0 /* TransferTicketsQuantitySelectionViewControllerTests.swift */; }; 5E7C7EEE563D81793CB96FA0 /* TransferTicketsCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C755132D9B6F95080A1BE /* TransferTicketsCoordinator.swift */; }; 5E7C7FAF2A07E7AE21BF09AF /* AlphaWalletSettingsTextRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C71684B93F60206992E10 /* AlphaWalletSettingsTextRow.swift */; }; 5E7C7FC0770A411DB09F8C09 /* TokenViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C7C077372C3F2A4349FA1 /* TokenViewCell.swift */; }; @@ -800,6 +801,7 @@ 5E7C70088832B2D161EB4AAB /* SendViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SendViewController.swift; sourceTree = ""; }; 5E7C700CD3E43689E88FBE9B /* SetSellTicketsExpiryDateViewControllerViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SetSellTicketsExpiryDateViewControllerViewModel.swift; sourceTree = ""; }; 5E7C7011D8E5C9FFE0E59D55 /* TransferTicketsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransferTicketsViewController.swift; sourceTree = ""; }; + 5E7C7021EE19C4B81CAAF3C0 /* TransferTicketsQuantitySelectionViewControllerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransferTicketsQuantitySelectionViewControllerTests.swift; sourceTree = ""; }; 5E7C703BA1D0E9ACB7399155 /* TransferTicketsQuantitySelectionViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransferTicketsQuantitySelectionViewModel.swift; sourceTree = ""; }; 5E7C70CC85B337061151724E /* ImportWalletHelpBubbleView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImportWalletHelpBubbleView.swift; sourceTree = ""; }; 5E7C70FB40612BB02594EC00 /* ChooseTicketTransferModeViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChooseTicketTransferModeViewController.swift; sourceTree = ""; }; @@ -1820,6 +1822,7 @@ 29BDF1991FEE50B60023A45F /* Types */, 29BDF1921FEE437E0023A45F /* Controllers */, 299B5E361FCBCDE90051361C /* ViewModels */, + 5E7C7DB8A228007C94CF94AF /* ViewControllers */, ); path = Transfer; sourceTree = ""; @@ -2427,6 +2430,14 @@ path = Helpers; sourceTree = ""; }; + 5E7C7DB8A228007C94CF94AF /* ViewControllers */ = { + isa = PBXGroup; + children = ( + 5E7C7021EE19C4B81CAAF3C0 /* TransferTicketsQuantitySelectionViewControllerTests.swift */, + ); + path = ViewControllers; + sourceTree = ""; + }; 5E7C7F64537949FBD3F77457 /* Views */ = { isa = PBXGroup; children = ( @@ -3696,6 +3707,7 @@ 76F1D850F4F2E968CF8D9C86 /* MonkeyTest.swift in Sources */, 5E7C786AD8E4877C36D3B14A /* TicketAdaptorTest.swift in Sources */, 5E7C7CCA357CB7BF12E1F2B4 /* UIStackView+Array.swift in Sources */, + 5E7C7EAED92E4AE8B99217AB /* TransferTicketsQuantitySelectionViewControllerTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Trust/Transfer/ViewControllers/TransferTicketsQuantitySelectionViewController.swift b/Trust/Transfer/ViewControllers/TransferTicketsQuantitySelectionViewController.swift index 733f3892d..5736e4355 100644 --- a/Trust/Transfer/ViewControllers/TransferTicketsQuantitySelectionViewController.swift +++ b/Trust/Transfer/ViewControllers/TransferTicketsQuantitySelectionViewController.swift @@ -53,6 +53,7 @@ class TransferTicketsQuantitySelectionViewController: UIViewController { quantityStepper, ].asStackView(axis: .vertical, alignment: .center) stackView.translatesAutoresizingMaskIntoConstraints = false + roundedBackground.addSubview(stackView) let buttonsStackView = [nextButton].asStackView(distribution: .fillEqually, contentHuggingPriority: .required) buttonsStackView.translatesAutoresizingMaskIntoConstraints = false diff --git a/TrustTests/Transfer/ViewControllers/TransferTicketsQuantitySelectionViewControllerTests.swift b/TrustTests/Transfer/ViewControllers/TransferTicketsQuantitySelectionViewControllerTests.swift new file mode 100644 index 000000000..1c3c86320 --- /dev/null +++ b/TrustTests/Transfer/ViewControllers/TransferTicketsQuantitySelectionViewControllerTests.swift @@ -0,0 +1,19 @@ +// Copyright © 2018 Stormbird PTE. LTD. + +import XCTest +@testable import Trust +import UIKit + +class TransferTicketsQuantitySelectionViewControllerTests: XCTestCase { + func testTransferTicketQuantitySelectionViewControllerCanBeCreated() { + let token = TokenObject() + let type = PaymentFlow.send(type: .stormBird(token)) + let ticket = Ticket(id: "1", index: 1, city: "", name: "", venue: "", match: 1, date: Date(), seatId: 1, category: 1, countryA: "", countryB: "") + let ticketHolder = TicketHolder(tickets: [ticket], status: .available) + let controller = TransferTicketsQuantitySelectionViewController(paymentFlow: type) + let viewModel = TransferTicketsQuantitySelectionViewModel(ticketHolder: ticketHolder) + controller.configure(viewModel: viewModel) + + XCTAssertNoThrow(controller.view) + } +} From d2e2aac0660a91b4ee1ffaa8b0bd4b34097d1105 Mon Sep 17 00:00:00 2001 From: James Sangalli Date: Tue, 1 May 2018 11:21:04 +0800 Subject: [PATCH 2/2] add code to handle base64 safe encoding --- Trust/Market/UniversalLinkHandler.swift | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Trust/Market/UniversalLinkHandler.swift b/Trust/Market/UniversalLinkHandler.swift index 8e47a1088..f0230c160 100644 --- a/Trust/Market/UniversalLinkHandler.swift +++ b/Trust/Market/UniversalLinkHandler.swift @@ -39,13 +39,23 @@ public class UniversalLinkHandler { let binaryData = Data(bytes: link) let base64String = binaryData.base64EncodedString() - return urlPrefix + base64String + return urlPrefix + b64SafeEncoding(base64String) + } + + func b64SafeEncoding(_ b64String: String) -> String { + let safeEncodingB64 = b64String.replacingOccurrences(of: "+", with: "-") + return safeEncodingB64.replacingOccurrences(of: "/", with: "_") + } + + func b64SafeEncodingToRegularEncoding(_ b64SafeEncodedString: String) -> String { + let regularEncodingb64 = b64SafeEncodedString.replacingOccurrences(of: "-", with: "+") + return regularEncodingb64.replacingOccurrences(of: "_", with: "/") } //TODO add exception handling //link has shortened price and expiry and must be expanded func parseUniversalLink(url: String) -> SignedOrder { - let linkInfo = url.substring(from: urlPrefix.count) + let linkInfo = b64SafeEncodingToRegularEncoding(url.substring(from: urlPrefix.count)) let linkBytes = Data(base64Encoded: linkInfo)?.array let price = getPriceFromLinkBytes(linkBytes: linkBytes!) let expiry = getExpiryFromLinkBytes(linkBytes: linkBytes!)