Skip to content

Commit

Permalink
Merge branch 'feature/ui_updates' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmcl committed Dec 14, 2023
2 parents 2403209 + d34f950 commit 9539200
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 14 deletions.
11 changes: 7 additions & 4 deletions Kukai Mobile/Controls/Toast.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,15 @@ class Toast {
private init() {
toastView = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 34))
//toastView.translatesAutoresizingMaskIntoConstraints = false
toastView.backgroundColor = .colorNamed("BG2")
toastView.borderColor = .colorNamed("BG4")
toastView.borderWidth = 1
toastView.backgroundColor = .colorNamed("BG12")
toastView.customCornerRadius = 8

toastLabel = UILabel(frame: CGRect(x: 0, y: 0, width: 100, height: 34))
toastLabel.translatesAutoresizingMaskIntoConstraints = false
toastLabel.textAlignment = .center
toastLabel.numberOfLines = 1
toastLabel.font = .custom(ofType: .bold, andSize: 12)
toastLabel.textColor = .colorNamed("Txt6")
toastLabel.textColor = .colorNamed("Txt14")

toastView.addSubview(toastLabel)
NSLayoutConstraint.activate([
Expand Down Expand Up @@ -63,6 +61,11 @@ class Toast {
toastView.setNeedsLayout()
toastView.layoutIfNeeded()

if let first = toastView.layer.sublayers?.first, first.shadowPath != nil {
first.removeFromSuperlayer()
}
toastView.addShadow(color: UIColor(red: 0, green: 0, blue: 0, alpha: 0.23), opacity: 1, offset: CGSize(width: 1, height: 2), radius: 5)

attachedTo.isUserInteractionEnabled = false
// Animate view appeareance in
UIView.animate(withDuration: 0.3) { [weak self] in
Expand Down
8 changes: 8 additions & 0 deletions Kukai Mobile/Extensions/String+extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ extension String {
return readable ?? ""
}

public func isMichelsonEncodedString() -> Bool {
if String(self.prefix(2)) == "05" || String(self.prefix(4)) == "0x05" {
return true
}

return false
}

private func processString(fromIndex: Int) -> String {
let index = self.index(self.startIndex, offsetBy: fromIndex)
let subString = String(self.suffix(from: index))
Expand Down
2 changes: 2 additions & 0 deletions Kukai Mobile/Localization/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,5 @@
"error-cant-fav"="Unable to favourite token";
"error-cant-unfav"="Unable to unfavourite token";
"error-image-not-in-cahce"="Unable to locate image in cache, please make sure the image is displayed correctly";
"error-unsupported-sign"="Unsupported signature request";
"error-wc2-unrecoverable"="An unknown error occured with the connection. This operation can't continue. Please check the other application and try agian";
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,21 @@ class WalletConnectPairViewController: UIViewController, BottomSheetCustomFixedP
}
}

private func unrecoverableError() {
self.hideLoadingModal(completion: { [weak self] in
TransactionService.shared.resetWalletConnectState()
self?.windowError(withTitle: "error".localized(), description: "error-wc2-unrecoverable".localized())
self?.presentingViewController?.dismiss(animated: true)
})
}

@IBAction func closeButtonTapped(_ sender: Any) {
rejectTapped("")
}

@IBAction func connectTapped(_ sender: Any) {
guard let proposal = TransactionService.shared.walletConnectOperationData.proposal, let account = DependencyManager.shared.selectedWalletAddress else {
unrecoverableError()
return
}

Expand Down Expand Up @@ -131,6 +140,7 @@ class WalletConnectPairViewController: UIViewController, BottomSheetCustomFixedP

@IBAction func rejectTapped(_ sender: Any) {
guard let proposal = TransactionService.shared.walletConnectOperationData.proposal else {
unrecoverableError()
return
}

Expand Down
36 changes: 26 additions & 10 deletions Kukai Mobile/Services/WalletConnectService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,29 @@ public class WalletConnectService {
processWalletConnectRequest()

} else if request.method == "tezos_sign" {
delegate?.signRequested()

// Check for valid type
if let params = try? request.params.get([String: String].self), let expression = params["payload"], expression.isMichelsonEncodedString(), expression.humanReadableStringFromMichelson() != "" {
delegate?.signRequested()
} else {
Task {
try? await WalletConnectService.reject(topic: request.topic, requestId: request.id)
TransactionService.shared.resetWalletConnectState()
}
delegateErrorOnMain(message: "error-unsupported-sign".localized(), error: nil)
}

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

} else {
delegate?.error(message: "Unsupported WC method: \(request.method)", error: nil)
delegateErrorOnMain(message: "Unsupported WC method: \(request.method)", error: nil)
}
}

private func delegateErrorOnMain(message: String, error: Error?) {
DispatchQueue.main.async { [weak self] in
self?.delegate?.error(message: message, error: error)
}
}

Expand Down Expand Up @@ -234,7 +250,7 @@ public class WalletConnectService {

} catch {
Logger.app.error("WC Pairing connect error: \(error)")
self.delegate?.error(message: "Unable to connect to: \(uri.absoluteString), due to: \(error)", error: error)
delegateErrorOnMain(message: "Unable to connect to: \(uri.absoluteString), due to: \(error)", error: error)
}
}
}
Expand All @@ -243,7 +259,7 @@ public class WalletConnectService {
public func respondWithAccounts() {
guard let request = TransactionService.shared.walletConnectOperationData.request else {
Logger.app.error("WC Approve Session error: Unable to find request")
self.delegate?.error(message: "Wallet connect: Unable to respond to request for list of wallets", error: nil)
delegateErrorOnMain(message: "Wallet connect: Unable to respond to request for list of wallets", error: nil)
return
}

Expand Down Expand Up @@ -288,7 +304,7 @@ public class WalletConnectService {

} catch {
Logger.app.error("WC Approve Session error: \(error)")
self.delegate?.error(message: "Wallet connect: error returning list of accounts: \(error)", error: error)
delegateErrorOnMain(message: "Wallet connect: error returning list of accounts: \(error)", error: error)
}
}
}
Expand Down Expand Up @@ -360,13 +376,13 @@ public class WalletConnectService {

private func processWalletConnectRequest() {
guard let wcRequest = TransactionService.shared.walletConnectOperationData.request else {
self.delegate?.error(message: "Unable to process wallet connect request", error: nil)
self.delegateErrorOnMain(message: "Unable to process wallet connect request", error: nil)
return
}

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

Expand All @@ -375,12 +391,12 @@ public class WalletConnectService {
(wcRequest.chainId.absoluteString == "tezos:\(tezosChainName)" || (wcRequest.chainId.absoluteString == "tezos:ghostnet" && tezosChainName == "ithacanet"))
else {
let onDevice = DependencyManager.shared.currentNetworkType == .mainnet ? "Mainnet" : "Ghostnet"
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)
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)
return
}

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

Expand All @@ -392,7 +408,7 @@ public class WalletConnectService {

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

Expand Down

0 comments on commit 9539200

Please sign in to comment.