Add SignMessageCoordinator

pull/2/head
Michael Scoff 7 years ago
parent ed67ab5da2
commit 7eaa8655e4
  1. 4
      Trust.xcodeproj/project.pbxproj
  2. 71
      Trust/Transfer/Coordinators/SignMessageCoordinator.swift

@ -212,6 +212,7 @@
29BDF1A11FEE51A80023A45F /* GasLimitConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29BDF1A01FEE51A80023A45F /* GasLimitConfiguration.swift */; };
29BE3FD01F7071A200F6BFC2 /* UIColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29BE3FCF1F7071A200F6BFC2 /* UIColor.swift */; };
29BE3FD21F707DC300F6BFC2 /* TransactionDataCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29BE3FD11F707DC300F6BFC2 /* TransactionDataCoordinator.swift */; };
29C0FCE1200DA94A004A13CB /* SignMessageCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29C0FCE0200DA94A004A13CB /* SignMessageCoordinator.swift */; };
29C80D331FB2CCF10037B1E0 /* GetBlockByNumberRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29C80D321FB2CCF10037B1E0 /* GetBlockByNumberRequest.swift */; };
29C80D351FB2CD110037B1E0 /* Block.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29C80D341FB2CD110037B1E0 /* Block.swift */; };
29C80D371FB2CD230037B1E0 /* ParsedTransaction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29C80D361FB2CD230037B1E0 /* ParsedTransaction.swift */; };
@ -549,6 +550,7 @@
29BDF1A01FEE51A80023A45F /* GasLimitConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GasLimitConfiguration.swift; sourceTree = "<group>"; };
29BE3FCF1F7071A200F6BFC2 /* UIColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIColor.swift; sourceTree = "<group>"; };
29BE3FD11F707DC300F6BFC2 /* TransactionDataCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransactionDataCoordinator.swift; sourceTree = "<group>"; };
29C0FCE0200DA94A004A13CB /* SignMessageCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignMessageCoordinator.swift; sourceTree = "<group>"; };
29C80D321FB2CCF10037B1E0 /* GetBlockByNumberRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GetBlockByNumberRequest.swift; sourceTree = "<group>"; };
29C80D341FB2CD110037B1E0 /* Block.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Block.swift; sourceTree = "<group>"; };
29C80D361FB2CD230037B1E0 /* ParsedTransaction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParsedTransaction.swift; sourceTree = "<group>"; };
@ -1585,6 +1587,7 @@
29B6AECA1F7C5FA900EC6DE3 /* PaymentCoordinator.swift */,
29F114F31FA8117C00114A29 /* SendCoordinator.swift */,
29F114F51FA8147300114A29 /* RequestCoordinator.swift */,
29C0FCE0200DA94A004A13CB /* SignMessageCoordinator.swift */,
);
path = Coordinators;
sourceTree = "<group>";
@ -2479,6 +2482,7 @@
613D048B1FDE162B008DE72E /* TrustProvider.swift in Sources */,
293204581F8DC6B20095B7C1 /* ExchangeRateCoordinator.swift in Sources */,
61C359E02002AA5A0097B04D /* TransactionSigning.swift in Sources */,
29C0FCE1200DA94A004A13CB /* SignMessageCoordinator.swift in Sources */,
29B933F81F8609FF009FCABB /* PaymentFlow.swift in Sources */,
2963B6BF1F9AB9A2003063C1 /* ContractERC20Transfer.swift in Sources */,
29A13E331F6B1B7A00E432A2 /* AppStyle.swift in Sources */,

@ -0,0 +1,71 @@
// Copyright SIX DAY LLC. All rights reserved.
import Foundation
import UIKit
import TrustKeystore
import CryptoSwift
protocol SignMessageCoordinatorDelegate: class {
func didSignMesage(message: String, in coordinator: SignMessageCoordinator)
func didError(error: Error, in coordinator: SignMessageCoordinator)
func didCancel(in coordinator: SignMessageCoordinator)
}
class SignMessageCoordinator: Coordinator {
var coordinators: [Coordinator] = []
let navigationController: UINavigationController
let keystore: Keystore
let account: Account
weak var delegate: SignMessageCoordinatorDelegate?
init(
navigationController: UINavigationController,
keystore: Keystore,
account: Account
) {
self.navigationController = navigationController
self.keystore = keystore
self.account = account
}
func start(with message: String) {
let alertController = makeAlertController(message: message)
navigationController.present(alertController, animated: true, completion: nil)
}
private func makeAlertController(message: String) -> UIAlertController {
let alertController = UIAlertController(
title: NSLocalizedString("", value: "Confirm signing this message:", comment: ""),
message: message,
preferredStyle: .alert
)
let signAction = UIAlertAction(
title: NSLocalizedString("OK", value: "OK", comment: ""),
style: .default
) { [weak self] _ in
guard let `self` = self else { return }
self.handleSignedMessage(message: message)
}
let cancelAction = UIAlertAction(title: NSLocalizedString("Cancel", value: "Cancel", comment: ""), style: .cancel) { [weak self] _ in
guard let `self` = self else { return }
self.delegate?.didCancel(in: self)
}
alertController.addAction(signAction)
alertController.addAction(cancelAction)
return alertController
}
private func handleSignedMessage(message: String) {
let result = self.keystore.signMessage(message: message, account: self.account)
switch result {
case .success(let data):
delegate?.didSignMesage(message: data.toHexString(), in: self)
case .failure(let error):
delegate?.didError(error: error, in: self)
}
}
}
Loading…
Cancel
Save