Skip to content

Commit 37ca5e3

Browse files
author
Dmitry Bespalov
committed
fixed issues with presenting controllers in example apps
1 parent 0685497 commit 37ca5e3

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

ClientExample/MainViewController.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ extension MainViewController: WalletConnectDelegate {
5353
onMainThread { [unowned self] in
5454
self.actionsController = ActionsViewController.create(walletConnect: self.walletConnect)
5555
if let handshakeController = self.handshakeController {
56-
handshakeController.dismiss(animated: false)
56+
handshakeController.dismiss(animated: false) { [unowned self] in
57+
self.present(self.actionsController, animated: false)
58+
}
59+
} else if self.presentedViewController == nil {
60+
self.present(self.actionsController, animated: false)
5761
}
58-
if self.presentedViewController != nil {
59-
return
60-
}
61-
self.present(self.actionsController, animated: false)
6262
}
6363
}
6464

ServerExample/MainViewController.swift

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,15 @@ class PersonalSignHandler: BaseHandler {
113113

114114
override func handle(request: Request) {
115115
do {
116-
let message = try request.parameter(of: String.self, at: 0)
116+
let messageBytes = try request.parameter(of: String.self, at: 0)
117117
let address = try request.parameter(of: String.self, at: 1)
118118

119119
guard address == wallet.address() else {
120120
sever.send(.reject(request))
121121
return
122122
}
123123

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

126126
askToSign(request: request, message: decodedMessage) {
127127
try! self.wallet.personalSign(message: decodedMessage)
@@ -213,10 +213,12 @@ extension MainViewController: ServerDelegate {
213213
peerId: UUID().uuidString,
214214
peerMeta: walletMeta)
215215
onMainThread {
216-
UIAlertController.showShouldStart(from: self, clientName: session.dAppInfo.peerMeta.name) { [unowned self] in
216+
UIAlertController.showShouldStart(from: self, clientName: session.dAppInfo.peerMeta.name, onStart: {
217217
completion(walletInfo)
218-
self.scanQRCodeButton.isEnabled = false
219-
}
218+
}, onClose: {
219+
completion(Session.WalletInfo(approved: false, accounts: [], chainId: 4, peerId: "", peerMeta: walletMeta))
220+
self.scanQRCodeButton.isEnabled = true
221+
})
220222
}
221223
}
222224

@@ -247,12 +249,14 @@ extension MainViewController: ScannerViewControllerDelegate {
247249

248250
func didScan(_ code: String) {
249251
guard let url = WCURL(code) else { return }
250-
do {
251-
try server.connect(to: url)
252-
} catch {
253-
return
252+
scanQRCodeButton.isEnabled = false
253+
scannerController?.dismiss(animated: true) { [unowned self] in
254+
do {
255+
try self.server.connect(to: url)
256+
} catch {
257+
return
258+
}
254259
}
255-
scannerController?.dismiss(animated: true)
256260
}
257261

258262
}
@@ -264,11 +268,11 @@ extension UIAlertController {
264268
return self
265269
}
266270

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

274278
static func showFailedToConnect(from controller: UIViewController) {

0 commit comments

Comments
 (0)