Skip to content

Commit

Permalink
fixed issues with presenting controllers in example apps
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Bespalov committed Aug 29, 2019
1 parent 0685497 commit 37ca5e3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
10 changes: 5 additions & 5 deletions ClientExample/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ extension MainViewController: WalletConnectDelegate {
onMainThread { [unowned self] in
self.actionsController = ActionsViewController.create(walletConnect: self.walletConnect)
if let handshakeController = self.handshakeController {
handshakeController.dismiss(animated: false)
handshakeController.dismiss(animated: false) { [unowned self] in
self.present(self.actionsController, animated: false)
}
} else if self.presentedViewController == nil {
self.present(self.actionsController, animated: false)
}
if self.presentedViewController != nil {
return
}
self.present(self.actionsController, animated: false)
}
}

Expand Down
28 changes: 16 additions & 12 deletions ServerExample/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@ class PersonalSignHandler: BaseHandler {

override func handle(request: Request) {
do {
let message = try request.parameter(of: String.self, at: 0)
let messageBytes = try request.parameter(of: String.self, at: 0)
let address = try request.parameter(of: String.self, at: 1)

guard address == wallet.address() else {
sever.send(.reject(request))
return
}

let decodedMessage = message.hasPrefix("0x") ? (String(data: Data(hex: message), encoding: .utf8) ?? message) : message
let decodedMessage = String(data: Data(hex: messageBytes), encoding: .utf8) ?? messageBytes

askToSign(request: request, message: decodedMessage) {
try! self.wallet.personalSign(message: decodedMessage)
Expand Down Expand Up @@ -213,10 +213,12 @@ extension MainViewController: ServerDelegate {
peerId: UUID().uuidString,
peerMeta: walletMeta)
onMainThread {
UIAlertController.showShouldStart(from: self, clientName: session.dAppInfo.peerMeta.name) { [unowned self] in
UIAlertController.showShouldStart(from: self, clientName: session.dAppInfo.peerMeta.name, onStart: {
completion(walletInfo)
self.scanQRCodeButton.isEnabled = false
}
}, onClose: {
completion(Session.WalletInfo(approved: false, accounts: [], chainId: 4, peerId: "", peerMeta: walletMeta))
self.scanQRCodeButton.isEnabled = true
})
}
}

Expand Down Expand Up @@ -247,12 +249,14 @@ extension MainViewController: ScannerViewControllerDelegate {

func didScan(_ code: String) {
guard let url = WCURL(code) else { return }
do {
try server.connect(to: url)
} catch {
return
scanQRCodeButton.isEnabled = false
scannerController?.dismiss(animated: true) { [unowned self] in
do {
try self.server.connect(to: url)
} catch {
return
}
}
scannerController?.dismiss(animated: true)
}

}
Expand All @@ -264,11 +268,11 @@ extension UIAlertController {
return self
}

static func showShouldStart(from controller: UIViewController, clientName: String, onStart: @escaping () -> Void) {
static func showShouldStart(from controller: UIViewController, clientName: String, onStart: @escaping () -> Void, onClose: @escaping (() -> Void)) {
let alert = UIAlertController(title: "Request to start a session", message: clientName, preferredStyle: .alert)
let startAction = UIAlertAction(title: "Start", style: .default) { _ in onStart() }
alert.addAction(startAction)
controller.present(alert.withCloseButton(), animated: true)
controller.present(alert.withCloseButton(onClose: onClose), animated: true)
}

static func showFailedToConnect(from controller: UIViewController) {
Expand Down

0 comments on commit 37ca5e3

Please sign in to comment.