Pass peer meta to approve view controllers

This commit is contained in:
Ivan Grachev 2021-07-02 23:00:00 +03:00
parent 83a693f70b
commit 9f50da43fa
4 changed files with 17 additions and 8 deletions

View File

@ -61,9 +61,9 @@ class Agent: NSObject {
}
}
func showApprove(transaction: Transaction, completion: @escaping (Transaction?) -> Void) {
func showApprove(transaction: Transaction, peerMeta: WCPeerMeta?, completion: @escaping (Transaction?) -> Void) {
let windowController = Window.showNew()
let approveViewController = ApproveTransactionViewController.with(transaction: transaction) { [weak self] transaction in
let approveViewController = ApproveTransactionViewController.with(transaction: transaction, peerMeta: peerMeta) { [weak self] transaction in
if transaction != nil {
self?.askAuthentication(on: windowController.window, onStart: false, reason: Strings.sendTransaction) { success in
completion(success ? transaction : nil)
@ -77,9 +77,9 @@ class Agent: NSObject {
windowController.contentViewController = approveViewController
}
func showApprove(title: String, meta: String, completion: @escaping (Bool) -> Void) {
func showApprove(title: String, meta: String, peerMeta: WCPeerMeta?, completion: @escaping (Bool) -> Void) {
let windowController = Window.showNew()
let approveViewController = ApproveViewController.with(title: title, meta: meta) { [weak self] result in
let approveViewController = ApproveViewController.with(title: title, meta: meta, peerMeta: peerMeta) { [weak self] result in
if result {
self?.askAuthentication(on: windowController.window, onStart: false, reason: title) { success in
completion(success)

View File

@ -1,6 +1,7 @@
// Copyright © 2021 Encrypted Ink. All rights reserved.
import Cocoa
import WalletConnect
class ApproveTransactionViewController: NSViewController {
@ -17,7 +18,7 @@ class ApproveTransactionViewController: NSViewController {
private var completion: ((Transaction?) -> Void)!
private var didEnableSpeedConfiguration = false
static func with(transaction: Transaction, completion: @escaping (Transaction?) -> Void) -> ApproveTransactionViewController {
static func with(transaction: Transaction, peerMeta: WCPeerMeta?, completion: @escaping (Transaction?) -> Void) -> ApproveTransactionViewController {
let new = instantiate(ApproveTransactionViewController.self)
new.transaction = transaction
new.completion = completion

View File

@ -1,6 +1,7 @@
// Copyright © 2021 Encrypted Ink. All rights reserved.
import Cocoa
import WalletConnect
class ApproveViewController: NSViewController {
@ -12,7 +13,7 @@ class ApproveViewController: NSViewController {
var meta: String!
var completion: ((Bool) -> Void)!
static func with(title: String, meta: String, completion: @escaping (Bool) -> Void) -> ApproveViewController {
static func with(title: String, meta: String, peerMeta: WCPeerMeta?, completion: @escaping (Bool) -> Void) -> ApproveViewController {
let new = instantiate(ApproveViewController.self)
new.completion = completion
new.meta = meta

View File

@ -42,6 +42,11 @@ class WalletConnect {
peers.removeValue(forKey: id)
}
private func getPeerOfInteractor(_ interactor: WCInteractor?) -> WCPeerMeta? {
guard let id = interactor?.clientId else { return nil }
return peers[id]
}
private func configure(interactor: WCInteractor, address: String) {
let accounts = [address]
let chainId = 1
@ -76,8 +81,9 @@ class WalletConnect {
return
}
let peer = getPeerOfInteractor(interactor)
let transaction = Transaction(from: wct.from, to: to, nonce: wct.nonce, gasPrice: wct.gasPrice, gas: wct.gas, value: wct.value, data: wct.data)
Agent.shared.showApprove(transaction: transaction) { [weak self, weak interactor] transaction in
Agent.shared.showApprove(transaction: transaction, peerMeta: peer) { [weak self, weak interactor] transaction in
if let transaction = transaction {
self?.sendTransaction(transaction, address: address, requestId: id, interactor: interactor)
} else {
@ -103,7 +109,8 @@ class WalletConnect {
}
}
Agent.shared.showApprove(title: title, meta: message ?? "") { [weak self, weak interactor] approved in
let peer = getPeerOfInteractor(interactor)
Agent.shared.showApprove(title: title, meta: message ?? "", peerMeta: peer) { [weak self, weak interactor] approved in
if approved {
self?.sign(id: id, message: message, payload: payload, address: address, interactor: interactor)
} else {