Skip to content

Commit

Permalink
Implement latest changes to TrustWalletSDK
Browse files Browse the repository at this point in the history
  • Loading branch information
vikmeup committed Jun 4, 2018
1 parent c2fc955 commit 39d243b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 23 deletions.
7 changes: 4 additions & 3 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ PODS:
- TrezorCrypto
- TrustCore
- TrustWalletSDK (0.0.1):
- Result
- TrustCore
- TrustWeb3Provider (0.1.7)
- URLNavigator (2.0.4)
Expand Down Expand Up @@ -152,7 +153,7 @@ CHECKOUT OPTIONS:
:commit: 80bd79cbeede842949b229f81bc6328f53701c5a
:git: https://github.com/yannickl/QRCodeReaderViewController.git
TrustWalletSDK:
:commit: 1c5db1578caf5589dcc719c94dd7e18a941df0a6
:commit: c0a66b6fa566ab418da6a36fa78a44f067764aca
:git: https://github.com/TrustWallet/TrustSDK-iOS
TrustWeb3Provider:
:commit: f4e0ebb1b8fa4812637babe85ef975d116543dfd
Expand Down Expand Up @@ -190,10 +191,10 @@ SPEC CHECKSUMS:
TrezorCrypto: ecef681446bf02af6248d3b5e394026d7e766e56
TrustCore: 688df9a241008cf9cfa3842ec8ef28777a8b7534
TrustKeystore: fdd5936098af80b9478122bbd3a89477a5389298
TrustWalletSDK: 8f42c49399e3bba86e7fa85501b9f7fb68c5969d
TrustWalletSDK: 12451433bda69bc07e5a27408449b1f4692879e4
TrustWeb3Provider: 50fa391bdf170feb43dd4419992931510a5751d8
URLNavigator: af5582fbbb3586c958be16835d799bfdb23a4793

PODFILE CHECKSUM: b6ed29b92790ccd93215436a07191d9d287ef870

COCOAPODS: 1.5.3
COCOAPODS: 1.5.2
51 changes: 31 additions & 20 deletions Trust/Core/Coordinators/LocalSchemeCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import TrustCore
import TrustKeystore
import TrustWalletSDK
import BigInt
import Result

protocol LocalSchemeCoordinatorDelegate: class {
func didCancel(in coordinator: LocalSchemeCoordinator)
Expand All @@ -31,7 +32,7 @@ class LocalSchemeCoordinator: Coordinator {
self.session = session
}

private func signMessage(for account: Account, message: Data, completion: @escaping (Data?) -> Void) {
private func signMessage(for account: Account, signMessage: SignMesageType, completion: @escaping (Result<Data, WalletError>) -> Void) {
let coordinator = SignMessageCoordinator(
navigationController: navigationController,
keystore: keystore,
Expand All @@ -41,18 +42,18 @@ class LocalSchemeCoordinator: Coordinator {
guard let `self` = self else { return }
switch result {
case .success(let data):
completion(data)
completion(.success(data))
case .failure:
completion(nil)
completion(.failure(WalletError.cancelled))
}
self.removeCoordinator(coordinator)
}
coordinator.delegate = self
addCoordinator(coordinator)
coordinator.start(with: .message(message))
coordinator.start(with: signMessage)
}

private func signTransaction(account: Account, transaction: UnconfirmedTransaction, type: ConfirmType, completion: @escaping (Data?) -> Void) {
private func signTransaction(account: Account, transaction: UnconfirmedTransaction, type: ConfirmType, completion: @escaping (Result<Data, WalletError>) -> Void) {
let configurator = TransactionConfigurator(
session: session,
account: account,
Expand All @@ -73,19 +74,26 @@ class LocalSchemeCoordinator: Coordinator {
case .success(let type):
switch type {
case .signedTransaction(let transaction):
completion(transaction.data)
completion(.success(transaction.data))
case .sentTransaction(let transaction):
completion(transaction.data)
completion(.success(transaction.data))
}
case .failure:
completion(.none)
completion(.failure(WalletError.cancelled))
}
self.removeCoordinator(coordinator)
self.navigationController.dismiss(animated: true, completion: nil)
}
coordinator.start()
navigationController.present(coordinator.navigationController, animated: true, completion: nil)
}

private func account(for session: WalletSession) -> Account? {
switch session.account.type {
case .privateKey(let account), .hd(let account): return account
case .address: return .none
}
}
}

extension LocalSchemeCoordinator: SignMessageCoordinatorDelegate {
Expand All @@ -96,16 +104,21 @@ extension LocalSchemeCoordinator: SignMessageCoordinatorDelegate {
}

extension LocalSchemeCoordinator: WalletDelegate {
func signMessage(_ message: Data, address: Address?, completion: @escaping (Data?) -> Void) {
switch session.account.type {
case .privateKey(let account), .hd(let account):
signMessage(for: account, message: message, completion: completion)
case .address:
break
func signMessage(_ message: Data, address: Address?, completion: @escaping (Result<Data, WalletError>) -> Void) {
guard let account = account(for: session) else {
return completion(.failure(WalletError.cancelled))
}
signMessage(for: account, signMessage: .message(message), completion: completion)
}

func signTransaction(_ transaction: TrustCore.Transaction, completion: @escaping (Data?) -> Void) {
func signPersonalMessage(_ message: Data, address: Address?, completion: @escaping (Result<Data, WalletError>) -> Void) {
guard let account = account(for: session) else {
return completion(.failure(WalletError.cancelled))
}
signMessage(for: account, signMessage: .personalMessage(message), completion: completion)
}

func signTransaction(_ transaction: TrustCore.Transaction, completion: @escaping (Result<Data, WalletError>) -> Void) {
let transaction = UnconfirmedTransaction(
transferType: .ether(destination: .none),
value: transaction.amount,
Expand All @@ -116,11 +129,9 @@ extension LocalSchemeCoordinator: WalletDelegate {
nonce: BigInt(transaction.nonce)
)

switch session.account.type {
case .privateKey(let account), .hd(let account):
signTransaction(account: account, transaction: transaction, type: .sign, completion: completion)
case .address:
break
guard let account = account(for: session) else {
return completion(.failure(WalletError.cancelled))
}
signTransaction(account: account, transaction: transaction, type: .sign, completion: completion)
}
}

0 comments on commit 39d243b

Please sign in to comment.