Skip to content

Commit

Permalink
Merge pull request #3288 from safe-global/GH-2464/ipad-crashes
Browse files Browse the repository at this point in the history
GH-2464 fix crashing on presentation of an actionSheet on iPad
  • Loading branch information
DmitryBespalov committed Aug 10, 2023
2 parents 3bcc321 + c7e927c commit d005f3f
Show file tree
Hide file tree
Showing 14 changed files with 60 additions and 70 deletions.
4 changes: 4 additions & 0 deletions Multisig.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,7 @@
B0D61F54F176906A7C5A65CB /* SendTransactionRequestViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0D61BDFEADB74805D9221DB /* SendTransactionRequestViewController.swift */; };
B0D61FFF1935AA2484BD940A /* WebConnectionRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0D617C60F3081A3A923005D /* WebConnectionRepository.swift */; };
B343BEB32A77DDA1006BF46B /* DMSans-Bold.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 0491067C28F99246005A4A99 /* DMSans-Bold.ttf */; };
B3B6044F2A850F5E007BDAC0 /* UIAlertControllerStyle+Multiplatform.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3B6044E2A850F5E007BDAC0 /* UIAlertControllerStyle+Multiplatform.swift */; };
D80B5A032769CEAD00D6E024 /* Tooltip.swift in Sources */ = {isa = PBXBuildFile; fileRef = D80B5A022769CEAD00D6E024 /* Tooltip.swift */; };
D80B5A052769CF1B00D6E024 /* TooltipSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = D80B5A042769CF1B00D6E024 /* TooltipSource.swift */; };
D80B5A072769D05D00D6E024 /* BaseCustomView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D80B5A062769D05D00D6E024 /* BaseCustomView.swift */; };
Expand Down Expand Up @@ -2022,6 +2023,7 @@
B0D61DB08E699747DCEE7325 /* GnosisSafeWebPeerInfo.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GnosisSafeWebPeerInfo.swift; sourceTree = "<group>"; };
B0D61EF933B18A7181F0F6E8 /* WebConnectionOpenRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WebConnectionOpenRequest.swift; sourceTree = "<group>"; };
B0D61FB05FC8C6D45FAC1246 /* ActionPanelView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ActionPanelView.xib; sourceTree = "<group>"; };
B3B6044E2A850F5E007BDAC0 /* UIAlertControllerStyle+Multiplatform.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIAlertControllerStyle+Multiplatform.swift"; sourceTree = "<group>"; };
D80B5A022769CEAD00D6E024 /* Tooltip.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Tooltip.swift; sourceTree = "<group>"; };
D80B5A042769CF1B00D6E024 /* TooltipSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TooltipSource.swift; sourceTree = "<group>"; };
D80B5A062769D05D00D6E024 /* BaseCustomView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseCustomView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2844,6 +2846,7 @@
0A839B5F2578EB9500103AD9 /* View Controllers */,
558835ED255BFEA80014E8C7 /* Views */,
6A007E912A60179B000F0ADD /* UIGestures.swift */,
B3B6044E2A850F5E007BDAC0 /* UIAlertControllerStyle+Multiplatform.swift */,
);
path = "UI Library";
sourceTree = "<group>";
Expand Down Expand Up @@ -5672,6 +5675,7 @@
0A478D1B25B860240038363E /* KeyPickerController.swift in Sources */,
6A7D476F29B49BC500D690BE /* RelaysRemainingRequest.swift in Sources */,
0AF2737724DD48AD007E4012 /* NotificationPayload.swift in Sources */,
B3B6044F2A850F5E007BDAC0 /* UIAlertControllerStyle+Multiplatform.swift in Sources */,
55B6465B253050200050BD95 /* SignatureString.swift in Sources */,
04131FBD2851571E001F60C2 /* CreateInviteOwnerIntroViewController.swift in Sources */,
0497B2AA29A63BE8007109ED /* WalletConnectManager.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ class DisconnectionConfirmationController: UIAlertController {
let alertController = DisconnectionConfirmationController(
title: nil,
message: "Your Safe Account will be disconnected from web.",
preferredStyle: .actionSheet)
preferredStyle: .multiplatformActionSheet)
let remove = UIAlertAction(title: "Disconnect", style: .destructive) { _ in
Tracker.trackEvent(.webConnectionDisconnected)
WebConnectionController.shared.userDidDisconnect(connection)
Expand All @@ -243,7 +243,7 @@ class DisconnectionConfirmationController: UIAlertController {
let alertController = DisconnectionConfirmationController(
title: nil,
message: "Your owner will be disconnected from the wallet.",
preferredStyle: .actionSheet)
preferredStyle: .multiplatformActionSheet)
let remove = UIAlertAction(title: "Disconnect", style: .destructive) { _ in
Tracker.trackEvent(.disconnectInstalledWallet)
WebConnectionController.shared.disconnectConnections(account: key.address)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,8 @@ class EnterCustomAddressViewController: UIViewController {
}

private func didTapAddressField() {
let alertVC = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
let alertVC = UIAlertController(title: nil, message: nil, preferredStyle: .multiplatformActionSheet)

if let popoverPresentationController = alertVC.popoverPresentationController {
popoverPresentationController.sourceView = addressField
}
alertVC.addAction(UIAlertAction(title: "Paste from Clipboard", style: .default, handler: { [weak self] _ in
let text = Pasteboard.string
self?.didEnterText(text)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,8 @@ class EnterSafeAddressViewController: UIViewController {
}

private func didTapAddressField() {
let alertVC = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
let alertVC = UIAlertController(title: nil, message: nil, preferredStyle: .multiplatformActionSheet)

if let popoverPresentationController = alertVC.popoverPresentationController {
popoverPresentationController.sourceView = addressField
}
alertVC.addAction(UIAlertAction(title: "Paste from Clipboard", style: .default, handler: { [weak self] _ in
let text = Pasteboard.string
self?.didEnterText(text)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class SelectAddressViewController: UIAlertController {
weak var presenter: UIViewController?

convenience init(chain: Chain?, presenter: UIViewController, completion: @escaping (Address) -> Void) {
self.init(title: nil, message: nil, preferredStyle: .actionSheet)
self.init(title: nil, message: nil, preferredStyle: .multiplatformActionSheet)
self.presenter = presenter
self.chain = chain
self.completion = completion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,7 @@ final class SwitchSafesViewController: UITableViewController {
let alertController = UIAlertController(
title: nil,
message: nil,
preferredStyle: .actionSheet)

if let popoverPresentationController = alertController.popoverPresentationController {
popoverPresentationController.sourceView = tableView
popoverPresentationController.sourceRect = tableView.rectForRow(at: indexPath)
}
preferredStyle: .multiplatformActionSheet)

let addSafe = UIAlertAction(title: "Load existing Safe Account", style: .default) { [weak self] _ in
self?.onAddSafe?()
Expand Down Expand Up @@ -169,28 +164,23 @@ final class SwitchSafesViewController: UITableViewController {

var actions = [UIContextualAction]()

let deleteAction = UIContextualAction(style: .destructive, title: "Remove") { [unowned self] _, _, completion in
self.remove(safe: safe, tableView: tableView, indexPath: indexPath)
let deleteAction = UIContextualAction(style: .destructive, title: "Remove") { [weak self] _, _, completion in
self?.remove(safe: safe)
completion(true)
}
actions.append(deleteAction)

return UISwipeActionsConfiguration(actions: actions)
}

private func remove(safe: Safe, tableView: UITableView, indexPath: IndexPath) {
private func remove(safe: Safe) {
let title = safe.safeStatus == .deployed ?
"Removing a Safe only removes it from this app. It does not delete the Safe from the blockchain. Funds will not get lost." :
"Are you sure you want to remove this Safe? The transaction fees will not be returned."
let alertController = UIAlertController(
title: nil,
message: title,
preferredStyle: .actionSheet)

if let popoverPresentationController = alertController.popoverPresentationController {
popoverPresentationController.sourceView = tableView
popoverPresentationController.sourceRect = tableView.rectForRow(at: indexPath)
}
preferredStyle: .multiplatformActionSheet)

let remove = UIAlertAction(title: "Remove", style: .destructive) { _ in
Safe.remove(safe: safe)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,14 @@ class AddressBookListTableViewController: LoadableViewController, UITableViewDel
let entry = chainEntries[indexPath.section].entries[indexPath.row]

var actions = [UIContextualAction]()
let editAction = UIContextualAction(style: .normal, title: "Edit") { [unowned self] _, _, completion in
showEdit(entry: chainEntries[indexPath.section].entries[indexPath.row])
let editAction = UIContextualAction(style: .normal, title: "Edit") { [weak self] _, _, completion in
self?.showEdit(entry: entry)
completion(true)
}
actions.append(editAction)

let deleteAction = UIContextualAction(style: .destructive, title: "Delete") { [unowned self] _, _, completion in
self.remove(entry, tableView: tableView, indexPath: indexPath)
let deleteAction = UIContextualAction(style: .destructive, title: "Delete") { [weak self] _, _, completion in
self?.remove(entry)
completion(true)
}
actions.append(deleteAction)
Expand Down Expand Up @@ -232,15 +232,12 @@ class AddressBookListTableViewController: LoadableViewController, UITableViewDel
show(ribbonVC, sender: nil)
}

private func remove(_ entry: AddressBookEntry, tableView: UITableView, indexPath: IndexPath) {
private func remove(_ entry: AddressBookEntry) {
let alertController = UIAlertController(
title: nil,
message: "Removing the entry key only removes it from this app.",
preferredStyle: .actionSheet)
if let popoverPresentationController = alertController.popoverPresentationController {
popoverPresentationController.sourceView = tableView
popoverPresentationController.sourceRect = tableView.rectForRow(at: indexPath)
}
preferredStyle: .multiplatformActionSheet)

let remove = UIAlertAction(title: "Remove", style: .destructive) { _ in
AddressBookEntry.remove(entry: entry)
App.shared.snackbar.show(message: "Address book entry removed")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,8 @@ class CreateAddressBookEntryViewController: UIViewController {
}

private func didTapAddressField() {
let alertVC = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
let alertVC = UIAlertController(title: nil, message: nil, preferredStyle: .multiplatformActionSheet)

if let popoverPresentationController = alertVC.popoverPresentationController {
popoverPresentationController.sourceView = addressField
}
alertVC.addAction(UIAlertAction(title: "Paste from Clipboard", style: .default, handler: { [weak self] _ in
let text = Pasteboard.string
self?.didEnterText(text)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class AddKeyAsOwnerIntroViewController: UIViewController, UIAdaptivePresentation
let alertController = UIAlertController(
title: nil,
message: nil,
preferredStyle: .actionSheet)
preferredStyle: .multiplatformActionSheet)

let add = UIAlertAction(title: "Add new owner", style: .default) { [unowned self] _ in
onAdd?()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class OwnerKeyDetailsViewController: UITableViewController, WebConnectionObserve
}

@IBAction func removeButtonTouched(_ sender: UIButton) {
removeKey(sourceView: sender)
removeKey()
}

@objc private func didTapExportButton() {
Expand Down Expand Up @@ -255,14 +255,12 @@ class OwnerKeyDetailsViewController: UITableViewController, WebConnectionObserve
completion?()
}

private func removeKey(sourceView: UIView) {
private func removeKey() {
let alertController = UIAlertController(
title: nil,
message: "Removing the owner key only removes it from this app. It doesn’t delete any Safes from this app or from blockchain. Transactions for Safes controlled by this key will no longer be available for signing in this app.",
preferredStyle: .actionSheet)
if let popoverPresentationController = alertController.popoverPresentationController {
popoverPresentationController.sourceView = sourceView
}
preferredStyle: .multiplatformActionSheet)

let remove = UIAlertAction(title: "Remove", style: .destructive) { _ in
OwnerKeyController.remove(keyInfo: self.keyInfo)
}
Expand Down Expand Up @@ -315,11 +313,7 @@ class OwnerKeyDetailsViewController: UITableViewController, WebConnectionObserve
indexPath: indexPath)
case Section.Advanced.remove:
return tableView.removeCell(indexPath: indexPath, title: "Remove owner key") { [weak self] in
guard let self = self,
let cell = tableView.cellForRow(at: indexPath) else {
return
}
self.removeKey(sourceView: cell)
self?.removeKey()
}
default:
return UITableViewCell()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ class OwnerKeysListViewController: LoadableViewController, UITableViewDelegate,
actions.append(wcAction)
}

let deleteAction = UIContextualAction(style: .destructive, title: "Delete") { [unowned self] _, _, completion in
self.remove(key: keyInfo, tableView: tableView, indexPath: indexPath)
let deleteAction = UIContextualAction(style: .destructive, title: "Delete") { [weak self] _, _, completion in
self?.remove(key: keyInfo)
completion(true)
}
actions.append(deleteAction)
Expand All @@ -174,16 +174,11 @@ class OwnerKeysListViewController: LoadableViewController, UITableViewDelegate,
present(vc, animated: true)
}

private func remove(key: KeyInfo, tableView: UITableView, indexPath: IndexPath) {
private func remove(key: KeyInfo) {
let alertController = UIAlertController(
title: nil,
message: "Removing the owner key only removes it from this app. It doesn’t delete any Safes from this app or from blockchain. Transactions for Safes controlled by this key will no longer be available for signing in this app.",
preferredStyle: .actionSheet)

if let popoverPresentationController = alertController.popoverPresentationController {
popoverPresentationController.sourceView = tableView
popoverPresentationController.sourceRect = tableView.rectForRow(at: indexPath)
}
preferredStyle: .multiplatformActionSheet)

let remove = UIAlertAction(title: "Remove", style: .destructive) { _ in
OwnerKeyController.remove(keyInfo: key)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class ReceiveAddOwnerLinkViewController: UIViewController {
let alertController = UIAlertController(
title: nil,
message: nil,
preferredStyle: .actionSheet)
preferredStyle: .multiplatformActionSheet)
alertController.addAction(add)
alertController.addAction(replace)
alertController.addAction(cancel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,15 +353,10 @@ class SafeSettingsViewController: LoadableViewController, UITableViewDelegate, U
let alertController = UIAlertController(
title: nil,
message: "Removing a Safe only removes it from this app. It does not delete the Safe from the blockchain. Funds will not get lost.",
preferredStyle: .actionSheet)
preferredStyle: .multiplatformActionSheet)

if let popoverPresentationController = alertController.popoverPresentationController {
popoverPresentationController.sourceView = tableView
popoverPresentationController.sourceRect = tableView.rectForRow(at: indexPath)
}

let remove = UIAlertAction(title: "Remove", style: .destructive) { _ in
if let safe = self.safe {
let remove = UIAlertAction(title: "Remove", style: .destructive) { [weak self] _ in
if let safe = self?.safe {
Safe.remove(safe: safe)
}
}
Expand Down
24 changes: 24 additions & 0 deletions Multisig/UI/UI Library/UIAlertControllerStyle+Multiplatform.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// UIAlertControllerStyle+Multiplatform.swift
// Multisig
//
// Created by Dmitrii Bespalov on 10.08.23.
// Copyright © 2023 Gnosis Ltd. All rights reserved.
//

import UIKit

extension UIAlertController.Style {
// Thanks to adamek and matt for the inspiration https://stackoverflow.com/questions/73007791/is-there-a-way-to-detect-which-platform-is-running-in-an-xcode-ios-macos-multipl
static var multiplatformActionSheet: UIAlertController.Style {
#if os(iOS)
if UIDevice.current.userInterfaceIdiom == .phone {
return .actionSheet
} else {
return .alert
}
#else
return .alert
#endif
}
}

0 comments on commit d005f3f

Please sign in to comment.