Skip to content

Commit 9539200

Browse files
committed
Merge branch 'feature/ui_updates' into develop
2 parents 2403209 + d34f950 commit 9539200

File tree

5 files changed

+53
-14
lines changed

5 files changed

+53
-14
lines changed

Kukai Mobile/Controls/Toast.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,15 @@ class Toast {
1717
private init() {
1818
toastView = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 34))
1919
//toastView.translatesAutoresizingMaskIntoConstraints = false
20-
toastView.backgroundColor = .colorNamed("BG2")
21-
toastView.borderColor = .colorNamed("BG4")
22-
toastView.borderWidth = 1
20+
toastView.backgroundColor = .colorNamed("BG12")
2321
toastView.customCornerRadius = 8
2422

2523
toastLabel = UILabel(frame: CGRect(x: 0, y: 0, width: 100, height: 34))
2624
toastLabel.translatesAutoresizingMaskIntoConstraints = false
2725
toastLabel.textAlignment = .center
2826
toastLabel.numberOfLines = 1
2927
toastLabel.font = .custom(ofType: .bold, andSize: 12)
30-
toastLabel.textColor = .colorNamed("Txt6")
28+
toastLabel.textColor = .colorNamed("Txt14")
3129

3230
toastView.addSubview(toastLabel)
3331
NSLayoutConstraint.activate([
@@ -63,6 +61,11 @@ class Toast {
6361
toastView.setNeedsLayout()
6462
toastView.layoutIfNeeded()
6563

64+
if let first = toastView.layer.sublayers?.first, first.shadowPath != nil {
65+
first.removeFromSuperlayer()
66+
}
67+
toastView.addShadow(color: UIColor(red: 0, green: 0, blue: 0, alpha: 0.23), opacity: 1, offset: CGSize(width: 1, height: 2), radius: 5)
68+
6669
attachedTo.isUserInteractionEnabled = false
6770
// Animate view appeareance in
6871
UIView.animate(withDuration: 0.3) { [weak self] in

Kukai Mobile/Extensions/String+extensions.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ extension String {
2828
return readable ?? ""
2929
}
3030

31+
public func isMichelsonEncodedString() -> Bool {
32+
if String(self.prefix(2)) == "05" || String(self.prefix(4)) == "0x05" {
33+
return true
34+
}
35+
36+
return false
37+
}
38+
3139
private func processString(fromIndex: Int) -> String {
3240
let index = self.index(self.startIndex, offsetBy: fromIndex)
3341
let subString = String(self.suffix(from: index))

Kukai Mobile/Localization/en.lproj/Localizable.strings

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,5 @@
4747
"error-cant-fav"="Unable to favourite token";
4848
"error-cant-unfav"="Unable to unfavourite token";
4949
"error-image-not-in-cahce"="Unable to locate image in cache, please make sure the image is displayed correctly";
50+
"error-unsupported-sign"="Unsupported signature request";
51+
"error-wc2-unrecoverable"="An unknown error occured with the connection. This operation can't continue. Please check the other application and try agian";

Kukai Mobile/Modules/ConnectedApps/WalletConnectPairViewController.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,21 @@ class WalletConnectPairViewController: UIViewController, BottomSheetCustomFixedP
6868
}
6969
}
7070

71+
private func unrecoverableError() {
72+
self.hideLoadingModal(completion: { [weak self] in
73+
TransactionService.shared.resetWalletConnectState()
74+
self?.windowError(withTitle: "error".localized(), description: "error-wc2-unrecoverable".localized())
75+
self?.presentingViewController?.dismiss(animated: true)
76+
})
77+
}
78+
7179
@IBAction func closeButtonTapped(_ sender: Any) {
7280
rejectTapped("")
7381
}
7482

7583
@IBAction func connectTapped(_ sender: Any) {
7684
guard let proposal = TransactionService.shared.walletConnectOperationData.proposal, let account = DependencyManager.shared.selectedWalletAddress else {
85+
unrecoverableError()
7786
return
7887
}
7988

@@ -131,6 +140,7 @@ class WalletConnectPairViewController: UIViewController, BottomSheetCustomFixedP
131140

132141
@IBAction func rejectTapped(_ sender: Any) {
133142
guard let proposal = TransactionService.shared.walletConnectOperationData.proposal else {
143+
unrecoverableError()
134144
return
135145
}
136146

Kukai Mobile/Services/WalletConnectService.swift

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,29 @@ public class WalletConnectService {
163163
processWalletConnectRequest()
164164

165165
} else if request.method == "tezos_sign" {
166-
delegate?.signRequested()
166+
167+
// Check for valid type
168+
if let params = try? request.params.get([String: String].self), let expression = params["payload"], expression.isMichelsonEncodedString(), expression.humanReadableStringFromMichelson() != "" {
169+
delegate?.signRequested()
170+
} else {
171+
Task {
172+
try? await WalletConnectService.reject(topic: request.topic, requestId: request.id)
173+
TransactionService.shared.resetWalletConnectState()
174+
}
175+
delegateErrorOnMain(message: "error-unsupported-sign".localized(), error: nil)
176+
}
167177

168178
} else if request.method == "tezos_getAccounts" {
169179
delegate?.provideAccountList()
170180

171181
} else {
172-
delegate?.error(message: "Unsupported WC method: \(request.method)", error: nil)
182+
delegateErrorOnMain(message: "Unsupported WC method: \(request.method)", error: nil)
183+
}
184+
}
185+
186+
private func delegateErrorOnMain(message: String, error: Error?) {
187+
DispatchQueue.main.async { [weak self] in
188+
self?.delegate?.error(message: message, error: error)
173189
}
174190
}
175191

@@ -234,7 +250,7 @@ public class WalletConnectService {
234250

235251
} catch {
236252
Logger.app.error("WC Pairing connect error: \(error)")
237-
self.delegate?.error(message: "Unable to connect to: \(uri.absoluteString), due to: \(error)", error: error)
253+
delegateErrorOnMain(message: "Unable to connect to: \(uri.absoluteString), due to: \(error)", error: error)
238254
}
239255
}
240256
}
@@ -243,7 +259,7 @@ public class WalletConnectService {
243259
public func respondWithAccounts() {
244260
guard let request = TransactionService.shared.walletConnectOperationData.request else {
245261
Logger.app.error("WC Approve Session error: Unable to find request")
246-
self.delegate?.error(message: "Wallet connect: Unable to respond to request for list of wallets", error: nil)
262+
delegateErrorOnMain(message: "Wallet connect: Unable to respond to request for list of wallets", error: nil)
247263
return
248264
}
249265

@@ -288,7 +304,7 @@ public class WalletConnectService {
288304

289305
} catch {
290306
Logger.app.error("WC Approve Session error: \(error)")
291-
self.delegate?.error(message: "Wallet connect: error returning list of accounts: \(error)", error: error)
307+
delegateErrorOnMain(message: "Wallet connect: error returning list of accounts: \(error)", error: error)
292308
}
293309
}
294310
}
@@ -360,13 +376,13 @@ public class WalletConnectService {
360376

361377
private func processWalletConnectRequest() {
362378
guard let wcRequest = TransactionService.shared.walletConnectOperationData.request else {
363-
self.delegate?.error(message: "Unable to process wallet connect request", error: nil)
379+
self.delegateErrorOnMain(message: "Unable to process wallet connect request", error: nil)
364380
return
365381
}
366382

367383
DependencyManager.shared.tezosNodeClient.getNetworkInformation { _, error in
368384
if let err = error {
369-
self.delegate?.error(message: "Unable to fetch info from the Tezos node, please try again", error: err)
385+
self.delegateErrorOnMain(message: "Unable to fetch info from the Tezos node, please try again", error: err)
370386
return
371387
}
372388

@@ -375,12 +391,12 @@ public class WalletConnectService {
375391
(wcRequest.chainId.absoluteString == "tezos:\(tezosChainName)" || (wcRequest.chainId.absoluteString == "tezos:ghostnet" && tezosChainName == "ithacanet"))
376392
else {
377393
let onDevice = DependencyManager.shared.currentNetworkType == .mainnet ? "Mainnet" : "Ghostnet"
378-
self.delegate?.error(message: "Request is for a different network than the one currently selected on device (\"\(onDevice)\"). Please check the dApp and apps settings to match sure they match", error: nil)
394+
self.delegateErrorOnMain(message: "Request is for a different network than the one currently selected on device (\"\(onDevice)\"). Please check the dApp and apps settings to match sure they match", error: nil)
379395
return
380396
}
381397

382398
guard let params = try? wcRequest.params.get(WalletConnectRequestParams.self), let wallet = WalletCacheService().fetchWallet(forAddress: params.account) else {
383-
self.delegate?.error(message: "Unable to parse response or locate wallet", error: nil)
399+
self.delegateErrorOnMain(message: "Unable to parse response or locate wallet", error: nil)
384400
return
385401
}
386402

@@ -392,7 +408,7 @@ public class WalletConnectService {
392408

393409
DependencyManager.shared.tezosNodeClient.estimate(operations: convertedOps, walletAddress: wallet.address, base58EncodedPublicKey: wallet.publicKeyBase58encoded()) { [weak self] result in
394410
guard let estimationResult = try? result.get() else {
395-
self?.delegate?.error(message: "Unable to estimate fees", error: result.getFailure())
411+
self?.delegateErrorOnMain(message: "Unable to estimate fees", error: result.getFailure())
396412
return
397413
}
398414

0 commit comments

Comments
 (0)