Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:WalletConnect/WalletConnectSwift…
Browse files Browse the repository at this point in the history
…V2 into #273-encryption-policies

# Conflicts:
#	Sources/Chat/NetworkingInteractor.swift
#	Sources/Chat/Serializing.swift
#	Sources/WalletConnectKMS/Codec/ChaChaPolyCodec.swift
#	Sources/WalletConnectKMS/Crypto/CryptoKitWrapper/CryptoKitWrapper.swift
#	Sources/WalletConnectKMS/Crypto/KeyManagementService.swift
#	Sources/WalletConnectKMS/Serialiser/Serializer.swift
#	Sources/WalletConnectSign/NetworkInteractor/NetworkInteractor.swift
#	Sources/WalletConnectSign/Serializing.swift
#	Tests/IntegrationTests/SerialiserTests.swift
#	Tests/TestingUtils/Mocks/KeyManagementServiceMock.swift
#	Tests/WalletConnectSignTests/Mocks/SerializerMock.swift
  • Loading branch information
llbartekll committed Jun 21, 2022
2 parents fb0b576 + 9412506 commit 0bd0a56
Show file tree
Hide file tree
Showing 203 changed files with 2,313 additions and 2,109 deletions.
20 changes: 20 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
disabled_rules:
- line_length
- force_try
- force_cast
- todo
- identifier_name
- nesting
- for_where
- large_tuple
- xctfail_message
- redundant_string_enum_value
- orphaned_doc_comment
- file_length
- type_name
- type_body_length
- multiple_closures_with_trailing_closure
- unused_optional_binding

# Rules descriptions: https://realm.github.io/SwiftLint/rule-directory.html

8 changes: 4 additions & 4 deletions Example/DApp/ Accounts/AccountsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ final class AccountsView: UIView {
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "accountCell")
return tableView
}()

override init(frame: CGRect) {
super.init(frame: frame)
backgroundColor = .systemBackground
addSubview(tableView)

subviews.forEach { $0.translatesAutoresizingMaskIntoConstraints = false }

NSLayoutConstraint.activate([
tableView.topAnchor.constraint(equalTo: safeAreaLayoutGuide.topAnchor, constant: 16),
tableView.leadingAnchor.constraint(equalTo: leadingAnchor),
tableView.trailingAnchor.constraint(equalTo: trailingAnchor),
tableView.bottomAnchor.constraint(equalTo: safeAreaLayoutGuide.bottomAnchor)
])
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
Expand Down
34 changes: 17 additions & 17 deletions Example/DApp/ Accounts/AccountsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,33 @@ struct AccountDetails {
let account: String
}

final class AccountsViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
final class AccountsViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

let session: Session
var accountsDetails: [AccountDetails] = []
var onDisconnect: (()->())?
var onDisconnect: (() -> Void)?

private let accountsView: AccountsView = {
AccountsView()
}()

init(session: Session) {
self.session = session
super.init(nibName: nil, bundle: nil)
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func loadView() {
view = accountsView
}

override func viewDidLoad() {
super.viewDidLoad()
navigationItem.title = "Accounts"

navigationItem.rightBarButtonItem = UIBarButtonItem(
title: "Disconnect",
style: .plain,
Expand All @@ -48,7 +48,7 @@ final class AccountsViewController: UIViewController, UITableViewDataSource, UIT
}
}
}

@objc
private func disconnect() {
Task {
Expand All @@ -59,15 +59,15 @@ final class AccountsViewController: UIViewController, UITableViewDataSource, UIT
}
} catch {
print(error)
//show failure alert
// show failure alert
}
}
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
accountsDetails.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "accountCell", for: indexPath)
let details = accountsDetails[indexPath.row]
Expand All @@ -76,18 +76,18 @@ final class AccountsViewController: UIViewController, UITableViewDataSource, UIT
cell.textLabel?.numberOfLines = 0
return cell
}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
showAccountRequestScreen(accountsDetails[indexPath.row])
}

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 70
}

func showAccountRequestScreen(_ details: AccountDetails) {
let vc = AccountRequestViewController(session: session, accountDetails: details)
navigationController?.pushViewController(vc, animated: true)
}

}
17 changes: 8 additions & 9 deletions Example/DApp/AccountRequest/AccountRequestView.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import UIKit
import Foundation

Expand All @@ -10,7 +9,7 @@ class AccountRequestView: UIView {
imageView.layer.cornerRadius = 32
return imageView
}()

let chainLabel: UILabel = {
let label = UILabel()
label.font = UIFont.systemFont(ofSize: 17.0, weight: .heavy)
Expand All @@ -32,9 +31,9 @@ class AccountRequestView: UIView {
stackView.alignment = .center
return stackView
}()

let tableView = UITableView()

override init(frame: CGRect) {
super.init(frame: frame)
backgroundColor = .systemBackground
Expand All @@ -45,21 +44,21 @@ class AccountRequestView: UIView {

headerStackView.addArrangedSubview(chainLabel)
headerStackView.addArrangedSubview(accountLabel)

subviews.forEach { $0.translatesAutoresizingMaskIntoConstraints = false }

NSLayoutConstraint.activate([
iconView.topAnchor.constraint(equalTo: topAnchor, constant: 64),
iconView.centerXAnchor.constraint(equalTo: centerXAnchor),

headerStackView.topAnchor.constraint(equalTo: iconView.bottomAnchor, constant: 32),
headerStackView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 32),
headerStackView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -32),

tableView.topAnchor.constraint(equalTo: headerStackView.bottomAnchor, constant: 0),
tableView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 0),
tableView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: 0),
tableView.bottomAnchor.constraint(equalTo: safeAreaLayoutGuide.bottomAnchor),
tableView.bottomAnchor.constraint(equalTo: safeAreaLayoutGuide.bottomAnchor)
])
}

Expand Down
31 changes: 14 additions & 17 deletions Example/DApp/AccountRequest/AccountRequestViewController.swift
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@


import Foundation
import UIKit
import WalletConnectSign
import WalletConnectUtils

class AccountRequestViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
class AccountRequestViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
private let session: Session
private let chainId: String
private let account: String
private let methods = ["eth_sendTransaction", "personal_sign", "eth_signTypedData"]
private let accountRequestView = {
AccountRequestView()
}()

init(session: Session, accountDetails: AccountDetails) {
self.session = session
self.chainId = accountDetails.chain
self.account = accountDetails.account
super.init(nibName: nil, bundle: nil)
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func loadView() {
view = accountRequestView
}

override func viewDidLoad() {
super.viewDidLoad()
accountRequestView.tableView.delegate = self
Expand All @@ -37,26 +35,25 @@ class AccountRequestViewController: UIViewController, UITableViewDelegate, UITab
accountRequestView.chainLabel.text = chainId
accountRequestView.accountLabel.text = account
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
methods.count
}

func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return "Methods"
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "method_cell", for: indexPath)
cell.textLabel?.text = methods[indexPath.row]
return cell
}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let method = methods[indexPath.row]
let requestParams = getRequest(for: method)



let request = Request(topic: session.topic, method: method, params: requestParams, chainId: Blockchain(chainId)!)
Task {
do {
Expand All @@ -66,18 +63,18 @@ class AccountRequestViewController: UIViewController, UITableViewDelegate, UITab
}
} catch {
print(error)
//show failure alert
// show failure alert
}
}
}

private func presentConfirmationAlert() {
let alert = UIAlertController(title: "Request Sent", message: nil, preferredStyle: .alert)
let action = UIAlertAction(title: "OK", style: .cancel)
alert.addAction(action)
present(alert, animated: true)
}

private func getRequest(for method: String) -> AnyCodable {
let account = session.namespaces.first!.value.accounts.first!.absoluteString
if method == "eth_sendTransaction" {
Expand All @@ -97,7 +94,7 @@ struct Transaction: Codable {
let gasPrice, value, nonce: String
}

fileprivate enum Stub {
private enum Stub {
static let tx = [Transaction(from: "0x9b2055d370f73ec7d8a03e965129118dc8f5bf83",
to: "0x9b2055d370f73ec7d8a03e965129118dc8f5bf83",
data: "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675",
Expand Down
2 changes: 0 additions & 2 deletions Example/DApp/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import UIKit

@main
Expand All @@ -22,5 +21,4 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}


}
20 changes: 9 additions & 11 deletions Example/DApp/Connect/ConnectView.swift
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@

import Foundation
import UIKit

final class ConnectView: UIView {
let tableView = UITableView()

let qrCodeView: UIImageView = {
let imageView = UIImageView()
imageView.contentMode = .center
return imageView
}()

let copyButton: UIButton = {
let button = UIButton(type: .system)
button.setTitle("Copy", for: .normal)
Expand All @@ -21,7 +20,7 @@ final class ConnectView: UIView {
button.layer.cornerRadius = 8
return button
}()

let connectWalletButton: UIButton = {
let button = UIButton(type: .system)
button.setTitle("Connect Wallet", for: .normal)
Expand All @@ -31,7 +30,7 @@ final class ConnectView: UIView {
button.layer.cornerRadius = 8
return button
}()

override init(frame: CGRect) {
super.init(frame: frame)
backgroundColor = .systemBackground
Expand All @@ -41,31 +40,30 @@ final class ConnectView: UIView {
addSubview(tableView)
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "pairing_cell")
subviews.forEach { $0.translatesAutoresizingMaskIntoConstraints = false }

NSLayoutConstraint.activate([
tableView.topAnchor.constraint(equalTo: safeAreaLayoutGuide.topAnchor),
tableView.leadingAnchor.constraint(equalTo: safeAreaLayoutGuide.leadingAnchor),
tableView.trailingAnchor.constraint(equalTo: safeAreaLayoutGuide.trailingAnchor),
tableView.bottomAnchor.constraint(equalTo: safeAreaLayoutGuide.bottomAnchor),


qrCodeView.topAnchor.constraint(equalTo: safeAreaLayoutGuide.topAnchor, constant: 50),
qrCodeView.centerXAnchor.constraint(equalTo: centerXAnchor),
qrCodeView.widthAnchor.constraint(equalTo: widthAnchor, multiplier: 0.6),
qrCodeView.widthAnchor.constraint(equalTo: qrCodeView.heightAnchor),

copyButton.topAnchor.constraint(equalTo: qrCodeView.bottomAnchor, constant: 16),
copyButton.centerXAnchor.constraint(equalTo: centerXAnchor),
copyButton.widthAnchor.constraint(equalTo: qrCodeView.widthAnchor),
copyButton.heightAnchor.constraint(equalToConstant: 44),

connectWalletButton.topAnchor.constraint(equalTo: copyButton.bottomAnchor, constant: 16),
connectWalletButton.centerXAnchor.constraint(equalTo: centerXAnchor),
connectWalletButton.widthAnchor.constraint(equalTo: copyButton.widthAnchor),
connectWalletButton.heightAnchor.constraint(equalToConstant: 44),
connectWalletButton.heightAnchor.constraint(equalToConstant: 44)
])
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
Expand Down
Loading

0 comments on commit 0bd0a56

Please sign in to comment.