Display address on approve string

This commit is contained in:
Ivan Grachyov 2021-12-13 16:57:02 +03:00
parent 55d5480d41
commit d7fea70986
5 changed files with 23 additions and 10 deletions

View File

@ -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)
}
}

View File

@ -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) {

View File

@ -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 {

View File

@ -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)]
}

View File

@ -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
}
}