diff --git a/Podfile b/Podfile index 91921452c..e18491373 100644 --- a/Podfile +++ b/Podfile @@ -24,6 +24,7 @@ target 'AlphaWallet' do pod 'CryptoSwift', :git=>'https://github.com/krzyzanowskim/CryptoSwift', :branch=>'master' pod 'Fabric' pod 'Crashlytics' + pod 'SwiftyXMLParser', :git => 'https://github.com/yahoojapan/SwiftyXMLParser.git' pod 'Kingfisher', '~> 4.0' pod 'TrustKeystore', :git=>'https://github.com/alpha-wallet/trust-keystore-snapshot', :branch=>'master' pod 'Branch' diff --git a/Podfile.lock b/Podfile.lock index bbc5d990f..6a4a1854b 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -43,6 +43,7 @@ PODS: - StatefulViewController (3.0) - SwiftLint (0.24.1) - SwiftyJSON (4.0.0) + - SwiftyXMLParser (4.1.0) - TrezorCrypto (0.0.4) - TrustKeystore (0.2.0): - BigInt @@ -74,6 +75,7 @@ DEPENDENCIES: - StatefulViewController - SwiftLint - SwiftyJSON + - SwiftyXMLParser (from `https://github.com/yahoojapan/SwiftyXMLParser.git`) - TrustKeystore (from `https://github.com/alpha-wallet/trust-keystore-snapshot`, branch `master`) EXTERNAL SOURCES: @@ -85,6 +87,8 @@ EXTERNAL SOURCES: QRCodeReaderViewController: :branch: master :git: https://github.com/yannickl/QRCodeReaderViewController.git + SwiftyXMLParser: + :git: https://github.com/yahoojapan/SwiftyXMLParser.git TrustKeystore: :branch: master :git: https://github.com/alpha-wallet/trust-keystore-snapshot @@ -99,6 +103,9 @@ CHECKOUT OPTIONS: QRCodeReaderViewController: :commit: 80bd79cbeede842949b229f81bc6328f53701c5a :git: https://github.com/yannickl/QRCodeReaderViewController.git + SwiftyXMLParser: + :commit: 1ddcad0a09efb85f2325d994c2169cd9ba116ae3 + :git: https://github.com/yahoojapan/SwiftyXMLParser.git TrustKeystore: :commit: 71cf8592d88c770081bd4e24ad1bbdd06bb63303 :git: https://github.com/alpha-wallet/trust-keystore-snapshot @@ -133,9 +140,10 @@ SPEC CHECKSUMS: StatefulViewController: 4803bf900d44de26074344998e10e041113b5931 SwiftLint: 2e4b89feed5909c42c3735bbd6745f4345c4b772 SwiftyJSON: 070dabdcb1beb81b247c65ffa3a79dbbfb3b48aa + SwiftyXMLParser: b5a79fb8a730903703d0a92d30752a0b05158967 TrezorCrypto: 7f87a2296cf13872b21565c29fd9f7882dd00803 TrustKeystore: 381590c561f58fe0948abbd9cb626cbc08d75ff8 -PODFILE CHECKSUM: 53f98ad2d779a0137c05fe727a9e97f20552dae3 +PODFILE CHECKSUM: caca540a69e277efe6ea84cc65721152f15ab2cd COCOAPODS: 1.3.1 diff --git a/Trust.xcodeproj/project.pbxproj b/Trust.xcodeproj/project.pbxproj index 45a6985c5..d3fc79288 100644 --- a/Trust.xcodeproj/project.pbxproj +++ b/Trust.xcodeproj/project.pbxproj @@ -441,6 +441,9 @@ AA893ED5203C3E5400CDCED1 /* TokenBalance.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA893ED4203C3E5400CDCED1 /* TokenBalance.swift */; }; AAEB8DA2204BC7B700CB0B2C /* RedeemTicketsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAEB8DA1204BC7B700CB0B2C /* RedeemTicketsViewController.swift */; }; AAEF2CAB2050A68A0038BE0D /* SignatureHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAEF2CAA2050A68A0038BE0D /* SignatureHelper.swift */; }; + B1DB1A95207DBF6D00CA2B77 /* XMLHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = B1DB1A94207DBF6D00CA2B77 /* XMLHandler.swift */; }; + B1DB1A97207DCECF00CA2B77 /* AssetDefinitionXML.swift in Sources */ = {isa = PBXBuildFile; fileRef = B1DB1A96207DCECF00CA2B77 /* AssetDefinitionXML.swift */; }; + B1DB1A99207DDF9600CA2B77 /* XMLHandlerTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = B1DB1A98207DDF9600CA2B77 /* XMLHandlerTest.swift */; }; B1DC375D203AEAE200C9756D /* MarketQueueHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = B1DC375C203AEAE100C9756D /* MarketQueueHandler.swift */; }; B1DC375F203AEB4800C9756D /* MarketQueueHandlerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B1DC375E203AEB4800C9756D /* MarketQueueHandlerTests.swift */; }; BB5D6A9E20232EE8000FC5AB /* CurrencyRate+Fee.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB5D6A9D20232EE8000FC5AB /* CurrencyRate+Fee.swift */; }; @@ -949,6 +952,9 @@ AAEB8DA1204BC7B700CB0B2C /* RedeemTicketsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RedeemTicketsViewController.swift; sourceTree = ""; }; AAEF2CAA2050A68A0038BE0D /* SignatureHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignatureHelper.swift; sourceTree = ""; }; B13A87D3BA5167741E5D0801 /* Pods-Trust.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Trust.release.xcconfig"; path = "Pods/Target Support Files/Pods-Trust/Pods-Trust.release.xcconfig"; sourceTree = ""; }; + B1DB1A94207DBF6D00CA2B77 /* XMLHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XMLHandler.swift; sourceTree = ""; }; + B1DB1A96207DCECF00CA2B77 /* AssetDefinitionXML.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AssetDefinitionXML.swift; sourceTree = ""; }; + B1DB1A98207DDF9600CA2B77 /* XMLHandlerTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XMLHandlerTest.swift; sourceTree = ""; }; B1DC375C203AEAE100C9756D /* MarketQueueHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarketQueueHandler.swift; sourceTree = ""; }; B1DC375E203AEB4800C9756D /* MarketQueueHandlerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarketQueueHandlerTests.swift; sourceTree = ""; }; B2CF9CDF557F98DECE6D0AF6 /* Pods_AlphaWalletUITests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_AlphaWalletUITests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -1699,6 +1705,7 @@ 61FC5ED01FCFBDEB00CCB12A /* EtherNumberFormatterTests.swift */, 73D2683A202E8411009777A1 /* DecimalNumberFormatterTest.swift */, 73ED85A82034C42D00593BF3 /* StringFormatterTest.swift */, + B1DB1A98207DDF9600CA2B77 /* XMLHandlerTest.swift */, ); path = Foundation; sourceTree = ""; @@ -1838,6 +1845,8 @@ 298542F81FBE9A0100CB5081 /* CryptoAddressValidator.swift */, 61FC5ECE1FCFBAE500CCB12A /* EtherNumberFormatter.swift */, 73ED85A420349BE400593BF3 /* StringFormatter.swift */, + B1DB1A94207DBF6D00CA2B77 /* XMLHandler.swift */, + B1DB1A96207DCECF00CA2B77 /* AssetDefinitionXML.swift */, ); path = Foundation; sourceTree = ""; @@ -3068,6 +3077,7 @@ "${BUILT_PRODUCTS_DIR}/SipHash/SipHash.framework", "${BUILT_PRODUCTS_DIR}/StatefulViewController/StatefulViewController.framework", "${BUILT_PRODUCTS_DIR}/SwiftyJSON/SwiftyJSON.framework", + "${BUILT_PRODUCTS_DIR}/SwiftyXMLParser/SwiftyXMLParser.framework", "${BUILT_PRODUCTS_DIR}/TrezorCrypto/TrezorCrypto.framework", "${BUILT_PRODUCTS_DIR}/TrustKeystore/TrustKeystore.framework", "${BUILT_PRODUCTS_DIR}/secp256k1_ios/secp256k1_ios.framework", @@ -3097,6 +3107,7 @@ "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SipHash.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/StatefulViewController.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SwiftyJSON.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SwiftyXMLParser.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/TrezorCrypto.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/TrustKeystore.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/secp256k1_ios.framework", @@ -3156,6 +3167,7 @@ 77872D232023F43B0032D687 /* TransactionsTracker.swift in Sources */, 29FA00CE201CA64E002F7DC5 /* DappCommand.swift in Sources */, 29FF12F61F74799D00AFD326 /* NSAttributedString.swift in Sources */, + B1DB1A97207DCECF00CA2B77 /* AssetDefinitionXML.swift in Sources */, AA26C62320412A4100318B9B /* UIViewInspectableEnhancements.swift in Sources */, 290B2B651F91A4880053C83E /* TransactionsFooterView.swift in Sources */, 293B8B431F70815900356286 /* BalanceTitleView.swift in Sources */, @@ -3383,6 +3395,7 @@ 29F1C83E1FEB5C91003780D8 /* EditTokensViewController.swift in Sources */, 296AF9A31F733AB30058AF78 /* WalletCoordinator.swift in Sources */, 442FCBBFCC5926B4D416E6D3 /* GetNameCoordinator.swift in Sources */, + B1DB1A95207DBF6D00CA2B77 /* XMLHandler.swift in Sources */, 442FCB9850FC6F2D28978199 /* GetERC20Symbol.swift in Sources */, 442FC5F70AF003F331F7C841 /* GetSymbolCoordinator.swift in Sources */, 442FCB2B0DD39EB2D9233A2F /* GetStormBirdBalance.swift in Sources */, @@ -3556,6 +3569,7 @@ 29BDF19D1FEE50E90023A45F /* GasPriceConfigurationTests.swift in Sources */, 295996141FAB09A200DB66A8 /* DepositCoordinatorTests.swift in Sources */, 778EAF7D1FF10AF400C8E2AB /* SettingsCoordinatorTests.swift in Sources */, + B1DB1A99207DDF9600CA2B77 /* XMLHandlerTest.swift in Sources */, 732E0F502022716700B39C1F /* LockEnterPasscodeCoordinatorTest.swift in Sources */, 29F114E91FA3EC9E00114A29 /* InCoordinatorTests.swift in Sources */, 2981F4731F8303E600CA6590 /* TransactionCoordinatorTests.swift in Sources */, diff --git a/Trust/Foundation/AssetDefinitionXML.swift b/Trust/Foundation/AssetDefinitionXML.swift new file mode 100644 index 000000000..132c90557 --- /dev/null +++ b/Trust/Foundation/AssetDefinitionXML.swift @@ -0,0 +1,15 @@ +// +// AssetDefinitionXML.swift +// AlphaWallet +// +// Created by James Sangalli on 11/4/18. +// + +import Foundation + +class AssetDefinitionXML { + + // swiftlint:disable:next line_length + public static let assetDefinition = "
0xa3347C8ED134444C25169872c90a6360D42b3691
https://482kdh4npg.execute-api.ap-southeast-1.amazonaws.com/dev/ https://app.awallet.io/ город City 城市 Ciudad Москва́ Moscow 莫斯科 Moscú Санкт-Петербу́рг Saint Petersburg 圣彼得堡 San Petersburgo сочи Sochi 索契 Sochi екатеринбург Ekaterinburg 叶卡捷琳堡 Ekaterinburg Саранск Saransk 萨兰斯克 Saransk казань Kazan 喀山 Kazan Нижний Новгород Nizhny Novgorod 下诺夫哥罗德 Nizhny Novgorod Ростов-на-Дону Rostov-on-Don 顿河畔罗斯托夫 Rostov-on-Don Самара Samara 翅果 Samara Волгоград Volgograd 伏尔加格勒 Volgogrado Калининград Kaliningrad 加里宁格勒 Kaliningrad место встречи Venue 场馆 Lugar Стадион Калининград Kaliningrad Stadium 加里寧格勒體育場 Estadio de Kaliningrado Екатеринбург Арена Volgograd Arena 伏爾加格勒體育場 Volgogrado Arena Казань Арена Ekaterinburg Arena 加里宁格勒体育场 Ekaterimburgo Arena Мордовия Арена Fisht Stadium 菲什特奧林匹克體育場 Estadio Fisht Ростов Арена Kazan Arena 喀山體育場 Kazan Arena Самара Арена Nizhny Novgorod Stadium 下諾夫哥羅德體育場 Estadio de Nizhni Novgorod Стадион Калининград Luzhniki Stadium 卢日尼基体育场 Estadio Luzhniki Стадион Лужники Samara Arena 薩馬拉體育場 Samara Arena Стадион Нижний Новгород Rostov Arena 羅斯托夫體育場 Rostov Arena Стадион Спартак Spartak Stadium 斯巴達克體育場 Estadio del Spartak Стадион Санкт-Петербург Saint Petersburg Stadium 十字架體育場 Estadio de San Petersburgo Стадион Фишт Mordovia Arena 莫爾多維亞體育場 Mordovia Arena время Time 时间 Tiempo Team A 甲队 Equipo A Team B 乙队 Equipo B Match 场次 Evento Cat 等级 Cat Number 票号 Número
" + +} diff --git a/Trust/Foundation/XMLHandler.swift b/Trust/Foundation/XMLHandler.swift new file mode 100644 index 000000000..0bcdc0d32 --- /dev/null +++ b/Trust/Foundation/XMLHandler.swift @@ -0,0 +1,66 @@ +// +// XMLHandler.swift +// AlphaWallet +// +// Created by James Sangalli on 11/4/18. +// + +import Foundation +import SwiftyXMLParser + +struct FIFAInfo { + let locale: String + let venue: String + let time: Int + let countryA: String + let countryB: String + let match: Int + let category: Int + let number: Int +} + +/** + langs: + 0 = ru + 1 = en + 2 = zh + 3 = es + */ + +public class XMLHandler { + + private let xml = try! XML.parse(AssetDefinitionXML.assetDefinition) + + func getFifaInfoForToken(tokenId: String, lang: Int) -> FIFAInfo { + let locale = getLocale(attribute: tokenId.substring(to: 2), lang: lang) + let venue = getVenue(attribute: tokenId.substring(with: Range(uncheckedBounds: (2, 4))), lang: lang) + let time = Int(tokenId.substring(with: Range(uncheckedBounds: (5, 12))), radix: 16)! + //translatable to ascii + let countryA = tokenId.substring(with: Range(uncheckedBounds: (12, 18))).hexa2Bytes + let countryB = tokenId.substring(with: Range(uncheckedBounds: (18, 24))).hexa2Bytes + let match = Int(tokenId.substring(with: Range(uncheckedBounds: (24, 26))), radix: 16)! + let category = Int(tokenId.substring(with: Range(uncheckedBounds: (26, 28))), radix: 16)! + let number = Int(tokenId.substring(from: 28), radix: 16)! + return FIFAInfo( + locale: locale, + venue: venue, + time: time, + countryA: String(data: Data(bytes: countryA), encoding: .utf8)!, + countryB: String(data: Data(bytes:countryB), encoding: .utf8)!, + match: match, + category: category, + number: number + ) + } + + func getLocale(attribute: String, lang: Int) -> String { + let localeNumber = Int(attribute, radix: 16)! + return xml["asset"]["fields"]["field"][0][0]["mapping"]["entity"][localeNumber]["name"][lang].text! + } + + func getVenue(attribute: String, lang: Int) -> String { + let venueNumber = Int(attribute, radix: 16)! + return xml["asset"]["fields"]["field"][1][0]["mapping"]["entity"][venueNumber]["name"][lang].text! + } + +} diff --git a/Trust/Info.plist b/Trust/Info.plist index f80503c4e..3874e49ef 100644 --- a/Trust/Info.plist +++ b/Trust/Info.plist @@ -28,7 +28,7 @@ CFBundleVersion - 161 + 162 Fabric APIKey diff --git a/Trust/Market/UniversalLinkHandler.swift b/Trust/Market/UniversalLinkHandler.swift index d05570bbb..dc8f30ff7 100644 --- a/Trust/Market/UniversalLinkHandler.swift +++ b/Trust/Market/UniversalLinkHandler.swift @@ -32,6 +32,7 @@ public class UniversalLinkHandler { public let urlPrefix = "https://app.awallet.io/" public static let paymentServer = "http://feemaster.eastasia.cloudapp.azure.com:8080/api/claimToken" + //message is with 32 bytes each of price and expiry and is shortened for link func createUniversalLink(signedOrder: SignedOrder) -> String { let message = formatMessageForLink(signedOrder: signedOrder) diff --git a/TrustTests/Foundation/XMLHandlerTest.swift b/TrustTests/Foundation/XMLHandlerTest.swift new file mode 100644 index 000000000..e72bbb1c5 --- /dev/null +++ b/TrustTests/Foundation/XMLHandlerTest.swift @@ -0,0 +1,22 @@ +// +// XMLHandlerTest.swift +// AlphaWalletTests +// +// Created by James Sangalli on 11/4/18. +// + +import Foundation +import XCTest +@testable import Trust + +class XMLHandlerTest: XCTestCase { + + func testParser() { + let fifaDetails = XMLHandler().getFifaInfoForToken( + tokenId: "0x0a015af6d74042544e43484e01010001".substring(from: 2), + lang: 1 + ) + XCTAssertNotNil(fifaDetails) + } + +}