diff --git a/Shared/Extension/String.swift b/Shared/Extension/String.swift index b8eaebc7..defb63e4 100644 --- a/Shared/Extension/String.swift +++ b/Shared/Extension/String.swift @@ -21,4 +21,10 @@ extension String { return self + "…" } + var trimmedAddress: String { + guard !isEmpty else { return self } + let without0x = dropFirst(2) + return without0x.prefix(4) + "..." + without0x.suffix(4) + } + } diff --git a/Tokenary iOS/Screens/Accounts/AccountTableViewCell.swift b/Tokenary iOS/Screens/Accounts/AccountTableViewCell.swift index 7b09d90a..18c8dfca 100644 --- a/Tokenary iOS/Screens/Accounts/AccountTableViewCell.swift +++ b/Tokenary iOS/Screens/Accounts/AccountTableViewCell.swift @@ -18,8 +18,7 @@ class AccountTableViewCell: UITableViewCell { func setup(address: String, delegate: AccountTableViewCellDelegate) { cellDelegate = delegate avatarImageView.image = Blockies(seed: address.lowercased()).createImage() - let without0x = address.dropFirst(2) - titleLabel.text = without0x.prefix(4) + "..." + without0x.suffix(4) + titleLabel.text = address.trimmedAddress } @IBAction func moreButtonTapped(_ sender: Any) { diff --git a/Tokenary iOS/Screens/Accounts/AccountsListViewController.swift b/Tokenary iOS/Screens/Accounts/AccountsListViewController.swift index 19575229..344885d8 100644 --- a/Tokenary iOS/Screens/Accounts/AccountsListViewController.swift +++ b/Tokenary iOS/Screens/Accounts/AccountsListViewController.swift @@ -84,14 +84,16 @@ class AccountsListViewController: UIViewController, DataStateContainer { } presentForSafariRequest(selectAccountViewController.inNavigationController) case .signPersonalMessage: - guard let data = request.message else { + guard let data = request.message, + let wallet = walletsManager.getWallet(address: request.address), + let address = wallet.ethereumAddress else { respondTo(request: request, error: Strings.somethingWentWrong) return } let text = String(data: data, encoding: .utf8) ?? data.hexString - showApprove(subject: .signPersonalMessage, meta: text, peerMeta: peerMeta) { [weak self] approved in + showApprove(subject: .signPersonalMessage, address: address, meta: text, peerMeta: peerMeta) { [weak self] approved in if approved { - self?.signPersonalMessage(address: request.address, data: data, request: request) + self?.signPersonalMessage(wallet: wallet, data: data, request: request) } else { self?.respondTo(request: request, error: Strings.failedToSign) } @@ -108,8 +110,8 @@ class AccountsListViewController: UIViewController, DataStateContainer { } } - func showApprove(subject: ApprovalSubject, meta: String, peerMeta: PeerMeta?, completion: @escaping (Bool) -> Void) { - let approveViewController = ApproveViewController.with(subject: subject, meta: meta, peerMeta: peerMeta, completion: completion) + func showApprove(subject: ApprovalSubject, address: String, meta: String, peerMeta: PeerMeta?, completion: @escaping (Bool) -> Void) { + let approveViewController = ApproveViewController.with(subject: subject, address: address, meta: meta, peerMeta: peerMeta, completion: completion) presentForSafariRequest(approveViewController.inNavigationController) } @@ -354,8 +356,8 @@ class AccountsListViewController: UIViewController, DataStateContainer { present(alert, animated: true) } - private func signPersonalMessage(address: String, data: Data, request: SafariRequest) { - if let wallet = walletsManager.getWallet(address: address), let signed = try? ethereum.signPersonalMessage(data: data, wallet: wallet) { + private func signPersonalMessage(wallet: TokenaryWallet, data: Data, request: SafariRequest) { + if let signed = try? ethereum.signPersonalMessage(data: data, wallet: wallet) { let response = ResponseToExtension(name: request.name, result: signed) respondTo(request: request, response: response) } else { diff --git a/Tokenary iOS/Screens/Approve/ApproveViewController.swift b/Tokenary iOS/Screens/Approve/ApproveViewController.swift index 4864ee89..293cdfab 100644 --- a/Tokenary iOS/Screens/Approve/ApproveViewController.swift +++ b/Tokenary iOS/Screens/Approve/ApproveViewController.swift @@ -1,6 +1,7 @@ // Copyright © 2021 Tokenary. All rights reserved. import UIKit +import BlockiesSwift class ApproveViewController: UIViewController { @@ -21,15 +22,17 @@ class ApproveViewController: UIViewController { private var cellModels = [CellModel]() private var approveTitle: String! + private var address: String! private var meta: String! private var completion: ((Bool) -> Void)! private var peerMeta: PeerMeta? @IBOutlet weak var okButton: UIButton! - static func with(subject: ApprovalSubject, meta: String, peerMeta: PeerMeta?, completion: @escaping (Bool) -> Void) -> ApproveViewController { + static func with(subject: ApprovalSubject, address: String, meta: String, peerMeta: PeerMeta?, completion: @escaping (Bool) -> Void) -> ApproveViewController { let new = instantiate(ApproveViewController.self, from: .main) new.completion = completion + new.address = address new.meta = meta new.approveTitle = subject.title new.peerMeta = peerMeta @@ -43,6 +46,7 @@ class ApproveViewController: UIViewController { navigationItem.largeTitleDisplayMode = .always isModalInPresentation = true cellModels = [.textWithImage(text: peerMeta?.name ?? Strings.unknownWebsite, imageURL: peerMeta?.iconURLString, image: nil), + .textWithImage(text: address.trimmedAddress, imageURL: nil, image: Blockies(seed: address.lowercased()).createImage()), .text(meta)] } diff --git a/Tokenary iOS/Screens/Approve/ImageWithLabelTableViewCell.swift b/Tokenary iOS/Screens/Approve/ImageWithLabelTableViewCell.swift index 78b2f611..395bb56a 100644 --- a/Tokenary iOS/Screens/Approve/ImageWithLabelTableViewCell.swift +++ b/Tokenary iOS/Screens/Approve/ImageWithLabelTableViewCell.swift @@ -12,6 +12,7 @@ class ImageWithLabelTableViewCell: UITableViewCell { titleLabel.text = text if let image = image { iconImageView.image = image + iconImageView.layer.cornerRadius = 15 } else if let urlString = imageURL, let url = URL(string: urlString) { iconImageView.kf.setImage(with: url) } @@ -21,6 +22,7 @@ class ImageWithLabelTableViewCell: UITableViewCell { super.prepareForReuse() iconImageView.kf.cancelDownloadTask() iconImageView.image = Images.circleFill + iconImageView.layer.cornerRadius = 0 } }