Skip to content

Commit

Permalink
Make WalletConnect signature request be clearer about where it's comi…
Browse files Browse the repository at this point in the history
…ng from AlphaWallet#3289
  • Loading branch information
vladyslav-iosdev committed Nov 2, 2021
1 parent 34f1535 commit 3355849
Show file tree
Hide file tree
Showing 23 changed files with 302 additions and 226 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ final class DappBrowserCoordinator: NSObject, Coordinator {

private func signMessage(with type: SignMessageType, account: AlphaWallet.Address, callbackID: Int) {
firstly {
SignMessageCoordinator.promise(analyticsCoordinator: analyticsCoordinator, navigationController: navigationController, keystore: keystore, coordinator: self, signType: type, account: account, source: .dappBrowser)
SignMessageCoordinator.promise(analyticsCoordinator: analyticsCoordinator, navigationController: navigationController, keystore: keystore, coordinator: self, signType: type, account: account, source: .dappBrowser, walletConnectSession: nil)
}.done { data in
let callback: DappCallback
switch type {
Expand Down
4 changes: 2 additions & 2 deletions AlphaWallet/Core/ViewModels/PromptViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ struct PromptViewModel {
}

var footerBackgroundColor: UIColor {
R.color.white()!
Colors.appWhite
}
}
}
2 changes: 2 additions & 0 deletions AlphaWallet/Localization/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
"transaction.blockNumber.label.title" = "Block #";
"transaction.nonce.label.title" = "Nonce";
"confirmPayment.confirm.button.title" = "Confirm";
"confirmPayment.sign.button.title" = "Sign";
"confirmPayment.reject.button.title" = "Reject";
"confirmPayment.connect.button.title" = "Connect";
"confirmPayment.from.label.title" = "From";
"confirmPayment.gasFee.label.title" = "Estimate Network Fee";
"confirmPayment.gasLimit.label.title" = "Gas Limit";
Expand Down
2 changes: 2 additions & 0 deletions AlphaWallet/Localization/es.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
"transaction.blockNumber.label.title" = "Bloque n.º";
"transaction.nonce.label.title" = "Nonce";
"confirmPayment.confirm.button.title" = "Confirmar";
"confirmPayment.sign.button.title" = "Sign";
"confirmPayment.reject.button.title" = "Reject";
"confirmPayment.connect.button.title" = "Connect";
"confirmPayment.from.label.title" = "De";
"confirmPayment.gasFee.label.title" = "Estimación de la tarifa de red";
"confirmPayment.gasLimit.label.title" = "Límite de gas";
Expand Down
2 changes: 2 additions & 0 deletions AlphaWallet/Localization/ja.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
"transaction.blockNumber.label.title" = "ブロック番号";
"transaction.nonce.label.title" = "Nonce";
"confirmPayment.confirm.button.title" = "確認";
"confirmPayment.sign.button.title" = "Sign";
"confirmPayment.reject.button.title" = "Reject";
"confirmPayment.connect.button.title" = "Connect";
"confirmPayment.from.label.title" = "送信元";
"confirmPayment.gasFee.label.title" = "Estimate Network Fee";
"confirmPayment.gasLimit.label.title" = "ガスの制限";
Expand Down
2 changes: 2 additions & 0 deletions AlphaWallet/Localization/ko.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
"transaction.blockNumber.label.title" = "블록 번호";
"transaction.nonce.label.title" = "Nonce";
"confirmPayment.confirm.button.title" = "확인";
"confirmPayment.sign.button.title" = "Sign";
"confirmPayment.reject.button.title" = "Reject";
"confirmPayment.connect.button.title" = "Connect";
"confirmPayment.from.label.title" = "발신인";
"confirmPayment.gasFee.label.title" = "Estimate Network Fee";
"confirmPayment.gasLimit.label.title" = "가스 한도";
Expand Down
2 changes: 2 additions & 0 deletions AlphaWallet/Localization/zh-Hans.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
"transaction.blockNumber.label.title" = "区块 #";
"transaction.nonce.label.title" = "Nonce";
"confirmPayment.confirm.button.title" = "确认";
"confirmPayment.sign.button.title" = "Sign";
"confirmPayment.reject.button.title" = "Reject";
"confirmPayment.connect.button.title" = "Connect";
"confirmPayment.from.label.title" = "来源地址";
"confirmPayment.gasFee.label.title" = "估计网络费用";
"confirmPayment.gasLimit.label.title" = "燃料限制";
Expand Down
2 changes: 1 addition & 1 deletion AlphaWallet/Tokens/Views/TokenInstanceWebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ extension TokenInstanceWebView {
guard let navigationController = delegate?.navigationControllerFor(tokenInstanceWebView: self) else { return }
let keystore = try! EtherKeystore(analyticsCoordinator: analyticsCoordinator)
firstly {
SignMessageCoordinator.promise(analyticsCoordinator: analyticsCoordinator, navigationController: navigationController, keystore: keystore, signType: type, account: account, source: .tokenScript)
SignMessageCoordinator.promise(analyticsCoordinator: analyticsCoordinator, navigationController: navigationController, keystore: keystore, signType: type, account: account, source: .tokenScript, walletConnectSession: nil)
}.done { data in
let callback: DappCallback
switch type {
Expand Down
11 changes: 6 additions & 5 deletions AlphaWallet/Transfer/Coordinators/SignMessageCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class SignMessageCoordinator: Coordinator {
weak var delegate: SignMessageCoordinatorDelegate?

private lazy var confirmationViewController: SignatureConfirmationViewController = {
let controller = SignatureConfirmationViewController(viewModel: .init(message: message))
let controller = SignatureConfirmationViewController(viewModel: .init(message: message, walletConnectSession: walletConnectSession))
controller.delegate = self
return controller
}()
Expand All @@ -42,10 +42,12 @@ class SignMessageCoordinator: Coordinator {

return controller
}()

init(analyticsCoordinator: AnalyticsCoordinator, navigationController: UINavigationController, keystore: Keystore, account: AlphaWallet.Address, message: SignMessageType, source: Analytics.SignMessageRequestSource) {
private let walletConnectSession: WalletConnectSessionViewModel?

init(analyticsCoordinator: AnalyticsCoordinator, navigationController: UINavigationController, keystore: Keystore, account: AlphaWallet.Address, message: SignMessageType, source: Analytics.SignMessageRequestSource, walletConnectSession: WalletConnectSessionViewModel?) {
self.analyticsCoordinator = analyticsCoordinator
self.presentationNavigationController = navigationController
self.walletConnectSession = walletConnectSession
self.keystore = keystore
self.account = account
self.message = message
Expand Down Expand Up @@ -133,8 +135,7 @@ extension SignMessageCoordinator: SignatureConfirmationViewControllerDelegate {
func didClose(in controller: SignatureConfirmationViewController) {
analyticsCoordinator.log(action: Analytics.Action.cancelSignMessageRequest)
navigationController.dismiss(animated: false) {
guard let delegate = self.delegate else { return }
delegate.didCancel(in: self)
self.delegate?.didCancel(in: self)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ import Result
enum TransactionConfirmationConfiguration {
case tokenScriptTransaction(confirmType: ConfirmType, contract: AlphaWallet.Address, keystore: Keystore, functionCallMetaData: DecodedFunctionCall, ethPrice: Subscribable<Double>)
case dappTransaction(confirmType: ConfirmType, keystore: Keystore, ethPrice: Subscribable<Double>)
case walletConnect(confirmType: ConfirmType, keystore: Keystore, ethPrice: Subscribable<Double>)
case walletConnect(confirmType: ConfirmType, keystore: Keystore, ethPrice: Subscribable<Double>, walletConnectSession: WalletConnectSessionMappedToServer)
case sendFungiblesTransaction(confirmType: ConfirmType, keystore: Keystore, assetDefinitionStore: AssetDefinitionStore, amount: FungiblesTransactionAmount, ethPrice: Subscribable<Double>)
case sendNftTransaction(confirmType: ConfirmType, keystore: Keystore, ethPrice: Subscribable<Double>, tokenInstanceName: String?)
case claimPaidErc875MagicLink(confirmType: ConfirmType, keystore: Keystore, price: BigUInt, ethPrice: Subscribable<Double>, numberOfTokens: UInt)
case speedupTransaction(keystore: Keystore, ethPrice: Subscribable<Double>)
case cancelTransaction(keystore: Keystore, ethPrice: Subscribable<Double>)

var confirmType: ConfirmType {
switch self {
case .dappTransaction(let confirmType, _, _), .walletConnect(let confirmType, _, _), .sendFungiblesTransaction(let confirmType, _, _, _, _), .sendNftTransaction(let confirmType, _, _, _), .tokenScriptTransaction(let confirmType, _, _, _, _), .claimPaidErc875MagicLink(let confirmType, _, _, _, _):
case .dappTransaction(let confirmType, _, _), .walletConnect(let confirmType, _, _, _), .sendFungiblesTransaction(let confirmType, _, _, _, _), .sendNftTransaction(let confirmType, _, _, _), .tokenScriptTransaction(let confirmType, _, _, _, _), .claimPaidErc875MagicLink(let confirmType, _, _, _, _):
return confirmType
case .speedupTransaction, .cancelTransaction:
return .signThenSend
Expand All @@ -30,14 +31,14 @@ enum TransactionConfirmationConfiguration {

var keystore: Keystore {
switch self {
case .dappTransaction(_, let keystore, _), .walletConnect(_, let keystore, _), .sendFungiblesTransaction(_, let keystore, _, _, _), .sendNftTransaction(_, let keystore, _, _), .tokenScriptTransaction(_, _, let keystore, _, _), .claimPaidErc875MagicLink(_, let keystore, _, _, _), .speedupTransaction(let keystore, _), .cancelTransaction(let keystore, _):
case .dappTransaction(_, let keystore, _), .walletConnect(_, let keystore, _, _), .sendFungiblesTransaction(_, let keystore, _, _, _), .sendNftTransaction(_, let keystore, _, _), .tokenScriptTransaction(_, _, let keystore, _, _), .claimPaidErc875MagicLink(_, let keystore, _, _, _), .speedupTransaction(let keystore, _), .cancelTransaction(let keystore, _):
return keystore
}
}

var ethPrice: Subscribable<Double> {
switch self {
case .dappTransaction(_, _, let ethPrice), .walletConnect(_, _, let ethPrice), .sendFungiblesTransaction(_, _, _, _, let ethPrice), .sendNftTransaction(_, _, let ethPrice, _), .tokenScriptTransaction(_, _, _, _, let ethPrice), .claimPaidErc875MagicLink(_, _, _, let ethPrice, _), .speedupTransaction(_, let ethPrice), .cancelTransaction(_, let ethPrice):
case .dappTransaction(_, _, let ethPrice), .walletConnect(_, _, let ethPrice, _), .sendFungiblesTransaction(_, _, _, _, let ethPrice), .sendNftTransaction(_, _, let ethPrice, _), .tokenScriptTransaction(_, _, _, _, let ethPrice), .claimPaidErc875MagicLink(_, _, _, let ethPrice, _), .speedupTransaction(_, let ethPrice), .cancelTransaction(_, let ethPrice):
return ethPrice
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ protocol SignatureConfirmationViewControllerDelegate: AnyObject {

class SignatureConfirmationViewController: UIViewController {
private lazy var headerView = ConfirmationHeaderView(viewModel: .init(title: viewModel.navigationTitle))
private let buttonsBar = ButtonsBar(configuration: .custom(types: [.green, .white]))
private let buttonsBar = ButtonsBar(configuration: .empty)
private (set) var viewModel: SignatureConfirmationViewModel

private let stackView: UIStackView = {
Expand Down Expand Up @@ -224,22 +224,23 @@ class SignatureConfirmationViewController: UIViewController {
func reloadView() {
generateSubviews()
}

private func configure(for viewModel: SignatureConfirmationViewModel) {
scrollView.backgroundColor = viewModel.backgroundColor
view.backgroundColor = viewModel.backgroundColor
navigationItem.title = viewModel.title

buttonsBar.configure()
headerView.iconImageView.setImage(url: viewModel.dappIconUrl, placeholder: viewModel.placeholderIcon)
buttonsBar.configure(.custom(types: [.white, .green]))

let button1 = buttonsBar.buttons[0]
let button1 = buttonsBar.buttons[1]
button1.shrinkBorderColor = Colors.loadingIndicatorBorder
button1.setTitle(viewModel.confirmationButtonTitle, for: .normal)
button1.addTarget(self, action: #selector(confirmButtonTapped), for: .touchUpInside)

let button2 = buttonsBar.buttons[1]
let button2 = buttonsBar.buttons[0]
button2.shrinkBorderColor = Colors.loadingIndicatorBorder
button2.setTitle(viewModel.rejectionButtonTitle, for: .normal)
button2.setTitle(viewModel.cancelationButtonTitle, for: .normal)
button2.addTarget(self, action: #selector(dismissViewController), for: .touchUpInside)
}

Expand All @@ -260,29 +261,61 @@ extension SignatureConfirmationViewController {
var views: [UIView] = []
switch viewModel {
case .typedMessage(let viewModel):
for sectionIndex in viewModel.typedData.indices {
let header = TransactionConfirmationHeaderView(viewModel: viewModel.headerViewModel(section: sectionIndex))
header.delegate = self
header.enableTapAction(title: "Show")

views.append(header)
for each in viewModel.viewModels {
switch each {
case .header(let headerViewModel):
let header = TransactionConfirmationHeaderView(viewModel: headerViewModel)
header.delegate = self

views.append(header)
case .headerWithShowButton(let headerViewModel, let availableToShowFullMessage):
let header = TransactionConfirmationHeaderView(viewModel: headerViewModel)
header.delegate = self

if availableToShowFullMessage {
header.enableTapAction(title: "Show")
}

views.append(header)
}
}
case .personalMessage(viewModel: let viewModel), .message(viewModel: let viewModel):
let header = TransactionConfirmationHeaderView(viewModel: viewModel.headerViewModel(section: 0))
header.delegate = self

if viewModel.availableToShowFullMessage {
header.enableTapAction(title: "Show")
case .personalMessage(let viewModel), .message(let viewModel):
for each in viewModel.viewModels {
switch each {
case .header(let headerViewModel):
let header = TransactionConfirmationHeaderView(viewModel: headerViewModel)
header.delegate = self

views.append(header)
case .headerWithShowButton(let headerViewModel, let availableToShowFullMessage):
let header = TransactionConfirmationHeaderView(viewModel: headerViewModel)
header.delegate = self

if availableToShowFullMessage {
header.enableTapAction(title: "Show")
}

views.append(header)
}
}

views.append(header)
case .eip712v3And4(viewModel: let viewModel):
for sectionIndex in viewModel.values.indices {
let header = TransactionConfirmationHeaderView(viewModel: viewModel.headerViewModel(section: sectionIndex))
header.delegate = self
header.enableTapAction(title: "Show")

views.append(header)
case .eip712v3And4(let viewModel):
for each in viewModel.viewModels {
switch each {
case .header(let headerViewModel):
let header = TransactionConfirmationHeaderView(viewModel: headerViewModel)
header.delegate = self

views.append(header)
case .headerWithShowButton(let headerViewModel, let availableToShowFullMessage):
let header = TransactionConfirmationHeaderView(viewModel: headerViewModel)
header.delegate = self

if availableToShowFullMessage {
header.enableTapAction(title: "Show")
}

views.append(header)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ class TransactionConfirmationViewController: UIViewController {

switch viewModel {
case .dappOrWalletConnectTransaction(let dappTransactionViewModel):
headerView.iconImageView.setImage(url: dappTransactionViewModel.dappIconUrl, placeholder: dappTransactionViewModel.placeholderIcon)

dappTransactionViewModel.ethPrice.subscribe { [weak self] cryptoToDollarRate in
guard let strongSelf = self else { return }
dappTransactionViewModel.cryptoToDollarRate = cryptoToDollarRate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ struct ConfirmationHeaderViewModel {
style.alignment = .center

return .init(string: title, attributes: [
.font: DataEntry.Font.text as Any,
.font: Fonts.semibold(size: 17) as Any,
.paragraphStyle: style,
.foregroundColor: Colors.darkGray
.foregroundColor: Colors.black
])
}
var swipeIndicationHidden: Bool
Expand Down
Loading

0 comments on commit 3355849

Please sign in to comment.